KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > validation > data > Validation


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 /**
21  * This generated bean class Validation matches the schema element validation
22  *
23  *
24  * This class matches the root element of the DTD,
25  * and is the root of the following bean graph:
26  *
27  * validation : Validation
28  * [attr: validate ENUM ( true false ) true]
29  * element : Element[0,n]
30  * name : String
31  * check : Check[0,n]
32  * name : String
33  * parameters : Parameters?
34  * parameter : Parameter[1,n]
35  * name : String
36  * value : String[1,n]
37  *
38  */

39
40 package org.netbeans.modules.j2ee.sun.validation.data;
41
42 import org.w3c.dom.*;
43 import org.netbeans.modules.schema2beans.*;
44 import java.beans.*;
45 import java.util.*;
46 import java.io.*;
47
48 // BEGIN_NOI18N
49

50 public class Validation extends org.netbeans.modules.schema2beans.BaseBean
51 {
52
53     static Vector comparators = new Vector();
54
55     static public final String JavaDoc VALIDATE = "Validate"; // NOI18N
56
static public final String JavaDoc ELEMENT = "Element"; // NOI18N
57

58     public Validation() throws org.netbeans.modules.schema2beans.Schema2BeansException {
59         this(null, Common.USE_DEFAULT_VALUES);
60     }
61
62     public Validation(org.w3c.dom.Node JavaDoc doc, int options) throws org.netbeans.modules.schema2beans.Schema2BeansException {
63         this(Common.NO_DEFAULT_VALUES);
64         initFromNode(doc, options);
65     }
66     protected void initFromNode(org.w3c.dom.Node JavaDoc doc, int options) throws Schema2BeansException
67     {
68         if (doc == null)
69         {
70             doc = GraphManager.createRootElementNode("validation"); // NOI18N
71
if (doc == null)
72                 throw new Schema2BeansException(Common.getMessage(
73                     "CantCreateDOMRoot_msg", "validation"));
74         }
75         Node n = GraphManager.getElementNode("validation", doc); // NOI18N
76
if (n == null)
77             throw new Schema2BeansException(Common.getMessage(
78                 "DocRootNotInDOMGraph_msg", "validation", doc.getFirstChild().getNodeName()));
79
80         this.graphManager.setXmlDocument(doc);
81
82         // Entry point of the createBeans() recursive calls
83
this.createBean(n, this.graphManager());
84         this.initialize(options);
85     }
86     public Validation(int options)
87     {
88         super(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0));
89         initOptions(options);
90     }
91     protected void initOptions(int options)
92     {
93         // The graph manager is allocated in the bean root
94
this.graphManager = new GraphManager(this);
95         this.createRoot("validation", "Validation", // NOI18N
96
Common.TYPE_1 | Common.TYPE_BEAN, Validation.class);
97
98         // Properties (see root bean comments for the bean graph)
99
this.createProperty("element", // NOI18N
100
ELEMENT,
101             Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY,
102             Element.class);
103         this.createAttribute("validate", "Validate",
104                         AttrProp.ENUM,
105                         new String JavaDoc[] {
106                             "true",
107                             "false"
108                         }, "true");
109         this.initialize(options);
110     }
111
112     // Setting the default values of the properties
113
void initialize(int options)
114     {
115
116     }
117
118     // This attribute is mandatory
119
public void setValidate(java.lang.String JavaDoc value) {
120         setAttributeValue(VALIDATE, value);
121     }
122
123     //
124
public java.lang.String JavaDoc getValidate() {
125         return getAttributeValue(VALIDATE);
126     }
127
128     // This attribute is an array, possibly empty
129
public void setElement(int index, Element value) {
130         this.setValue(ELEMENT, index, value);
131     }
132
133     //
134
public Element getElement(int index) {
135         return (Element)this.getValue(ELEMENT, index);
136     }
137
138     // This attribute is an array, possibly empty
139
public void setElement(Element[] value) {
140         this.setValue(ELEMENT, value);
141     }
142
143     //
144
public Element[] getElement() {
145         return (Element[])this.getValues(ELEMENT);
146     }
147
148     // Return the number of properties
149
public int sizeElement() {
150         return this.size(ELEMENT);
151     }
152
153     // Add a new element returning its index in the list
154
public int addElement(org.netbeans.modules.j2ee.sun.validation.data.Element value) {
155         return this.addValue(ELEMENT, value);
156     }
157
158     //
159
// Remove an element using its reference
160
// Returns the index the element had in the list
161
//
162
public int removeElement(org.netbeans.modules.j2ee.sun.validation.data.Element value) {
163         return this.removeValue(ELEMENT, value);
164     }
165
166     //
167
public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) {
168         comparators.add(c);
169     }
170
171     //
172
public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) {
173         comparators.remove(c);
174     }
175     //
176
// This method returns the root of the bean graph
177
// Each call creates a new bean graph from the specified DOM graph
178
//
179
public static Validation createGraph(org.w3c.dom.Node JavaDoc doc) throws org.netbeans.modules.schema2beans.Schema2BeansException {
180         return new Validation(doc, Common.NO_DEFAULT_VALUES);
181     }
182
183     public static Validation createGraph(java.io.InputStream JavaDoc in) throws org.netbeans.modules.schema2beans.Schema2BeansException {
184         return createGraph(in, false);
185     }
186
187     public static Validation createGraph(java.io.InputStream JavaDoc in, boolean validate) throws org.netbeans.modules.schema2beans.Schema2BeansException {
188         Document doc = GraphManager.createXmlDocument(in, validate);
189         return createGraph(doc);
190     }
191
192     //
193
// This method returns the root for a new empty bean graph
194
//
195
public static Validation createGraph() {
196         try {
197             return new Validation();
198         }
199         catch (Schema2BeansException e) {
200             throw new RuntimeException JavaDoc(e.getMessage());
201         }
202     }
203
204     public void validate() throws org.netbeans.modules.schema2beans.ValidateException {
205         boolean restrictionFailure = false;
206         // Validating property validate
207
if (getValidate() == null) {
208             throw new org.netbeans.modules.schema2beans.ValidateException("getValidate() == null", "validate", this); // NOI18N
209
}
210         // Validating property element
211
for (int _index = 0; _index < sizeElement(); ++_index) {
212             org.netbeans.modules.j2ee.sun.validation.data.Element element = getElement(_index);
213             if (element != null) {
214                 element.validate();
215             }
216         }
217     }
218
219     // Special serializer: output XML as serialization
220
private void writeObject(java.io.ObjectOutputStream JavaDoc out) throws java.io.IOException JavaDoc{
221         ByteArrayOutputStream baos = new ByteArrayOutputStream();
222         write(baos);
223         String JavaDoc str = baos.toString();;
224         // System.out.println("str='"+str+"'");
225
out.writeUTF(str);
226     }
227     // Special deserializer: read XML as deserialization
228
private void readObject(java.io.ObjectInputStream JavaDoc in) throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc{
229         try{
230             init(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0));
231             String JavaDoc strDocument = in.readUTF();
232             // System.out.println("strDocument='"+strDocument+"'");
233
ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes());
234             Document doc = GraphManager.createXmlDocument(bais, false);
235             initOptions(Common.NO_DEFAULT_VALUES);
236             initFromNode(doc, Common.NO_DEFAULT_VALUES);
237         }
238         catch (Schema2BeansException e) {
239             e.printStackTrace();
240             throw new RuntimeException JavaDoc(e.getMessage());
241         }
242     }
243
244     // Dump the content of this bean returning it as a String
245
public void dump(StringBuffer JavaDoc str, String JavaDoc indent){
246         String JavaDoc s;
247         Object JavaDoc o;
248         org.netbeans.modules.schema2beans.BaseBean n;
249         str.append(indent);
250         str.append("Element["+this.sizeElement()+"]"); // NOI18N
251
for(int i=0; i<this.sizeElement(); i++)
252         {
253             str.append(indent+"\t");
254             str.append("#"+i+":");
255             n = (org.netbeans.modules.schema2beans.BaseBean) this.getElement(i);
256             if (n != null)
257                 n.dump(str, indent + "\t"); // NOI18N
258
else
259                 str.append(indent+"\tnull"); // NOI18N
260
this.dumpAttributes(ELEMENT, i, str, indent);
261         }
262
263     }
264     public String JavaDoc dumpBeanNode(){
265         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
266         str.append("Validation\n"); // NOI18N
267
this.dump(str, "\n "); // NOI18N
268
return str.toString();
269     }}
270
271 // END_NOI18N
272

273
274 /*
275         The following schema file has been used for generation:
276
277 <!--
278   XML DTD for for validation xml.
279   validation.xml is used to specify Constraints to be applied to
280   elements.
281  
282   $Revision: 1.2 $
283 -->
284
285
286 <!--
287 This is the root element
288 -->
289 <!ELEMENT validation (element*) >
290 <!ATTLIST validation
291         validate CDATA (true | false) "true">
292
293
294 <!--
295 This element represents, the set of Constraints to be applied to
296 the given element.
297 -->
298 <!ELEMENT element (name, check*)>
299
300
301 <!--
302 This element represents, a particular Constraint.
303 Note : Information about this Constraint must be provided through
304 corresponding <check-info> object in constraints.xml Sub element
305 <name> should match with <name> of corresponding <check-info>
306 element defined in constraints.xml.
307 -->
308 <!ELEMENT check (name, parameters?)>
309
310
311 <!--
312 This element represent, Constraint parameters.
313 Number of sub elements, <parameter> should match with the number
314 of <argument> sub elements, of corresponding <arguments> element
315 in constraints.xml
316 -->
317 <!ELEMENT parameters (parameter+)>
318
319
320 <!--
321 This element represents, a Constraint parameter.
322 Sub elements <name> should match with the <name> sub element of
323 corresponding <argument> element in constraints.xml
324 <value> could be one or more. In case of an variable array
325 argument, multiple <value> elements will be used.
326 Example : InConstraint
327 -->
328 <!ELEMENT parameter (name, value+)>
329
330
331 <!--
332 Used in elements : <element>, <check> and <parameter>
333 In <element> , it represents the name(xpath - complete absolute
334 name of an element(leaf).
335 In <check> , it represents name of a Constraint. This is the
336 linking element for <check> element in validation.xml and
337 <check-info> element in constraints.xml.
338 In <parameter>, it represents name of parameter. This is the
339 linking element for <parameter> element in validation.xml and
340 <argument> element in constraints.xml.
341 -->
342 <!ELEMENT name (#PCDATA)>
343
344
345 <!--
346 This element represents the value of a parameter.
347 -->
348 <!ELEMENT value (#PCDATA)>
349
350 */

351
Popular Tags