KickJava   Java API By Example, From Geeks To Geeks.

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


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 Constraints matches the schema element constraints
22  *
23  *
24  * This class matches the root element of the DTD,
25  * and is the root of the following bean graph:
26  *
27  * constraints : Constraints
28  * check-info : CheckInfo[0,n]
29  * name : String
30  * classname : String
31  * arguments : Arguments?
32  * argument : Argument[1,n]
33  * name : String
34  * type : String?
35  *
36  */

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

48 public class Constraints extends org.netbeans.modules.schema2beans.BaseBean
49 {
50
51     static Vector comparators = new Vector();
52
53     static public final String JavaDoc CHECK_INFO = "CheckInfo"; // NOI18N
54

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

250
251 /*
252         The following schema file has been used for generation:
253
254 <!--
255   XML DTD for for constraints xml.
256   constraints.xml is used to specify provide information of the
257   Constraints to the Validation framework.
258  
259   $Revision: 1.2 $
260 -->
261
262
263 <!--
264 This is the root element.
265 -->
266 <!ELEMENT constraints (check-info*)>
267
268
269 <!--
270 This represents an information, about a particular Constraint.
271 Provides information of a Constraint represented by corresponding
272 <check> element in validation.xml.
273 Sub element <name> is used to link this element with the
274 corresponding <check> element in validation.xml.
275 -->
276 <!ELEMENT check-info (name, classname, arguments?)>
277
278
279 <!--
280 This element represents information of a Constraint class arguments.
281 Number of sub elements, <argument> should match with the number
282 of <parameter> sub elements, of corresponding <arguments> element
283 in validation.xml
284 -->
285 <!ELEMENT arguments (argument+)>
286
287
288 <!--
289 This element represents information of a single Constraint class
290 argument.
291 Sub elements <name> should match with the <name> sub element of
292 corresponding <parameter> element in constraints.xml
293 -->
294 <!ELEMENT argument (name, type?)>
295
296
297 <!--
298 Used in two elements <check-info> and <argument>
299 In <check-info>, it represents a Constraint name and is the linking
300 element between <check> element in validation.xml and <check-info>
301 element in constraints.xml.
302 In <argument>, it represents argument name and is the linking element
303 between <parameter> element in validation.xml and <argument> element
304 in constraints.xml.
305 -->
306 <!ELEMENT name (#PCDATA)>
307
308
309 <!--
310 This element represents Constraint class name.
311 Constraint class should provide the constructor with no arguments.
312 Constraint class should also provide the set* methods for all the
313 required arguments.
314 Constraint class is always created using default constructor and
315 then the arguments are set using set* methods.
316 -->
317 <!ELEMENT classname (#PCDATA)>
318
319
320 <!--
321 This element represents the type of an argument.
322 If not specified, it defaults to java.lang.String
323 -->
324 <!ELEMENT type (#PCDATA)>
325
326 */

327
Popular Tags