001: /*
002: * Created on Jan 23, 2004
003: *
004: * To change the template for this generated file go to
005: * Window - Preferences - Java - Code Generation - Code and Comments
006: */
007: package org.vfny.geoserver.config.validation;
008:
009: import org.geotools.validation.dto.ArgumentDTO;
010: import java.beans.Introspector;
011: import java.beans.PropertyDescriptor;
012: import java.util.List;
013: import java.util.Locale;
014:
015: /**
016: * ArgumentConfig purpose.
017: * <p>
018: * Description of ArgumentConfig ...
019: * </p>
020: *
021: * @author dzwiers, Refractions Research, Inc.
022: * @author $Author: dmzwiers $ (last modification)
023: * @version $Id: ArgumentConfig.java 6177 2007-02-19 10:11:27Z aaime $
024: */
025: public class ArgumentConfig {
026: private String name;
027: private boolean _final;
028: private Object value;
029:
030: /**
031: * ArgumentConfig constructor.
032: * <p>
033: * Description
034: * </p>
035: *
036: */
037: public ArgumentConfig() {
038: }
039:
040: public ArgumentConfig(ArgumentConfig dto) {
041: name = dto.getName();
042: _final = isFinal();
043: value = dto.getValue();
044: }
045:
046: public ArgumentConfig(ArgumentDTO dto) {
047: name = dto.getName();
048: _final = isFinal();
049: value = dto.getValue();
050: }
051:
052: public Object clone() {
053: return new ArgumentConfig(this );
054: }
055:
056: public boolean equals(Object obj) {
057: boolean r = true;
058:
059: if ((obj == null) || !(obj instanceof ArgumentConfig)) {
060: return false;
061: }
062:
063: ArgumentConfig dto = (ArgumentConfig) obj;
064: r = r && (dto.isFinal() == _final);
065:
066: if (name != null) {
067: r = r && (name.equals(dto.getName()));
068: } else if (dto.getName() != null) {
069: return false;
070: }
071:
072: if (value != null) {
073: r = r && (value.equals(dto.getValue()));
074: } else if (dto.getValue() != null) {
075: return false;
076: }
077:
078: return r;
079: }
080:
081: public int hashCode() {
082: int r = 1;
083:
084: if (name != null) {
085: r *= name.hashCode();
086: }
087:
088: if (value != null) {
089: r *= value.hashCode();
090: }
091:
092: return r;
093: }
094:
095: public ArgumentDTO toDTO() {
096: ArgumentDTO dto = new ArgumentDTO();
097: dto.setFinal(_final);
098: dto.setName(name);
099: dto.setValue(value);
100:
101: return dto;
102: }
103:
104: /**
105: * Access _final property.
106: *
107: * @return Returns the _final.
108: */
109: public boolean isFinal() {
110: return _final;
111: }
112:
113: /**
114: * Set _final to _final.
115: *
116: * @param _final The _final to set.
117: */
118: public void setFinal(boolean _final) {
119: this ._final = _final;
120: }
121:
122: /**
123: * Access name property.
124: *
125: * @return Returns the name.
126: */
127: public String getName() {
128: return name;
129: }
130:
131: /**
132: * Set name to name.
133: *
134: * @param name The name to set.
135: */
136: public void setName(String name) {
137: this .name = name;
138: }
139:
140: /**
141: * Access value property.
142: *
143: * @return Returns the value.
144: */
145: public Object getValue() {
146: return value;
147: }
148:
149: /**
150: * Set value to value.
151: *
152: * @param value The value to set.
153: */
154: public void setValue(Object value) {
155: if (value == null) {
156: throw new NullPointerException(
157: "value should only be set when it has a value");
158: }
159:
160: this .value = value;
161: }
162:
163: /**
164: *
165: * getDisplayName purpose.
166: * <p>
167: * This is used to provide the locale to the property descriptor if it is required. This method is thread safe.
168: * </p>
169: * <p>
170: * This method must be both synchornized and static. The global locale is maintained from start to completion of execution, even when an unexpected exception occurs.
171: * </p>
172: * @param pd PropertyDescriptor to get the display name from
173: * @param locale Locale to use if required.
174: * @return String the Display Name
175: */
176: public static synchronized String getDisplayName(
177: PropertyDescriptor pd) {
178: String r = "";
179:
180: try { // to safely reset the locale.
181: r = pd.getDisplayName();
182: } finally {
183: }
184:
185: return r;
186: }
187:
188: public static synchronized void loadPropertyLists(
189: TestConfig testConfig, Locale lc, List attributeKeys,
190: List attributeHelps, List attributeValues) {
191: if (!lc.equals(Locale.getDefault())) {
192: Locale.setDefault(lc);
193: Introspector.flushCaches();
194: }
195:
196: PropertyDescriptor[] pd = testConfig.getPropertyDescriptors();
197:
198: for (int i = 0; i < pd.length; i++) {
199: PropertyDescriptor property = pd[i];
200: String propertyName = property.getName();
201: String displayName = ArgumentConfig
202: .getDisplayName(property);
203: String description = ArgumentConfig
204: .getDescription(property);
205:
206: attributeKeys.add(propertyName);
207: attributeHelps.add(description);
208: attributeValues.add(testConfig
209: .getArgStringValue(propertyName));
210: }
211: }
212:
213: /**
214: *
215: * getDescription purpose.
216: * <p>
217: * This is used to provide the locale to the property descriptor if it is required. This method is thread safe.
218: * </p>
219: * <p>
220: * This method must be both synchornized and static.
221: * </p>
222: * @param pd PropertyDescriptor to get the display description from
223: * @param locale Locale to use if required.
224: * @return String the display description
225: */
226: public static synchronized String getDescription(
227: PropertyDescriptor pd) {
228: String r = "";
229:
230: try { // to safely reset the locale.
231: r = pd.getShortDescription();
232: } finally {
233: }
234:
235: return r;
236: }
237: }
|