001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /**
042: * This generated bean class Wizard matches the schema element wizard
043: *
044: * Generated on Thu Sep 25 15:18:26 PDT 2003
045: *
046: * This class matches the root element of the DTD,
047: * and is the root of the following bean graph:
048: *
049: * wizard : Wizard
050: * name : String
051: * field-group : FieldGroup[1,n]
052: * name : String
053: * field : Field[1,n]
054: * [attr: field-type CDATA string]
055: * [attr: required CDATA true]
056: * name : String
057: * field-value : FieldValue
058: * default-field-value : String
059: * option-value-pair : OptionValuePair[0,n]
060: * option-name : String
061: * conditional-value : String
062: * tag : Tag?
063: * tag-item : String[0,n]
064: *
065: */package org.netbeans.modules.j2ee.sun.sunresources.beans;
066:
067: import org.w3c.dom.*;
068: import org.netbeans.modules.schema2beans.*;
069: import java.beans.*;
070: import java.util.*;
071: import java.io.*;
072:
073: // BEGIN_NOI18N
074:
075: public class Wizard extends org.netbeans.modules.schema2beans.BaseBean {
076:
077: static Vector comparators = new Vector();
078:
079: static public final String NAME = "Name"; // NOI18N
080: static public final String FIELD_GROUP = "FieldGroup"; // NOI18N
081:
082: public Wizard()
083: throws org.netbeans.modules.schema2beans.Schema2BeansException {
084: this (null, Common.USE_DEFAULT_VALUES);
085: }
086:
087: public Wizard(org.w3c.dom.Node doc, int options)
088: throws org.netbeans.modules.schema2beans.Schema2BeansException {
089: this (Common.NO_DEFAULT_VALUES);
090: initFromNode(doc, options);
091: }
092:
093: protected void initFromNode(org.w3c.dom.Node doc, int options)
094: throws Schema2BeansException {
095: if (doc == null) {
096: doc = GraphManager.createRootElementNode("wizard"); // NOI18N
097: if (doc == null) {
098: throw new Schema2BeansException(Common.getMessage(
099: "CantCreateDOMRoot_msg", "wizard"));
100: }
101: }
102: Node n = GraphManager.getElementNode("wizard", doc); // NOI18N
103: if (n == null) {
104: throw new Schema2BeansException(Common.getMessage(
105: "DocRootNotInDOMGraph_msg", "wizard", doc
106: .getFirstChild().getNodeName()));
107: }
108:
109: this .graphManager.setXmlDocument(doc);
110:
111: // Entry point of the createBeans() recursive calls
112: this .createBean(n, this .graphManager());
113: this .initialize(options);
114: }
115:
116: public Wizard(int options) {
117: super (comparators,
118: new org.netbeans.modules.schema2beans.Version(1, 2, 0));
119: initOptions(options);
120: }
121:
122: protected void initOptions(int options) {
123: // The graph manager is allocated in the bean root
124: this .graphManager = new GraphManager(this );
125: this .createRoot("wizard", "Wizard", // NOI18N
126: Common.TYPE_1 | Common.TYPE_BEAN, Wizard.class);
127:
128: // Properties (see root bean comments for the bean graph)
129: this .createProperty("name", // NOI18N
130: NAME, Common.TYPE_1 | Common.TYPE_STRING
131: | Common.TYPE_KEY, String.class);
132: this .createProperty("field-group", // NOI18N
133: FIELD_GROUP, Common.TYPE_1_N | Common.TYPE_BEAN
134: | Common.TYPE_KEY, FieldGroup.class);
135: this .initialize(options);
136: }
137:
138: // Setting the default values of the properties
139: void initialize(int options) {
140:
141: }
142:
143: // This attribute is mandatory
144: public void setName(String value) {
145: this .setValue(NAME, value);
146: }
147:
148: //
149: public String getName() {
150: return (String) this .getValue(NAME);
151: }
152:
153: // This attribute is an array containing at least one element
154: public void setFieldGroup(int index, FieldGroup value) {
155: this .setValue(FIELD_GROUP, index, value);
156: }
157:
158: //
159: public FieldGroup getFieldGroup(int index) {
160: return (FieldGroup) this .getValue(FIELD_GROUP, index);
161: }
162:
163: // This attribute is an array containing at least one element
164: public void setFieldGroup(FieldGroup[] value) {
165: this .setValue(FIELD_GROUP, value);
166: }
167:
168: //
169: public FieldGroup[] getFieldGroup() {
170: return (FieldGroup[]) this .getValues(FIELD_GROUP);
171: }
172:
173: // Return the number of properties
174: public int sizeFieldGroup() {
175: return this .size(FIELD_GROUP);
176: }
177:
178: // Add a new element returning its index in the list
179: public int addFieldGroup(
180: org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup value) {
181: return this .addValue(FIELD_GROUP, value);
182: }
183:
184: //
185: // Remove an element using its reference
186: // Returns the index the element had in the list
187: //
188: public int removeFieldGroup(
189: org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup value) {
190: return this .removeValue(FIELD_GROUP, value);
191: }
192:
193: //
194: public static void addComparator(
195: org.netbeans.modules.schema2beans.BeanComparator c) {
196: comparators.add(c);
197: }
198:
199: //
200: public static void removeComparator(
201: org.netbeans.modules.schema2beans.BeanComparator c) {
202: comparators.remove(c);
203: }
204:
205: //
206: // This method returns the root of the bean graph
207: // Each call creates a new bean graph from the specified DOM graph
208: //
209: public static Wizard createGraph(org.w3c.dom.Node doc)
210: throws org.netbeans.modules.schema2beans.Schema2BeansException {
211: return new Wizard(doc, Common.NO_DEFAULT_VALUES);
212: }
213:
214: public static Wizard createGraph(java.io.InputStream in)
215: throws org.netbeans.modules.schema2beans.Schema2BeansException {
216: return createGraph(in, false);
217: }
218:
219: public static Wizard createGraph(java.io.InputStream in,
220: boolean validate)
221: throws org.netbeans.modules.schema2beans.Schema2BeansException {
222: Document doc = GraphManager.createXmlDocument(in, validate);
223: return createGraph(doc);
224: }
225:
226: //
227: // This method returns the root for a new empty bean graph
228: //
229: public static Wizard createGraph() {
230: try {
231: return new Wizard();
232: } catch (Schema2BeansException e) {
233: throw new RuntimeException(e.getMessage());
234: }
235: }
236:
237: public void validate()
238: throws org.netbeans.modules.schema2beans.ValidateException {
239: // Validating property name
240: if (getName() == null) {
241: throw new org.netbeans.modules.schema2beans.ValidateException(
242: "getName() == null", "name", this ); // NOI18N
243: }
244: // Validating property fieldGroup
245: if (sizeFieldGroup() == 0) {
246: throw new org.netbeans.modules.schema2beans.ValidateException(
247: "sizeFieldGroup() == 0", "fieldGroup", this ); // NOI18N
248: }
249: for (int _index = 0; _index < sizeFieldGroup(); ++_index) {
250: org.netbeans.modules.j2ee.sun.sunresources.beans.FieldGroup element = getFieldGroup(_index);
251: if (element != null) {
252: element.validate();
253: }
254: }
255: }
256:
257: // Special serializer: output XML as serialization
258: private void writeObject(java.io.ObjectOutputStream out)
259: throws java.io.IOException {
260: ByteArrayOutputStream baos = new ByteArrayOutputStream();
261: write(baos);
262: String str = baos.toString();
263: ;
264: // System.out.println("str='"+str+"'");
265: out.writeUTF(str);
266: }
267:
268: // Special deserializer: read XML as deserialization
269: private void readObject(java.io.ObjectInputStream in)
270: throws java.io.IOException, ClassNotFoundException {
271: try {
272: init(comparators,
273: new org.netbeans.modules.schema2beans.Version(1, 2,
274: 0));
275: String strDocument = in.readUTF();
276: // System.out.println("strDocument='"+strDocument+"'");
277: ByteArrayInputStream bais = new ByteArrayInputStream(
278: strDocument.getBytes());
279: Document doc = GraphManager.createXmlDocument(bais, false);
280: initOptions(Common.NO_DEFAULT_VALUES);
281: initFromNode(doc, Common.NO_DEFAULT_VALUES);
282: } catch (Schema2BeansException e) {
283: e.printStackTrace();
284: throw new RuntimeException(e.getMessage());
285: }
286: }
287:
288: // Dump the content of this bean returning it as a String
289: public void dump(StringBuffer str, String indent) {
290: String s;
291: org.netbeans.modules.schema2beans.BaseBean n;
292: str.append(indent);
293: str.append("Name"); // NOI18N
294: str.append(indent + "\t"); // NOI18N
295: str.append("<"); // NOI18N
296: s = this .getName();
297: str.append((s == null ? "null" : s.trim())); // NOI18N
298: str.append(">\n"); // NOI18N
299: this .dumpAttributes(NAME, 0, str, indent);
300:
301: str.append(indent);
302: str.append("FieldGroup[" + this .sizeFieldGroup() + "]"); // NOI18N
303: for (int i = 0; i < this .sizeFieldGroup(); i++) {
304: str.append(indent + "\t");
305: str.append("#" + i + ":");
306: n = (org.netbeans.modules.schema2beans.BaseBean) this
307: .getFieldGroup(i);
308: if (n != null)
309: n.dump(str, indent + "\t"); // NOI18N
310: else
311: str.append(indent + "\tnull"); // NOI18N
312: this .dumpAttributes(FIELD_GROUP, i, str, indent);
313: }
314:
315: }
316:
317: public String dumpBeanNode() {
318: StringBuffer str = new StringBuffer();
319: str.append("Wizard\n"); // NOI18N
320: this .dump(str, "\n "); // NOI18N
321: return str.toString();
322: }
323: }
324:
325: // END_NOI18N
326:
327: /*
328: The following schema file has been used for generation:
329:
330: <!ELEMENT wizard (name, field-group+)>
331: <!ELEMENT field-group (name, field+)>
332: <!ELEMENT field (name, field-value, tag?)>
333: <!ATTLIST field field-type CDATA "string"
334: required CDATA "true">
335: <!ELEMENT field-value (default-field-value, option-value-pair*)>
336: <!ELEMENT option-value-pair (option-name, conditional-value)>
337: <!ELEMENT name (#PCDATA)>
338: <!ELEMENT default-field-value (#PCDATA)>
339: <!ELEMENT option-name (#PCDATA)>
340: <!ELEMENT conditional-value (#PCDATA)>
341: <!ELEMENT tag (tag-item*)>
342: <!ELEMENT tag-item (#PCDATA)>
343:
344:
345:
346: */
|