KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > properties > BooleanProperty


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

18 package org.apache.geronimo.interop.properties;
19
20 public class BooleanProperty extends PropertyType {
21     private boolean defaultValue = false;
22
23     public BooleanProperty(Class JavaDoc componentClass, String JavaDoc propertyName) {
24         super(componentClass, propertyName);
25     }
26
27     public BooleanProperty displayName(String JavaDoc displayName) {
28         setDisplayName(displayName);
29         return this;
30     }
31
32     public BooleanProperty displayOnlyIf(PropertyType other, String JavaDoc value) {
33         setDisplayOnlyIf(other, value);
34         return this;
35     }
36
37     public BooleanProperty description(String JavaDoc description) {
38         setDescription(description);
39         return this;
40     }
41
42     public BooleanProperty consoleHelp(String JavaDoc consoleHelp) {
43         setConsoleHelp(consoleHelp);
44         return this;
45     }
46
47     public BooleanProperty sortOrder(int sortOrder) {
48         setSortOrder(sortOrder);
49         return this;
50     }
51
52     public BooleanProperty defaultValue(boolean defaultValue) {
53         defaultValue = defaultValue;
54         return this;
55     }
56
57     public boolean getDefaultValue() {
58         return defaultValue;
59     }
60
61     public String JavaDoc getDefaultValueAsString() {
62         return String.valueOf(defaultValue);
63     }
64
65     public boolean getBoolean() {
66         return getBoolean(null, getComponentProperties());
67     }
68
69     public boolean getBoolean(String JavaDoc instanceName, PropertyMap props) {
70         boolean b;
71         boolean ok = true;
72         String JavaDoc value = props.getProperty(getPropertyName(), String.valueOf(defaultValue));
73         value = value.toLowerCase();
74         if (value.equals("true")) {
75             b = true;
76         } else if (value.equals("false")) {
77             b = false;
78         } else {
79             ok = false;
80             b = false;
81         }
82         if (!ok) {
83             badPropertyValue(instanceName, value, expectedTrueOrFalse());
84         }
85         logPropertyValue(instanceName, value, b == defaultValue);
86         return b;
87     }
88 }
89
Popular Tags