KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.List JavaDoc;
21
22 import org.apache.geronimo.interop.util.ExceptionUtil;
23
24 public abstract class PropertyType {
25     protected static boolean debug;
26
27     static {
28         try {
29             debug = Boolean.getBoolean("org.apache.geronimo.interop.debug:properties");
30         } catch (Exception JavaDoc ignore) // e.g. SecurityException for Applet
31
{
32             debug = false;
33         }
34     }
35
36     private Class JavaDoc componentClass;
37     private String JavaDoc propertyName;
38     private String JavaDoc displayName;
39     private String JavaDoc displayOnlyIfOther;
40     private String JavaDoc displayOnlyIfValue;
41     private String JavaDoc description;
42     private String JavaDoc consoleHelp;
43     private int sortOrder;
44
45     public PropertyType(Class JavaDoc componentClass, String JavaDoc propertyName) {
46         this.componentClass = componentClass;
47         this.propertyName = propertyName;
48     }
49
50     public Class JavaDoc getComponentClass() {
51         return componentClass;
52     }
53
54     public PropertyMap getComponentProperties() {
55         if (componentClass == SystemProperties.class) {
56             return SystemProperties.getInstance();
57         } else {
58             return null; // Component.forClass(_componentClass).getProperties();
59
}
60     }
61
62     public String JavaDoc getPropertyName() {
63         return propertyName;
64     }
65
66     public String JavaDoc getDisplayName() {
67         return displayName;
68     }
69
70     public String JavaDoc getDisplayOnlyIfOther() {
71         return displayOnlyIfOther;
72     }
73
74     public String JavaDoc getDisplayOnlyIfValue() {
75         return displayOnlyIfValue;
76     }
77
78     public String JavaDoc getDescription() {
79         return description;
80     }
81
82     public String JavaDoc getConsoleHelp() {
83         return consoleHelp;
84     }
85
86     public int getSortOrder() {
87         return sortOrder;
88     }
89
90     public String JavaDoc getDefaultValueAsString() {
91         return "";
92     }
93
94     public boolean isList() {
95         return false;
96     }
97
98     public boolean isReadOnly() {
99         return false;
100     }
101
102     public void setDisplayName(String JavaDoc displayName) {
103         this.displayName = displayName;
104     }
105
106     public void setDisplayOnlyIf(PropertyType other, String JavaDoc value) {
107         displayOnlyIfOther = other.getPropertyName();
108         displayOnlyIfValue = value;
109     }
110
111     public void setDescription(String JavaDoc description) {
112         this.description = description;
113     }
114
115     public void setConsoleHelp(String JavaDoc consoleHelp) {
116         this.consoleHelp = consoleHelp;
117     }
118
119     public void setSortOrder(int sortOrder) {
120         this.sortOrder = sortOrder;
121     }
122
123     public void badPropertyValue(String JavaDoc instanceName, String JavaDoc value) {
124         badPropertyValue(instanceName, value, (String JavaDoc) null);
125     }
126
127     public void badPropertyValue(String JavaDoc instanceName, String JavaDoc value, Exception JavaDoc ex) {
128         badPropertyValue(instanceName, value, "exception: " + ExceptionUtil.getStackTrace(ex));
129     }
130
131     public void badPropertyValue(String JavaDoc instanceName, String JavaDoc value, String JavaDoc reason) {
132         // TODO: I18N
133
/*
134         throw new SystemException("Bad value '" + value
135             + "' for property '" + _propertyName
136             + "' of component " + _componentClass.getName()
137             + (instanceName == null ? "" : (", instance " + instanceName))
138             + (reason != null ? (", " + reason) : ""));
139             */

140         Thread.dumpStack();
141     }
142
143     public String JavaDoc expectedNumberInRange(long minimumValue, long maximumValue) {
144         // TODO: I18N
145
return "expected number in range [" + minimumValue + " .. " + maximumValue + "]";
146     }
147
148     public String JavaDoc expectedNumberInRange(double minimumValue, double maximumValue) {
149         // TODO: I18N
150
return "expected number in range [" + minimumValue + " .. " + maximumValue + "]";
151     }
152
153     public String JavaDoc expectedTrueOrFalse() {
154         // TODO: I18N
155
return "expected true or false";
156     }
157
158     public String JavaDoc expectedValueInList(List JavaDoc legalValues) {
159         // TODO: I18N
160
return "expected value in list " + legalValues;
161     }
162
163     public void logPropertyValue(String JavaDoc instanceName, String JavaDoc value, boolean usingDefaultValue) {
164         if (propertyName.toLowerCase().endsWith("password")) {
165             value = "******";
166         }
167         if (debug) // TODO: allow for bootstrap
168
{
169             if (usingDefaultValue) {
170                 if (componentClass == SystemProperties.class) {
171                     SystemPropertyLog.getInstance(propertyName).debugUsingDefaultValue(value);
172                 } else {
173                     getLog(instanceName).debugUsingDefaultValue(value);
174                 }
175             } else {
176                 if (componentClass == SystemProperties.class) {
177                     SystemPropertyLog.getInstance(propertyName).debugUsingValue(value);
178                 } else {
179                     getLog(instanceName).debugUsingValue(value);
180                 }
181             }
182         }
183     }
184
185     public String JavaDoc getContext(String JavaDoc instanceName) {
186         /*
187         String showName = JavaClass.getNameSuffix(_componentClass.getName());
188         // TODO: optional full component name
189         return showName + (instanceName != null ? (":" + instanceName) : "");
190         */

191         return "TODO: PropertyType.getContext()";
192     }
193
194     public PropertyLog getLog(String JavaDoc instanceName) {
195         return PropertyLog.getInstance(propertyName + ", " + getContext(instanceName));
196     }
197 }
198
Popular Tags