KickJava   Java API By Example, From Geeks To Geeks.

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


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 Constraints matches the schema element constraints
26  *
27  * Generated on Wed Aug 20 17:20:08 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  * constraints : Constraints
33  * check-info : CheckInfo[0,n]
34  * name : String
35  * classname : String
36  * arguments : Arguments?
37  * argument : Argument[1,n]
38  * name : String
39  * type : String?
40  *
41  */

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

53 public class Constraints extends org.netbeans.modules.schema2beans.BaseBean
54 {
55
56     static Vector comparators = new Vector();
57
58     static public final String JavaDoc CHECK_INFO = "CheckInfo"; // NOI18N
59

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

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

332
Popular Tags