KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > data > Validator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /**
20  * This generated bean class Validator
21  * matches the schema element 'validator'.
22  * The root bean class is DynamicProperties
23  *
24  * Generated on Wed Sep 29 16:29:53 PDT 2004
25  * @Generated
26  */

27
28 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.data;
29
30 public class Validator {
31     public static final String JavaDoc VALIDATOR_NAME = "ValidatorName"; // NOI18N
32
public static final String JavaDoc VALIDATOR_PATTERN = "ValidatorPattern"; // NOI18N
33

34     private String JavaDoc _ValidatorName;
35     private String JavaDoc _ValidatorPattern;
36
37     /**
38      * Normal starting point constructor.
39      */

40     public Validator() {
41         _ValidatorName = "";
42         _ValidatorPattern = "";
43     }
44
45     /**
46      * Required parameters constructor
47      */

48     public Validator(String JavaDoc validatorName, String JavaDoc validatorPattern) {
49         _ValidatorName = validatorName;
50         _ValidatorPattern = validatorPattern;
51     }
52
53     /**
54      * Deep copy
55      */

56     public Validator(org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.Validator source) {
57         this(source, false);
58     }
59
60     /**
61      * Deep copy
62      * @param justData just copy the XML relevant data
63      */

64     public Validator(org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.Validator source, boolean justData) {
65         _ValidatorName = source._ValidatorName;
66         _ValidatorPattern = source._ValidatorPattern;
67     }
68
69     // This attribute is mandatory
70
public void setValidatorName(String JavaDoc value) {
71         _ValidatorName = value;
72     }
73
74     public String JavaDoc getValidatorName() {
75         return _ValidatorName;
76     }
77
78     // This attribute is mandatory
79
public void setValidatorPattern(String JavaDoc value) {
80         _ValidatorPattern = value;
81     }
82
83     public String JavaDoc getValidatorPattern() {
84         return _ValidatorPattern;
85     }
86
87     public void writeNode(java.io.Writer JavaDoc out) throws java.io.IOException JavaDoc {
88         String JavaDoc myName;
89         myName = "validator";
90         writeNode(out, myName, ""); // NOI18N
91
}
92
93     public void writeNode(java.io.Writer JavaDoc out, String JavaDoc nodeName, String JavaDoc indent) throws java.io.IOException JavaDoc {
94         writeNode(out, nodeName, null, indent, new java.util.HashMap JavaDoc());
95     }
96
97     /**
98      * It's not recommended to call this method directly.
99      */

100     public void writeNode(java.io.Writer JavaDoc out, String JavaDoc nodeName, String JavaDoc namespace, String JavaDoc indent, java.util.Map JavaDoc namespaceMap) throws java.io.IOException JavaDoc {
101         out.write(indent);
102         out.write("<");
103         if (namespace != null) {
104             out.write((String JavaDoc)namespaceMap.get(namespace));
105             out.write(":");
106         }
107         out.write(nodeName);
108         out.write(">\n");
109         String JavaDoc nextIndent = indent + " ";
110         if (_ValidatorName != null) {
111             out.write(nextIndent);
112             out.write("<validator-name"); // NOI18N
113
out.write(">"); // NOI18N
114
org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.DynamicProperties.writeXML(out, _ValidatorName, false);
115             out.write("</validator-name>\n"); // NOI18N
116
}
117         if (_ValidatorPattern != null) {
118             out.write(nextIndent);
119             out.write("<validator-pattern"); // NOI18N
120
out.write(">"); // NOI18N
121
org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.DynamicProperties.writeXML(out, _ValidatorPattern, false);
122             out.write("</validator-pattern>\n"); // NOI18N
123
}
124         out.write(indent);
125         out.write("</");
126         if (namespace != null) {
127             out.write((String JavaDoc)namespaceMap.get(namespace));
128             out.write(":");
129         }
130         out.write(nodeName);
131         out.write(">\n");
132     }
133
134     public void readNode(org.w3c.dom.Node JavaDoc node) {
135         readNode(node, new java.util.HashMap JavaDoc());
136     }
137
138     public void readNode(org.w3c.dom.Node JavaDoc node, java.util.Map JavaDoc namespacePrefixes) {
139         if (node.hasAttributes()) {
140             org.w3c.dom.NamedNodeMap JavaDoc attrs = node.getAttributes();
141             org.w3c.dom.Attr JavaDoc attr;
142             java.lang.String JavaDoc attrValue;
143             boolean firstNamespaceDef = true;
144             for (int attrNum = 0; attrNum < attrs.getLength(); ++attrNum) {
145                 attr = (org.w3c.dom.Attr JavaDoc) attrs.item(attrNum);
146                 String JavaDoc attrName = attr.getName();
147                 if (attrName.startsWith("xmlns:")) {
148                     if (firstNamespaceDef) {
149                         firstNamespaceDef = false;
150                         // Dup prefix map, so as to not write over previous values, and to make it easy to clear out our entries.
151
namespacePrefixes = new java.util.HashMap JavaDoc(namespacePrefixes);
152                     }
153                     String JavaDoc attrNSPrefix = attrName.substring(6, attrName.length());
154                     namespacePrefixes.put(attrNSPrefix, attr.getValue());
155                 }
156             }
157         }
158         org.w3c.dom.NodeList JavaDoc children = node.getChildNodes();
159         for (int i = 0, size = children.getLength(); i < size; ++i) {
160             org.w3c.dom.Node JavaDoc childNode = children.item(i);
161             String JavaDoc childNodeName = (childNode.getLocalName() == null ? childNode.getNodeName().intern() : childNode.getLocalName().intern());
162             String JavaDoc childNodeValue = "";
163             if (childNode.getFirstChild() != null) {
164                 childNodeValue = childNode.getFirstChild().getNodeValue();
165             }
166             if (childNodeName == "validator-name") {
167                 _ValidatorName = childNodeValue;
168             }
169             else if (childNodeName == "validator-pattern") {
170                 _ValidatorPattern = childNodeValue;
171             }
172             else {
173                 // Found extra unrecognized childNode
174
}
175         }
176     }
177
178     public void changePropertyByName(String JavaDoc name, Object JavaDoc value) {
179         if (name == null) return;
180         name = name.intern();
181         if (name == "validatorName")
182             setValidatorName((String JavaDoc)value);
183         else if (name == "validatorPattern")
184             setValidatorPattern((String JavaDoc)value);
185         else
186             throw new IllegalArgumentException JavaDoc(name+" is not a valid property name for Validator");
187     }
188
189     public Object JavaDoc fetchPropertyByName(String JavaDoc name) {
190         if (name == "validatorName")
191             return getValidatorName();
192         if (name == "validatorPattern")
193             return getValidatorPattern();
194         throw new IllegalArgumentException JavaDoc(name+" is not a valid property name for Validator");
195     }
196
197     public String JavaDoc nameSelf() {
198         return "Validator";
199     }
200
201     public String JavaDoc nameChild(Object JavaDoc childObj) {
202         return nameChild(childObj, false, false);
203     }
204
205     /**
206      * @param childObj The child object to search for
207      * @param returnSchemaName Whether or not the schema name should be returned or the property name
208      * @return null if not found
209      */

210     public String JavaDoc nameChild(Object JavaDoc childObj, boolean returnConstName, boolean returnSchemaName) {
211         return nameChild(childObj, returnConstName, returnSchemaName, false);
212     }
213
214     /**
215      * @param childObj The child object to search for
216      * @param returnSchemaName Whether or not the schema name should be returned or the property name
217      * @return null if not found
218      */

219     public String JavaDoc nameChild(Object JavaDoc childObj, boolean returnConstName, boolean returnSchemaName, boolean returnXPathName) {
220         if (childObj instanceof java.lang.String JavaDoc) {
221             java.lang.String JavaDoc child = (java.lang.String JavaDoc) childObj;
222             if (child == _ValidatorName) {
223                 if (returnConstName) {
224                     return VALIDATOR_NAME;
225                 } else if (returnSchemaName) {
226                     return "validator-name";
227                 } else if (returnXPathName) {
228                     return "validator-name";
229                 } else {
230                     return "ValidatorName";
231                 }
232             }
233             if (child == _ValidatorPattern) {
234                 if (returnConstName) {
235                     return VALIDATOR_PATTERN;
236                 } else if (returnSchemaName) {
237                     return "validator-pattern";
238                 } else if (returnXPathName) {
239                     return "validator-pattern";
240                 } else {
241                     return "ValidatorPattern";
242                 }
243             }
244         }
245         return null;
246     }
247
248     /**
249      * Return an array of all of the properties that are beans and are set.
250      */

251     public java.lang.Object JavaDoc[] childBeans(boolean recursive) {
252         java.util.List JavaDoc children = new java.util.LinkedList JavaDoc();
253         childBeans(recursive, children);
254         java.lang.Object JavaDoc[] result = new java.lang.Object JavaDoc[children.size()];
255         return (java.lang.Object JavaDoc[]) children.toArray(result);
256     }
257
258     /**
259      * Put all child beans into the beans list.
260      */

261     public void childBeans(boolean recursive, java.util.List JavaDoc beans) {
262     }
263
264     public boolean equals(Object JavaDoc o) {
265         return o instanceof org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.Validator && equals((org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.Validator) o);
266     }
267
268     public boolean equals(org.netbeans.modules.j2ee.sun.share.configbean.customizers.data.Validator inst) {
269         if (inst == this) {
270             return true;
271         }
272         if (inst == null) {
273             return false;
274         }
275         if (!(_ValidatorName == null ? inst._ValidatorName == null : _ValidatorName.equals(inst._ValidatorName))) {
276             return false;
277         }
278         if (!(_ValidatorPattern == null ? inst._ValidatorPattern == null : _ValidatorPattern.equals(inst._ValidatorPattern))) {
279             return false;
280         }
281         return true;
282     }
283
284     public int hashCode() {
285         int result = 17;
286         result = 37*result + (_ValidatorName == null ? 0 : _ValidatorName.hashCode());
287         result = 37*result + (_ValidatorPattern == null ? 0 : _ValidatorPattern.hashCode());
288         return result;
289     }
290
291 }
292
293
294 /*
295         The following schema file has been used for generation:
296
297 <?xml version="1.0" encoding="UTF-8"?>
298
299 <!--
300     Document : dynamic-properties.dtd
301     Created on : January 28, 2004, 8:48 PM
302     Author : Peter Williams
303     Description:
304         Purpose of the document follows.
305         
306     DTD for definition of properties, their editors and validators to allow for
307     name/value pair property editing to be handled nicely in the plugin.
308 -->
309
310 <!-- The file is a list of property lists -->
311 <!ELEMENT dynamic-properties (property-list*, validator*)>
312
313 <!-- Each property list can be fixed or editable and has a name -->
314 <!ELEMENT property-list (property-name, property-param+, help-id?)>
315 <!ATTLIST property-list editable CDATA "false"
316                         description CDATA "true"
317                         bundle-path CDATA #IMPLIED>
318
319 <!ELEMENT property-name (#PCDATA)>
320
321 <!--
322     Each element in a property list has a name. It may also have a type, a
323     validator, and possibly a min and/or max if the type is 'number'. Lastly,
324     it could have a helpId
325 -->
326 <!ELEMENT property-param (param-name, param-type, param-label?, param-validator?, default-value?,
327                           help-id?, param-description?)>
328
329 <!ELEMENT param-name (#PCDATA)>
330
331 <!--
332     There are four allowed types: boolean, text, number, and list. The editable
333     attribute is ignored for all types except the list type.
334     
335     For boolean properties, default value should be string using the boolean
336       'ENTITY' definitions in the sun-xxx dtd's, preferably true/false.
337     For text properties, you should provide a validator (or none to allow
338       arbitrary text) and a default value if desired.
339     For number properties, the number is assumed to be a signed long integer.
340       Use the min & max params to specify a range if required.
341     For list properties, use as many param-value entries as necessary to represent
342       the list. If the list is editable, set the editable attribute on the type.
343       One exception here is if the list is the list of charsets or locales, use
344       param-locale or param-charset to specify this. These lists are provided by
345       the Locale and Charset classes in the JVM.
346
347     (I'm not actually defining ENTITY's here because Schema2Beans does not support them.)
348 -->
349 <!ELEMENT param-type ((param-value* | param-locale | param-charset), param-min?, param-max?)>
350 <!ATTLIST param-type type CDATA "text"
351                      editable CDATA "false"
352                      required CDATA "true">
353
354 <!ELEMENT param-value (#PCDATA)>
355 <!ELEMENT param-locale EMPTY>
356 <!ELEMENT param-charset EMPTY>
357 <!ELEMENT param-min (#PCDATA)>
358 <!ELEMENT param-max (#PCDATA)>
359
360 <!--
361     The text label (actually, will become bundle string id) to be used for the
362     value field instead of the word 'Value'
363 -->
364 <!ELEMENT param-label (#PCDATA)>
365
366 <!--
367     Validators are used to ensure the text in a text field matches a specific
368     pattern. The following validators are supported: (Can I support java
369     regular expression patterns here? It would make it lots easier!!!)
370     
371         directory: A directory path specification
372         javaid: A legal java identifier (allows java keywords though)
373         url: A URL string
374         domain: A domain. This is probably similar to javaid + represents a server domain
375         package: A legal java package name, e.g. javaid's separated by periods.
376         memorysize: A number followed by kb or mb (case insensitive)
377         classid: A windows classid (GUID)
378 -->
379 <!ELEMENT param-validator (#PCDATA)>
380
381 <!--
382     String that will become the default value for the property. If the property
383     value must fit a specific pattern, the default-value must qualify.
384 -->
385 <!ELEMENT default-value (#PCDATA)>
386
387 <!--
388     The help id for this field (or panel if specified at the property level,
389     which is likely what we'll do.
390 -->
391 <!ELEMENT help-id (#PCDATA)>
392
393
394 <!--
395     ID of string in bundle (see property-list attributes) to use for default
396     description.
397 -->
398 <!ELEMENT param-description (#PCDATA)>
399
400 <!-- !PW this would be used by property-param once it's done
401
402     Version of the appserver this property-param belongs to. Not present means
403     the property is applicable to all versions.
404     
405     Allowable Strings: major[.minor][pe|se|ee]
406         Major version is require.
407         Minor is optional (not present matches all)
408         Type is optional (not present matches all)
409         
410     For range attribute, valid values are:
411         ending, only, starting
412 <!ELEMENT appserver-version (#PCDATA)>
413 <!ATTLIST appserver-version range CDATA #IMPLIED>
414 -->
415
416 <!--
417     Validator definition. These are referred to by name from the <param-validator>
418     entry in <property-param>, above.
419 -->
420 <!ELEMENT validator (validator-name, validator-pattern)>
421
422 <!ELEMENT validator-name (#PCDATA)>
423
424 <!ELEMENT validator-pattern (#PCDATA)>
425
426
427
428 */

429
430
Popular Tags