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 Book matches the schema element 'book'.
043: *
044: * Generated on Wed Mar 09 17:37:54 CET 2005
045: *
046: * This class matches the root element of the DTD,
047: * and is the root of the following bean graph:
048: *
049: * book <book> : Book
050: * [attr: instock ENUM ( yes no ) yes]
051: * title <title> : String
052: * [attr: lang CDATA #FIXED en]
053: * chapter <chapter> : Chapter[1,n]
054: * [attr: length CDATA #IMPLIED ]
055: * title <title> : String
056: * [attr: lang CDATA #FIXED en]
057: * summary <summary> : String[0,1]
058: * paragraph <paragraph> : String[0,n]
059: * paperback <paperback> : boolean[0,1]
060: * EMPTY : String
061: * price <price> : String[0,1]
062: *
063: * @Generated
064: */package org.netbeans.modules.xml.multiview.test.bookmodel;
065:
066: import org.w3c.dom.*;
067: import org.netbeans.modules.schema2beans.*;
068: import java.beans.*;
069: import java.util.*;
070: import java.io.*;
071:
072: // BEGIN_NOI18N
073:
074: public class Book extends org.netbeans.modules.schema2beans.BaseBean {
075:
076: static Vector comparators = new Vector();
077: private static final org.netbeans.modules.schema2beans.Version runtimeVersion = new org.netbeans.modules.schema2beans.Version(
078: 4, 0, 0);
079:
080: static public final String TITLE = "Title"; // NOI18N
081: static public final String CHAPTER = "Chapter"; // NOI18N
082: static public final String PAPERBACK = "Paperback"; // NOI18N
083: static public final String PRICE = "Price"; // NOI18N
084:
085: public Book() {
086: this (null, Common.USE_DEFAULT_VALUES);
087: }
088:
089: public Book(org.w3c.dom.Node doc, int options) {
090: this (Common.NO_DEFAULT_VALUES);
091: try {
092: initFromNode(doc, options);
093: } catch (Schema2BeansException e) {
094: throw new RuntimeException(e);
095: }
096: }
097:
098: protected void initFromNode(org.w3c.dom.Node doc, int options)
099: throws Schema2BeansException {
100: if (doc == null) {
101: doc = GraphManager.createRootElementNode("book"); // NOI18N
102: if (doc == null)
103: throw new Schema2BeansException(Common.getMessage(
104: "CantCreateDOMRoot_msg", "book"));
105: }
106: Node n = GraphManager.getElementNode("book", doc); // NOI18N
107: if (n == null)
108: throw new Schema2BeansException(Common.getMessage(
109: "DocRootNotInDOMGraph_msg", "book", doc
110: .getFirstChild().getNodeName()));
111:
112: this .graphManager.setXmlDocument(doc);
113:
114: // Entry point of the createBeans() recursive calls
115: this .createBean(n, this .graphManager());
116: this .initialize(options);
117: }
118:
119: public Book(int options) {
120: super (comparators, runtimeVersion);
121: initOptions(options);
122: }
123:
124: protected void initOptions(int options) {
125: // The graph manager is allocated in the bean root
126: this .graphManager = new GraphManager(this );
127: this .createRoot("book", "Book", // NOI18N
128: Common.TYPE_1 | Common.TYPE_BEAN, Book.class);
129:
130: // Properties (see root bean comments for the bean graph)
131: initPropertyTables(4);
132: this .createProperty("title", // NOI18N
133: TITLE, Common.TYPE_1 | Common.TYPE_STRING
134: | Common.TYPE_KEY, String.class);
135: this .createAttribute(TITLE, "lang", "Lang", AttrProp.CDATA
136: | AttrProp.FIXED, null, "en");
137: this .createProperty("chapter", // NOI18N
138: CHAPTER, Common.TYPE_1_N | Common.TYPE_BEAN
139: | Common.TYPE_KEY, Chapter.class);
140: this .createAttribute(CHAPTER, "length", "Length",
141: AttrProp.CDATA | AttrProp.IMPLIED, null, null);
142: this .createProperty("paperback", // NOI18N
143: PAPERBACK, Common.TYPE_0_1 | Common.TYPE_BOOLEAN
144: | Common.TYPE_KEY, Boolean.class);
145: this .createProperty("price", // NOI18N
146: PRICE, Common.TYPE_0_1 | Common.TYPE_STRING
147: | Common.TYPE_KEY, String.class);
148: this .createAttribute("instock", "Instock", AttrProp.ENUM,
149: new String[] { "yes", "no" }, "yes");
150: this .initialize(options);
151: }
152:
153: // Setting the default values of the properties
154: void initialize(int options) {
155:
156: }
157:
158: // This attribute is mandatory
159: public void setTitle(String value) {
160: this .setValue(TITLE, value);
161: }
162:
163: //
164: public String getTitle() {
165: return (String) this .getValue(TITLE);
166: }
167:
168: // This attribute is an array containing at least one element
169: public void setChapter(int index, Chapter value) {
170: this .setValue(CHAPTER, index, value);
171: }
172:
173: //
174: public Chapter getChapter(int index) {
175: return (Chapter) this .getValue(CHAPTER, index);
176: }
177:
178: // Return the number of properties
179: public int sizeChapter() {
180: return this .size(CHAPTER);
181: }
182:
183: // This attribute is an array containing at least one element
184: public void setChapter(Chapter[] value) {
185: this .setValue(CHAPTER, value);
186: }
187:
188: //
189: public Chapter[] getChapter() {
190: return (Chapter[]) this .getValues(CHAPTER);
191: }
192:
193: // Add a new element returning its index in the list
194: public int addChapter(
195: org.netbeans.modules.xml.multiview.test.bookmodel.Chapter value) {
196: int positionOfNewItem = this .addValue(CHAPTER, value);
197: return positionOfNewItem;
198: }
199:
200: //
201: // Remove an element using its reference
202: // Returns the index the element had in the list
203: //
204: public int removeChapter(
205: org.netbeans.modules.xml.multiview.test.bookmodel.Chapter value) {
206: return this .removeValue(CHAPTER, value);
207: }
208:
209: // This attribute is optional
210: public void setPaperback(boolean value) {
211: this .setValue(PAPERBACK, (value ? java.lang.Boolean.TRUE
212: : java.lang.Boolean.FALSE));
213: }
214:
215: //
216: public boolean isPaperback() {
217: Boolean ret = (Boolean) this .getValue(PAPERBACK);
218: if (ret == null)
219: ret = (Boolean) Common
220: .defaultScalarValue(Common.TYPE_BOOLEAN);
221: return ((java.lang.Boolean) ret).booleanValue();
222: }
223:
224: // This attribute is optional
225: public void setPrice(String value) {
226: this .setValue(PRICE, value);
227: }
228:
229: //
230: public String getPrice() {
231: return (String) this .getValue(PRICE);
232: }
233:
234: /**
235: * Create a new bean using it's default constructor.
236: * This does not add it to any bean graph.
237: */
238: public Chapter newChapter() {
239: return new Chapter();
240: }
241:
242: //
243: public static void addComparator(
244: org.netbeans.modules.schema2beans.BeanComparator c) {
245: comparators.add(c);
246: }
247:
248: //
249: public static void removeComparator(
250: org.netbeans.modules.schema2beans.BeanComparator c) {
251: comparators.remove(c);
252: }
253:
254: //
255: // This method returns the root of the bean graph
256: // Each call creates a new bean graph from the specified DOM graph
257: //
258: public static Book createGraph(org.w3c.dom.Node doc) {
259: return new Book(doc, Common.NO_DEFAULT_VALUES);
260: }
261:
262: public static Book createGraph(java.io.File f)
263: throws java.io.IOException {
264: java.io.InputStream in = new java.io.FileInputStream(f);
265: try {
266: return createGraph(in, false);
267: } finally {
268: in.close();
269: }
270: }
271:
272: public static Book createGraph(java.io.InputStream in) {
273: return createGraph(in, false);
274: }
275:
276: public static Book createGraph(java.io.InputStream in,
277: boolean validate) {
278: try {
279: Document doc = GraphManager.createXmlDocument(in, validate);
280: return createGraph(doc);
281: } catch (Exception t) {
282: throw new RuntimeException(Common.getMessage(
283: "DOMGraphCreateFailed_msg", t));
284: }
285: }
286:
287: //
288: // This method returns the root for a new empty bean graph
289: //
290: public static Book createGraph() {
291: return new Book();
292: }
293:
294: public void validate()
295: throws org.netbeans.modules.schema2beans.ValidateException {
296: boolean restrictionFailure = false;
297: boolean restrictionPassed = false;
298: // Validating property title
299: if (getTitle() == null) {
300: throw new org.netbeans.modules.schema2beans.ValidateException(
301: "getTitle() == null",
302: org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE,
303: "title", this ); // NOI18N
304: }
305: // Validating property chapter
306: if (sizeChapter() == 0) {
307: throw new org.netbeans.modules.schema2beans.ValidateException(
308: "sizeChapter() == 0",
309: org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE,
310: "chapter", this ); // NOI18N
311: }
312: for (int _index = 0; _index < sizeChapter(); ++_index) {
313: org.netbeans.modules.xml.multiview.test.bookmodel.Chapter element = getChapter(_index);
314: if (element != null) {
315: element.validate();
316: }
317: }
318: // Validating property paperback
319: // Validating property price
320: }
321:
322: // Special serializer: output XML as serialization
323: private void writeObject(java.io.ObjectOutputStream out)
324: throws java.io.IOException {
325: ByteArrayOutputStream baos = new ByteArrayOutputStream();
326: write(baos);
327: String str = baos.toString();
328: ;
329: // System.out.println("str='"+str+"'");
330: out.writeUTF(str);
331: }
332:
333: // Special deserializer: read XML as deserialization
334: private void readObject(java.io.ObjectInputStream in)
335: throws java.io.IOException, ClassNotFoundException {
336: try {
337: init(comparators, runtimeVersion);
338: String strDocument = in.readUTF();
339: // System.out.println("strDocument='"+strDocument+"'");
340: ByteArrayInputStream bais = new ByteArrayInputStream(
341: strDocument.getBytes());
342: Document doc = GraphManager.createXmlDocument(bais, false);
343: initOptions(Common.NO_DEFAULT_VALUES);
344: initFromNode(doc, Common.NO_DEFAULT_VALUES);
345: } catch (Schema2BeansException e) {
346: throw new RuntimeException(e);
347: }
348: }
349:
350: public void _setSchemaLocation(String location) {
351: if (beanProp().getAttrProp("xsi:schemaLocation", true) == null) {
352: createAttribute("xmlns:xsi", "xmlns:xsi", AttrProp.CDATA
353: | AttrProp.IMPLIED, null,
354: "http://www.w3.org/2001/XMLSchema-instance");
355: setAttributeValue("xmlns:xsi",
356: "http://www.w3.org/2001/XMLSchema-instance");
357: createAttribute("xsi:schemaLocation", "xsi:schemaLocation",
358: AttrProp.CDATA | AttrProp.IMPLIED, null, location);
359: }
360: setAttributeValue("xsi:schemaLocation", location);
361: }
362:
363: public String _getSchemaLocation() {
364: if (beanProp().getAttrProp("xsi:schemaLocation", true) == null) {
365: createAttribute("xmlns:xsi", "xmlns:xsi", AttrProp.CDATA
366: | AttrProp.IMPLIED, null,
367: "http://www.w3.org/2001/XMLSchema-instance");
368: setAttributeValue("xmlns:xsi",
369: "http://www.w3.org/2001/XMLSchema-instance");
370: createAttribute("xsi:schemaLocation", "xsi:schemaLocation",
371: AttrProp.CDATA | AttrProp.IMPLIED, null, null);
372: }
373: return getAttributeValue("xsi:schemaLocation");
374: }
375:
376: // Dump the content of this bean returning it as a String
377: public void dump(StringBuffer str, String indent) {
378: String s;
379: Object o;
380: org.netbeans.modules.schema2beans.BaseBean n;
381: str.append(indent);
382: str.append("Title"); // NOI18N
383: str.append(indent + "\t"); // NOI18N
384: str.append("<"); // NOI18N
385: o = this .getTitle();
386: str.append((o == null ? "null" : o.toString().trim())); // NOI18N
387: str.append(">\n"); // NOI18N
388: this .dumpAttributes(TITLE, 0, str, indent);
389:
390: str.append(indent);
391: str.append("Chapter[" + this .sizeChapter() + "]"); // NOI18N
392: for (int i = 0; i < this .sizeChapter(); i++) {
393: str.append(indent + "\t");
394: str.append("#" + i + ":");
395: n = (org.netbeans.modules.schema2beans.BaseBean) this
396: .getChapter(i);
397: if (n != null)
398: n.dump(str, indent + "\t"); // NOI18N
399: else
400: str.append(indent + "\tnull"); // NOI18N
401: this .dumpAttributes(CHAPTER, i, str, indent);
402: }
403:
404: str.append(indent);
405: str.append("Paperback"); // NOI18N
406: str.append(indent + "\t"); // NOI18N
407: str.append((this .isPaperback() ? "true" : "false"));
408: this .dumpAttributes(PAPERBACK, 0, str, indent);
409:
410: str.append(indent);
411: str.append("Price"); // NOI18N
412: str.append(indent + "\t"); // NOI18N
413: str.append("<"); // NOI18N
414: o = this .getPrice();
415: str.append((o == null ? "null" : o.toString().trim())); // NOI18N
416: str.append(">\n"); // NOI18N
417: this .dumpAttributes(PRICE, 0, str, indent);
418:
419: }
420:
421: public String dumpBeanNode() {
422: StringBuffer str = new StringBuffer();
423: str.append("Book\n"); // NOI18N
424: this .dump(str, "\n "); // NOI18N
425: return str.toString();
426: }
427: }
428:
429: // END_NOI18N
430:
431: /*
432: The following schema file has been used for generation:
433:
434: <!ELEMENT book (title, chapter+, paperback?, price?) >
435: <!ELEMENT title (#PCDATA) >
436: <!ELEMENT chapter ( title, summary?, paragraph* ) >
437: <!ELEMENT summary (#PCDATA) >
438: <!ELEMENT paragraph (#PCDATA) >
439: <!ELEMENT paperback EMPTY >
440: <!ELEMENT price (#PCDATA) >
441: <!ATTLIST book instock (yes | no) "yes" >
442: <!ATTLIST title lang CDATA #FIXED "en" >
443: <!ATTLIST chapter length CDATA #IMPLIED >
444:
445: */
|