KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gcc > properties > PropertyType


1 /*
2  * Copyright 2004 The Apache Software Foundation or its licensors, as
3  * applicable.
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
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package gcc.properties;
20
21 import gcc.util.*;
22 import java.util.*;
23
24 public abstract class PropertyType
25 {
26     protected static boolean _debug;
27
28     static
29     {
30         try
31         {
32             _debug = Boolean.getBoolean("gcc.debug:properties");
33         }
34         catch (Exception ignore) // e.g. SecurityException for Applet
35
{
36             _debug = false;
37         }
38     }
39
40     protected Class _componentClass;
41
42     protected String _propertyName;
43
44     protected String _displayName;
45
46     protected String _displayOnlyIfOther;
47
48     protected String _displayOnlyIfValue;
49
50     protected String _description;
51
52     protected String _consoleHelp;
53
54     protected int _sortOrder;
55
56     public PropertyType(Class componentClass, String propertyName)
57     {
58         _componentClass = componentClass;
59         _propertyName = propertyName;
60     }
61
62     public Class getComponentClass()
63     {
64         return _componentClass;
65     }
66
67     public PropertyMap getComponentProperties()
68     {
69         if (_componentClass == SystemProperties.class)
70         {
71             return SystemProperties.getInstance();
72         }
73         else
74         {
75             return null; // Component.forClass(_componentClass).getProperties();
76
}
77     }
78
79     public String getPropertyName()
80     {
81         return _propertyName;
82     }
83
84     public String getDisplayName()
85     {
86         return _displayName;
87     }
88
89     public String getDisplayOnlyIfOther()
90     {
91         return _displayOnlyIfOther;
92     }
93
94     public String getDisplayOnlyIfValue()
95     {
96         return _displayOnlyIfValue;
97     }
98
99     public String getDescription()
100     {
101         return _description;
102     }
103
104     public String getConsoleHelp()
105     {
106         return _consoleHelp;
107     }
108
109     public int getSortOrder()
110     {
111         return _sortOrder;
112     }
113
114     public String getDefaultValueAsString()
115     {
116         return "";
117     }
118
119     public boolean isList()
120     {
121         return false;
122     }
123
124     public boolean isReadOnly()
125     {
126         return false;
127     }
128
129     public void setDisplayName(String displayName)
130     {
131         _displayName = displayName;
132     }
133
134     public void setDisplayOnlyIf(PropertyType other, String value)
135     {
136         _displayOnlyIfOther = other.getPropertyName();
137         _displayOnlyIfValue = value;
138     }
139
140     public void setDescription(String description)
141     {
142         _description = description;
143     }
144
145     public void setConsoleHelp(String consoleHelp)
146     {
147         _consoleHelp = consoleHelp;
148     }
149
150     public void setSortOrder(int sortOrder)
151     {
152         _sortOrder = sortOrder;
153     }
154
155     public void badPropertyValue(String instanceName, String value)
156     {
157         badPropertyValue(instanceName, value, (String)null);
158     }
159
160     public void badPropertyValue(String instanceName, String value, Exception ex)
161     {
162         badPropertyValue(instanceName, value, "exception: " + ExceptionUtil.getStackTrace(ex));
163     }
164
165     public void badPropertyValue(String instanceName, String value, String reason)
166     {
167         // TODO: I18N
168
/*
169         throw new SystemException("Bad value '" + value
170             + "' for property '" + _propertyName
171             + "' of component " + _componentClass.getName()
172             + (instanceName == null ? "" : (", instance " + instanceName))
173             + (reason != null ? (", " + reason) : ""));
174             */

175         Thread.dumpStack();
176     }
177
178     public String expectedNumberInRange(long minimumValue, long maximumValue)
179     {
180         // TODO: I18N
181
return "expected number in range [" + minimumValue + " .. " + maximumValue + "]";
182     }
183
184     public String expectedNumberInRange(double minimumValue, double maximumValue)
185     {
186         // TODO: I18N
187
return "expected number in range [" + minimumValue + " .. " + maximumValue + "]";
188     }
189
190     public String expectedTrueOrFalse()
191     {
192         // TODO: I18N
193
return "expected true or false";
194     }
195
196     public String expectedValueInList(List legalValues)
197     {
198         // TODO: I18N
199
return "expected value in list " + legalValues;
200     }
201
202     public void logPropertyValue(String instanceName, String value, boolean usingDefaultValue)
203     {
204         if (_propertyName.toLowerCase().endsWith("password"))
205         {
206             value = "******";
207         }
208         if (_debug) // TODO: allow for bootstrap
209
{
210             if (usingDefaultValue)
211             {
212                 if (_componentClass == SystemProperties.class)
213                 {
214                     SystemPropertyLog.getInstance(_propertyName).debugUsingDefaultValue(value);
215                 }
216                 else
217                 {
218                     getLog(instanceName).debugUsingDefaultValue(value);
219                 }
220             }
221             else
222             {
223                 if (_componentClass == SystemProperties.class)
224                 {
225                     SystemPropertyLog.getInstance(_propertyName).debugUsingValue(value);
226                 }
227                 else
228                 {
229                     getLog(instanceName).debugUsingValue(value);
230                 }
231             }
232         }
233     }
234
235     public String getContext(String instanceName)
236     {
237         /*
238         String showName = JavaClass.getNameSuffix(_componentClass.getName());
239         // TODO: optional full component name
240         return showName + (instanceName != null ? (":" + instanceName) : "");
241         */

242         return "TODO: PropertyType.getContext()";
243     }
244
245     public PropertyLog getLog(String instanceName)
246     {
247         return PropertyLog.getInstance(_propertyName + ", " + getContext(instanceName));
248     }
249 }
250
Popular Tags