KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > multiview > test > bookmodel > Book


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 Book matches the schema element 'book'.
21  *
22  * Generated on Wed Mar 09 17:37:54 CET 2005
23  *
24  * This class matches the root element of the DTD,
25  * and is the root of the following bean graph:
26  *
27  * book <book> : Book
28  * [attr: instock ENUM ( yes no ) yes]
29  * title <title> : String
30  * [attr: lang CDATA #FIXED en]
31  * chapter <chapter> : Chapter[1,n]
32  * [attr: length CDATA #IMPLIED ]
33  * title <title> : String
34  * [attr: lang CDATA #FIXED en]
35  * summary <summary> : String[0,1]
36  * paragraph <paragraph> : String[0,n]
37  * paperback <paperback> : boolean[0,1]
38  * EMPTY : String
39  * price <price> : String[0,1]
40  *
41  * @Generated
42  */

43
44 package org.netbeans.modules.xml.multiview.test.bookmodel;
45
46 import org.w3c.dom.*;
47 import org.netbeans.modules.schema2beans.*;
48 import java.beans.*;
49 import java.util.*;
50 import java.io.*;
51
52 // BEGIN_NOI18N
53

54 public class Book extends org.netbeans.modules.schema2beans.BaseBean
55 {
56
57     static Vector comparators = new Vector();
58     private static final org.netbeans.modules.schema2beans.Version runtimeVersion = new org.netbeans.modules.schema2beans.Version(4, 0, 0);
59
60     static public final String JavaDoc TITLE = "Title"; // NOI18N
61
static public final String JavaDoc CHAPTER = "Chapter"; // NOI18N
62
static public final String JavaDoc PAPERBACK = "Paperback"; // NOI18N
63
static public final String JavaDoc PRICE = "Price"; // NOI18N
64

65     public Book() {
66         this(null, Common.USE_DEFAULT_VALUES);
67     }
68
69     public Book(org.w3c.dom.Node JavaDoc doc, int options) {
70         this(Common.NO_DEFAULT_VALUES);
71         try {
72             initFromNode(doc, options);
73         }
74         catch (Schema2BeansException e) {
75             throw new RuntimeException JavaDoc(e);
76         }
77     }
78     protected void initFromNode(org.w3c.dom.Node JavaDoc doc, int options) throws Schema2BeansException
79     {
80         if (doc == null)
81         {
82             doc = GraphManager.createRootElementNode("book"); // NOI18N
83
if (doc == null)
84                 throw new Schema2BeansException(Common.getMessage(
85                     "CantCreateDOMRoot_msg", "book"));
86         }
87         Node n = GraphManager.getElementNode("book", doc); // NOI18N
88
if (n == null)
89             throw new Schema2BeansException(Common.getMessage(
90                 "DocRootNotInDOMGraph_msg", "book", doc.getFirstChild().getNodeName()));
91
92         this.graphManager.setXmlDocument(doc);
93
94         // Entry point of the createBeans() recursive calls
95
this.createBean(n, this.graphManager());
96         this.initialize(options);
97     }
98     public Book(int options)
99     {
100         super(comparators, runtimeVersion);
101         initOptions(options);
102     }
103     protected void initOptions(int options)
104     {
105         // The graph manager is allocated in the bean root
106
this.graphManager = new GraphManager(this);
107         this.createRoot("book", "Book", // NOI18N
108
Common.TYPE_1 | Common.TYPE_BEAN, Book.class);
109
110         // Properties (see root bean comments for the bean graph)
111
initPropertyTables(4);
112         this.createProperty("title", // NOI18N
113
TITLE,
114             Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY,
115             String JavaDoc.class);
116         this.createAttribute(TITLE, "lang", "Lang",
117                         AttrProp.CDATA | AttrProp.FIXED,
118                         null, "en");
119         this.createProperty("chapter", // NOI18N
120
CHAPTER,
121             Common.TYPE_1_N | Common.TYPE_BEAN | Common.TYPE_KEY,
122             Chapter.class);
123         this.createAttribute(CHAPTER, "length", "Length",
124                         AttrProp.CDATA | AttrProp.IMPLIED,
125                         null, null);
126         this.createProperty("paperback", // NOI18N
127
PAPERBACK,
128             Common.TYPE_0_1 | Common.TYPE_BOOLEAN | Common.TYPE_KEY,
129             Boolean JavaDoc.class);
130         this.createProperty("price", // NOI18N
131
PRICE,
132             Common.TYPE_0_1 | Common.TYPE_STRING | Common.TYPE_KEY,
133             String JavaDoc.class);
134         this.createAttribute("instock", "Instock",
135                         AttrProp.ENUM,
136                         new String JavaDoc[] {
137                             "yes",
138                             "no"
139                         }, "yes");
140         this.initialize(options);
141     }
142
143     // Setting the default values of the properties
144
void initialize(int options) {
145
146     }
147
148     // This attribute is mandatory
149
public void setTitle(String JavaDoc value) {
150         this.setValue(TITLE, value);
151     }
152
153     //
154
public String JavaDoc getTitle() {
155         return (String JavaDoc)this.getValue(TITLE);
156     }
157
158     // This attribute is an array containing at least one element
159
public void setChapter(int index, Chapter value) {
160         this.setValue(CHAPTER, index, value);
161     }
162
163     //
164
public Chapter getChapter(int index) {
165         return (Chapter)this.getValue(CHAPTER, index);
166     }
167
168     // Return the number of properties
169
public int sizeChapter() {
170         return this.size(CHAPTER);
171     }
172
173     // This attribute is an array containing at least one element
174
public void setChapter(Chapter[] value) {
175         this.setValue(CHAPTER, value);
176     }
177
178     //
179
public Chapter[] getChapter() {
180         return (Chapter[])this.getValues(CHAPTER);
181     }
182
183     // Add a new element returning its index in the list
184
public int addChapter(org.netbeans.modules.xml.multiview.test.bookmodel.Chapter value) {
185         int positionOfNewItem = this.addValue(CHAPTER, value);
186         return positionOfNewItem;
187     }
188
189     //
190
// Remove an element using its reference
191
// Returns the index the element had in the list
192
//
193
public int removeChapter(org.netbeans.modules.xml.multiview.test.bookmodel.Chapter value) {
194         return this.removeValue(CHAPTER, value);
195     }
196
197     // This attribute is optional
198
public void setPaperback(boolean value) {
199         this.setValue(PAPERBACK, (value ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE));
200     }
201
202     //
203
public boolean isPaperback() {
204         Boolean JavaDoc ret = (Boolean JavaDoc)this.getValue(PAPERBACK);
205         if (ret == null)
206             ret = (Boolean JavaDoc)Common.defaultScalarValue(Common.TYPE_BOOLEAN);
207         return ((java.lang.Boolean JavaDoc)ret).booleanValue();
208     }
209
210     // This attribute is optional
211
public void setPrice(String JavaDoc value) {
212         this.setValue(PRICE, value);
213     }
214
215     //
216
public String JavaDoc getPrice() {
217         return (String JavaDoc)this.getValue(PRICE);
218     }
219
220     /**
221      * Create a new bean using it's default constructor.
222      * This does not add it to any bean graph.
223      */

224     public Chapter newChapter() {
225         return new Chapter();
226     }
227
228     //
229
public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) {
230         comparators.add(c);
231     }
232
233     //
234
public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) {
235         comparators.remove(c);
236     }
237     //
238
// This method returns the root of the bean graph
239
// Each call creates a new bean graph from the specified DOM graph
240
//
241
public static Book createGraph(org.w3c.dom.Node JavaDoc doc) {
242         return new Book(doc, Common.NO_DEFAULT_VALUES);
243     }
244
245     public static Book createGraph(java.io.File JavaDoc f) throws java.io.IOException JavaDoc {
246         java.io.InputStream JavaDoc in = new java.io.FileInputStream JavaDoc(f);
247         try {
248             return createGraph(in, false);
249         } finally {
250             in.close();
251         }
252     }
253
254     public static Book createGraph(java.io.InputStream JavaDoc in) {
255         return createGraph(in, false);
256     }
257
258     public static Book createGraph(java.io.InputStream JavaDoc in, boolean validate) {
259         try {
260             Document doc = GraphManager.createXmlDocument(in, validate);
261             return createGraph(doc);
262         }
263         catch (Exception JavaDoc t) {
264             throw new RuntimeException JavaDoc(Common.getMessage(
265                 "DOMGraphCreateFailed_msg",
266                 t));
267         }
268     }
269
270     //
271
// This method returns the root for a new empty bean graph
272
//
273
public static Book createGraph() {
274         return new Book();
275     }
276
277     public void validate() throws org.netbeans.modules.schema2beans.ValidateException {
278         boolean restrictionFailure = false;
279         boolean restrictionPassed = false;
280         // Validating property title
281
if (getTitle() == null) {
282             throw new org.netbeans.modules.schema2beans.ValidateException("getTitle() == null", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, "title", this); // NOI18N
283
}
284         // Validating property chapter
285
if (sizeChapter() == 0) {
286             throw new org.netbeans.modules.schema2beans.ValidateException("sizeChapter() == 0", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, "chapter", this); // NOI18N
287
}
288         for (int _index = 0; _index < sizeChapter(); ++_index) {
289             org.netbeans.modules.xml.multiview.test.bookmodel.Chapter element = getChapter(_index);
290             if (element != null) {
291                 element.validate();
292             }
293         }
294         // Validating property paperback
295
// Validating property price
296
}
297
298     // Special serializer: output XML as serialization
299
private void writeObject(java.io.ObjectOutputStream JavaDoc out) throws java.io.IOException JavaDoc{
300         ByteArrayOutputStream baos = new ByteArrayOutputStream();
301         write(baos);
302         String JavaDoc str = baos.toString();;
303         // System.out.println("str='"+str+"'");
304
out.writeUTF(str);
305     }
306     // Special deserializer: read XML as deserialization
307
private void readObject(java.io.ObjectInputStream JavaDoc in) throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc{
308         try{
309             init(comparators, runtimeVersion);
310             String JavaDoc strDocument = in.readUTF();
311             // System.out.println("strDocument='"+strDocument+"'");
312
ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes());
313             Document doc = GraphManager.createXmlDocument(bais, false);
314             initOptions(Common.NO_DEFAULT_VALUES);
315             initFromNode(doc, Common.NO_DEFAULT_VALUES);
316         }
317         catch (Schema2BeansException e) {
318             throw new RuntimeException JavaDoc(e);
319         }
320     }
321
322     public void _setSchemaLocation(String JavaDoc location) {
323         if (beanProp().getAttrProp("xsi:schemaLocation", true) == null) {
324             createAttribute("xmlns:xsi", "xmlns:xsi", AttrProp.CDATA | AttrProp.IMPLIED, null, "http://www.w3.org/2001/XMLSchema-instance");
325             setAttributeValue("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
326             createAttribute("xsi:schemaLocation", "xsi:schemaLocation", AttrProp.CDATA | AttrProp.IMPLIED, null, location);
327         }
328         setAttributeValue("xsi:schemaLocation", location);
329     }
330
331     public String JavaDoc _getSchemaLocation() {
332         if (beanProp().getAttrProp("xsi:schemaLocation", true) == null) {
333             createAttribute("xmlns:xsi", "xmlns:xsi", AttrProp.CDATA | AttrProp.IMPLIED, null, "http://www.w3.org/2001/XMLSchema-instance");
334             setAttributeValue("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
335             createAttribute("xsi:schemaLocation", "xsi:schemaLocation", AttrProp.CDATA | AttrProp.IMPLIED, null, null);
336         }
337         return getAttributeValue("xsi:schemaLocation");
338     }
339
340     // Dump the content of this bean returning it as a String
341
public void dump(StringBuffer JavaDoc str, String JavaDoc indent){
342         String JavaDoc s;
343         Object JavaDoc o;
344         org.netbeans.modules.schema2beans.BaseBean n;
345         str.append(indent);
346         str.append("Title"); // NOI18N
347
str.append(indent+"\t"); // NOI18N
348
str.append("<"); // NOI18N
349
o = this.getTitle();
350         str.append((o==null?"null":o.toString().trim())); // NOI18N
351
str.append(">\n"); // NOI18N
352
this.dumpAttributes(TITLE, 0, str, indent);
353
354         str.append(indent);
355         str.append("Chapter["+this.sizeChapter()+"]"); // NOI18N
356
for(int i=0; i<this.sizeChapter(); i++)
357         {
358             str.append(indent+"\t");
359             str.append("#"+i+":");
360             n = (org.netbeans.modules.schema2beans.BaseBean) this.getChapter(i);
361             if (n != null)
362                 n.dump(str, indent + "\t"); // NOI18N
363
else
364                 str.append(indent+"\tnull"); // NOI18N
365
this.dumpAttributes(CHAPTER, i, str, indent);
366         }
367
368         str.append(indent);
369         str.append("Paperback"); // NOI18N
370
str.append(indent+"\t"); // NOI18N
371
str.append((this.isPaperback()?"true":"false"));
372         this.dumpAttributes(PAPERBACK, 0, str, indent);
373
374         str.append(indent);
375         str.append("Price"); // NOI18N
376
str.append(indent+"\t"); // NOI18N
377
str.append("<"); // NOI18N
378
o = this.getPrice();
379         str.append((o==null?"null":o.toString().trim())); // NOI18N
380
str.append(">\n"); // NOI18N
381
this.dumpAttributes(PRICE, 0, str, indent);
382
383     }
384     public String JavaDoc dumpBeanNode(){
385         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
386         str.append("Book\n"); // NOI18N
387
this.dump(str, "\n "); // NOI18N
388
return str.toString();
389     }}
390
391 // END_NOI18N
392

393
394 /*
395         The following schema file has been used for generation:
396
397 <!ELEMENT book (title, chapter+, paperback?, price?) >
398 <!ELEMENT title (#PCDATA) >
399 <!ELEMENT chapter ( title, summary?, paragraph* ) >
400 <!ELEMENT summary (#PCDATA) >
401 <!ELEMENT paragraph (#PCDATA) >
402 <!ELEMENT paperback EMPTY >
403 <!ELEMENT price (#PCDATA) >
404 <!ATTLIST book instock (yes | no) "yes" >
405 <!ATTLIST title lang CDATA #FIXED "en" >
406 <!ATTLIST chapter length CDATA #IMPLIED >
407
408 */

409
Popular Tags