|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Default.java | 0% | 0% | 0% | 0% |
|
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 defaultValue; | |
35 | ||
36 | 0 | public void resetForPool() |
37 | { | |
38 | 0 | binding = null; |
39 | 0 | defaultValue = null; |
40 | } | |
41 | ||
42 | 0 | public void setBinding(IBinding value) |
43 | { | |
44 | 0 | binding = value; |
45 | } | |
46 | ||
47 | 0 | public IBinding getBinding() |
48 | { | |
49 | 0 | return binding; |
50 | } | |
51 | ||
52 | 0 | public void setDefaultValue(Object value) |
53 | { | |
54 | 0 | defaultValue = value; |
55 | } | |
56 | ||
57 | 0 | public Object getDefaultValue() |
58 | { | |
59 | 0 | 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 | 0 | public Object getValue() |
69 | { | |
70 | 0 | if (binding == null) |
71 | 0 | return defaultValue; |
72 | ||
73 | 0 | Object value = binding.getObject(); |
74 | ||
75 | 0 | if (value == null) |
76 | 0 | return defaultValue; |
77 | ||
78 | 0 | return value; |
79 | } | |
80 | ||
81 | /** @since 3.0 **/ | |
82 | ||
83 | 0 | public void discardFromPool() |
84 | { | |
85 | } | |
86 | ||
87 | } |
|