KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > bean > Default


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.bean;
16
17 import org.apache.tapestry.IBinding;
18
19 /**
20  * A helper bean to assist with providing defaults for unspecified
21  * parameters. It is initalized
22  * with an {@link IBinding} and a default value. It's value property
23  * is either the value of the binding, but if the binding is null,
24  * or the binding returns null, the default value is returned.
25  *
26  * @author Howard Lewis Ship
27  * @since 1.0.5
28  *
29  **/

30
31 public class Default
32 {
33     private IBinding binding;
34     private Object JavaDoc defaultValue;
35
36     public void resetForPool()
37     {
38         binding = null;
39         defaultValue = null;
40     }
41
42     public void setBinding(IBinding value)
43     {
44         binding = value;
45     }
46
47     public IBinding getBinding()
48     {
49         return binding;
50     }
51
52     public void setDefaultValue(Object JavaDoc value)
53     {
54         defaultValue = value;
55     }
56
57     public Object JavaDoc getDefaultValue()
58     {
59         return defaultValue;
60     }
61
62     /**
63      * Returns the value of the binding. However, if the binding is null, or the binding
64      * returns null, then the defaultValue is returned instead.
65      *
66      **/

67
68     public Object JavaDoc getValue()
69     {
70         if (binding == null)
71             return defaultValue;
72
73         Object JavaDoc value = binding.getObject();
74
75         if (value == null)
76             return defaultValue;
77
78         return value;
79     }
80     
81     /** @since 3.0 **/
82     
83     public void discardFromPool()
84     {
85     }
86
87 }
Popular Tags