KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > validation > data > Validation


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /**
25  * This generated bean class Validation matches the schema element validation
26  *
27  * Generated on Wed Aug 20 17:21:25 PDT 2003
28  *
29  * This class matches the root element of the DTD,
30  * and is the root of the following bean graph:
31  *
32  * validation : Validation
33  * [attr: validate ENUM ( true false ) true]
34  * element : Element[0,n]
35  * name : String
36  * check : Check[0,n]
37  * name : String
38  * parameters : Parameters?
39  * parameter : Parameter[1,n]
40  * name : String
41  * value : String[1,n]
42  *
43  */

44
45 package com.sun.enterprise.tools.common.validation.data;
46
47 import org.w3c.dom.*;
48 import org.netbeans.modules.schema2beans.*;
49 import java.beans.*;
50 import java.util.*;
51 import java.io.*;
52
53 // BEGIN_NOI18N
54

55 public class Validation extends org.netbeans.modules.schema2beans.BaseBean
56 {
57
58     static Vector comparators = new Vector();
59
60     static public final String JavaDoc VALIDATE = "Validate"; // NOI18N
61
static public final String JavaDoc ELEMENT = "Element"; // NOI18N
62

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

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

356
Popular Tags