KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > sunresources > beans > Wizard


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 Wizard matches the schema element wizard
21  *
22  * Generated on Thu Sep 25 15:18:26 PDT 2003
23  *
24  * This class matches the root element of the DTD,
25  * and is the root of the following bean graph:
26  *
27  * wizard : Wizard
28  * name : String
29  * field-group : FieldGroup[1,n]
30  * name : String
31  * field : Field[1,n]
32  * [attr: field-type CDATA string]
33  * [attr: required CDATA true]
34  * name : String
35  * field-value : FieldValue
36  * default-field-value : String
37  * option-value-pair : OptionValuePair[0,n]
38  * option-name : String
39  * conditional-value : String
40  * tag : Tag?
41  * tag-item : String[0,n]
42  *
43  */

44
45 package org.netbeans.modules.j2ee.sun.sunresources.beans;
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 Wizard extends org.netbeans.modules.schema2beans.BaseBean
56 {
57
58     static Vector comparators = new Vector();
59
60     static public final String JavaDoc NAME = "Name"; // NOI18N
61
static public final String JavaDoc FIELD_GROUP = "FieldGroup"; // NOI18N
62

63     public Wizard() throws org.netbeans.modules.schema2beans.Schema2BeansException {
64         this(null, Common.USE_DEFAULT_VALUES);
65     }
66
67     public Wizard(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("wizard"); // NOI18N
76
if (doc == null){
77                 throw new Schema2BeansException(Common.getMessage(
78                     "CantCreateDOMRoot_msg", "wizard"));
79                         }
80         }
81         Node n = GraphManager.getElementNode("wizard", doc); // NOI18N
82
if (n == null){
83             throw new Schema2BeansException(Common.getMessage(
84                 "DocRootNotInDOMGraph_msg", "wizard", doc.getFirstChild().getNodeName()));
85                 }
86
87         this.graphManager.setXmlDocument(doc);
88
89         // Entry point of the createBeans() recursive calls
90
this.createBean(n, this.graphManager());
91         this.initialize(options);
92     }
93     public Wizard(int options)
94     {
95         super(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0));
96         initOptions(options);
97     }
98     protected void initOptions(int options)
99     {
100         // The graph manager is allocated in the bean root
101
this.graphManager = new GraphManager(this);
102         this.createRoot("wizard", "Wizard", // NOI18N
103
Common.TYPE_1 | Common.TYPE_BEAN, Wizard.class);
104
105         // Properties (see root bean comments for the bean graph)
106
this.createProperty("name", // NOI18N
107
NAME,
108             Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY,
109             String JavaDoc.class);
110         this.createProperty("field-group", // NOI18N
111
FIELD_GROUP,
112             Common.TYPE_1_N | Common.TYPE_BEAN | Common.TYPE_KEY,
113             FieldGroup.class);
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 setName(String JavaDoc value) {
125         this.setValue(NAME, value);
126     }
127
128     //
129
public String JavaDoc getName() {
130         return (String JavaDoc)this.getValue(NAME);
131     }
132
133     // This attribute is an array containing at least one element
134
public void setFieldGroup(int index, FieldGroup value) {
135         this.setValue(FIELD_GROUP, index, value);
136     }
137
138     //
139
public FieldGroup getFieldGroup(int index) {
140         return (FieldGroup)this.getValue(FIELD_GROUP, index);
141     }
142
143     // This attribute is an array containing at least one element
144
public void setFieldGroup(FieldGroup[] value) {
145         this.setValue(FIELD_GROUP, value);
146     }
147
148     //
149
public FieldGroup[] getFieldGroup() {
150         return (FieldGroup[])this.getValues(FIELD_GROUP);
151     }
152
153     // Return the number of properties
154
public int sizeFieldGroup() {
155         return this.size(FIELD_GROUP);
156     }
157
158     // Add a new element returning its index in the list
159
public int addFieldGroup(org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup value) {
160         return this.addValue(FIELD_GROUP, 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 removeFieldGroup(org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup value) {
168         return this.removeValue(FIELD_GROUP, 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 Wizard createGraph(org.w3c.dom.Node JavaDoc doc) throws org.netbeans.modules.schema2beans.Schema2BeansException {
185         return new Wizard(doc, Common.NO_DEFAULT_VALUES);
186     }
187
188     public static Wizard createGraph(java.io.InputStream JavaDoc in) throws org.netbeans.modules.schema2beans.Schema2BeansException {
189         return createGraph(in, false);
190     }
191
192     public static Wizard 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 Wizard createGraph() {
201         try {
202             return new Wizard();
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         // Validating property name
211
if (getName() == null) {
212             throw new org.netbeans.modules.schema2beans.ValidateException("getName() == null", "name", this); // NOI18N
213
}
214         // Validating property fieldGroup
215
if (sizeFieldGroup() == 0) {
216             throw new org.netbeans.modules.schema2beans.ValidateException("sizeFieldGroup() == 0", "fieldGroup", this); // NOI18N
217
}
218         for (int _index = 0; _index < sizeFieldGroup(); ++_index) {
219             org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup element = getFieldGroup(_index);
220             if (element != null) {
221                 element.validate();
222             }
223         }
224     }
225
226     // Special serializer: output XML as serialization
227
private void writeObject(java.io.ObjectOutputStream JavaDoc out) throws java.io.IOException JavaDoc{
228         ByteArrayOutputStream baos = new ByteArrayOutputStream();
229         write(baos);
230         String JavaDoc str = baos.toString();;
231         // System.out.println("str='"+str+"'");
232
out.writeUTF(str);
233     }
234     // Special deserializer: read XML as deserialization
235
private void readObject(java.io.ObjectInputStream JavaDoc in) throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc{
236         try{
237             init(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0));
238             String JavaDoc strDocument = in.readUTF();
239             // System.out.println("strDocument='"+strDocument+"'");
240
ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes());
241             Document doc = GraphManager.createXmlDocument(bais, false);
242             initOptions(Common.NO_DEFAULT_VALUES);
243             initFromNode(doc, Common.NO_DEFAULT_VALUES);
244         }
245         catch (Schema2BeansException e) {
246             e.printStackTrace();
247             throw new RuntimeException JavaDoc(e.getMessage());
248         }
249     }
250
251     // Dump the content of this bean returning it as a String
252
public void dump(StringBuffer JavaDoc str, String JavaDoc indent){
253         String JavaDoc s;
254         org.netbeans.modules.schema2beans.BaseBean n;
255         str.append(indent);
256         str.append("Name"); // NOI18N
257
str.append(indent+"\t"); // NOI18N
258
str.append("<"); // NOI18N
259
s = this.getName();
260         str.append((s==null?"null":s.trim())); // NOI18N
261
str.append(">\n"); // NOI18N
262
this.dumpAttributes(NAME, 0, str, indent);
263
264         str.append(indent);
265         str.append("FieldGroup["+this.sizeFieldGroup()+"]"); // NOI18N
266
for(int i=0; i<this.sizeFieldGroup(); i++)
267         {
268             str.append(indent+"\t");
269             str.append("#"+i+":");
270             n = (org.netbeans.modules.schema2beans.BaseBean) this.getFieldGroup(i);
271             if (n != null)
272                 n.dump(str, indent + "\t"); // NOI18N
273
else
274                 str.append(indent+"\tnull"); // NOI18N
275
this.dumpAttributes(FIELD_GROUP, i, str, indent);
276         }
277
278     }
279     public String JavaDoc dumpBeanNode(){
280         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
281         str.append("Wizard\n"); // NOI18N
282
this.dump(str, "\n "); // NOI18N
283
return str.toString();
284     }}
285
286 // END_NOI18N
287

288
289 /*
290         The following schema file has been used for generation:
291
292 <!ELEMENT wizard (name, field-group+)>
293 <!ELEMENT field-group (name, field+)>
294 <!ELEMENT field (name, field-value, tag?)>
295 <!ATTLIST field field-type CDATA "string"
296                  required CDATA "true">
297 <!ELEMENT field-value (default-field-value, option-value-pair*)>
298 <!ELEMENT option-value-pair (option-name, conditional-value)>
299 <!ELEMENT name (#PCDATA)>
300 <!ELEMENT default-field-value (#PCDATA)>
301 <!ELEMENT option-name (#PCDATA)>
302 <!ELEMENT conditional-value (#PCDATA)>
303 <!ELEMENT tag (tag-item*)>
304 <!ELEMENT tag-item (#PCDATA)>
305
306
307
308 */

309
Popular Tags