1 19 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 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 TITLE = "Title"; static public final String CHAPTER = "Chapter"; static public final String PAPERBACK = "Paperback"; static public final String PRICE = "Price"; 65 public Book() { 66 this(null, Common.USE_DEFAULT_VALUES); 67 } 68 69 public Book(org.w3c.dom.Node doc, int options) { 70 this(Common.NO_DEFAULT_VALUES); 71 try { 72 initFromNode(doc, options); 73 } 74 catch (Schema2BeansException e) { 75 throw new RuntimeException (e); 76 } 77 } 78 protected void initFromNode(org.w3c.dom.Node doc, int options) throws Schema2BeansException 79 { 80 if (doc == null) 81 { 82 doc = GraphManager.createRootElementNode("book"); if (doc == null) 84 throw new Schema2BeansException(Common.getMessage( 85 "CantCreateDOMRoot_msg", "book")); 86 } 87 Node n = GraphManager.getElementNode("book", doc); if (n == null) 89 throw new Schema2BeansException(Common.getMessage( 90 "DocRootNotInDOMGraph_msg", "book", doc.getFirstChild().getNodeName())); 91 92 this.graphManager.setXmlDocument(doc); 93 94 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 this.graphManager = new GraphManager(this); 107 this.createRoot("book", "Book", Common.TYPE_1 | Common.TYPE_BEAN, Book.class); 109 110 initPropertyTables(4); 112 this.createProperty("title", TITLE, 114 Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY, 115 String .class); 116 this.createAttribute(TITLE, "lang", "Lang", 117 AttrProp.CDATA | AttrProp.FIXED, 118 null, "en"); 119 this.createProperty("chapter", 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", PAPERBACK, 128 Common.TYPE_0_1 | Common.TYPE_BOOLEAN | Common.TYPE_KEY, 129 Boolean .class); 130 this.createProperty("price", PRICE, 132 Common.TYPE_0_1 | Common.TYPE_STRING | Common.TYPE_KEY, 133 String .class); 134 this.createAttribute("instock", "Instock", 135 AttrProp.ENUM, 136 new String [] { 137 "yes", 138 "no" 139 }, "yes"); 140 this.initialize(options); 141 } 142 143 void initialize(int options) { 145 146 } 147 148 public void setTitle(String value) { 150 this.setValue(TITLE, value); 151 } 152 153 public String getTitle() { 155 return (String )this.getValue(TITLE); 156 } 157 158 public void setChapter(int index, Chapter value) { 160 this.setValue(CHAPTER, index, value); 161 } 162 163 public Chapter getChapter(int index) { 165 return (Chapter)this.getValue(CHAPTER, index); 166 } 167 168 public int sizeChapter() { 170 return this.size(CHAPTER); 171 } 172 173 public void setChapter(Chapter[] value) { 175 this.setValue(CHAPTER, value); 176 } 177 178 public Chapter[] getChapter() { 180 return (Chapter[])this.getValues(CHAPTER); 181 } 182 183 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 public int removeChapter(org.netbeans.modules.xml.multiview.test.bookmodel.Chapter value) { 194 return this.removeValue(CHAPTER, value); 195 } 196 197 public void setPaperback(boolean value) { 199 this.setValue(PAPERBACK, (value ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE)); 200 } 201 202 public boolean isPaperback() { 204 Boolean ret = (Boolean )this.getValue(PAPERBACK); 205 if (ret == null) 206 ret = (Boolean )Common.defaultScalarValue(Common.TYPE_BOOLEAN); 207 return ((java.lang.Boolean )ret).booleanValue(); 208 } 209 210 public void setPrice(String value) { 212 this.setValue(PRICE, value); 213 } 214 215 public String getPrice() { 217 return (String )this.getValue(PRICE); 218 } 219 220 224 public Chapter newChapter() { 225 return new Chapter(); 226 } 227 228 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 230 comparators.add(c); 231 } 232 233 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 235 comparators.remove(c); 236 } 237 public static Book createGraph(org.w3c.dom.Node doc) { 242 return new Book(doc, Common.NO_DEFAULT_VALUES); 243 } 244 245 public static Book createGraph(java.io.File f) throws java.io.IOException { 246 java.io.InputStream in = new java.io.FileInputStream (f); 247 try { 248 return createGraph(in, false); 249 } finally { 250 in.close(); 251 } 252 } 253 254 public static Book createGraph(java.io.InputStream in) { 255 return createGraph(in, false); 256 } 257 258 public static Book createGraph(java.io.InputStream in, boolean validate) { 259 try { 260 Document doc = GraphManager.createXmlDocument(in, validate); 261 return createGraph(doc); 262 } 263 catch (Exception t) { 264 throw new RuntimeException (Common.getMessage( 265 "DOMGraphCreateFailed_msg", 266 t)); 267 } 268 } 269 270 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 if (getTitle() == null) { 282 throw new org.netbeans.modules.schema2beans.ValidateException("getTitle() == null", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, "title", this); } 284 if (sizeChapter() == 0) { 286 throw new org.netbeans.modules.schema2beans.ValidateException("sizeChapter() == 0", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, "chapter", this); } 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 } 297 298 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 300 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 301 write(baos); 302 String str = baos.toString();; 303 out.writeUTF(str); 305 } 306 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 308 try{ 309 init(comparators, runtimeVersion); 310 String strDocument = in.readUTF(); 311 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 (e); 319 } 320 } 321 322 public void _setSchemaLocation(String 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 _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 public void dump(StringBuffer str, String indent){ 342 String s; 343 Object o; 344 org.netbeans.modules.schema2beans.BaseBean n; 345 str.append(indent); 346 str.append("Title"); str.append(indent+"\t"); str.append("<"); o = this.getTitle(); 350 str.append((o==null?"null":o.toString().trim())); str.append(">\n"); this.dumpAttributes(TITLE, 0, str, indent); 353 354 str.append(indent); 355 str.append("Chapter["+this.sizeChapter()+"]"); 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"); else 364 str.append(indent+"\tnull"); this.dumpAttributes(CHAPTER, i, str, indent); 366 } 367 368 str.append(indent); 369 str.append("Paperback"); str.append(indent+"\t"); str.append((this.isPaperback()?"true":"false")); 372 this.dumpAttributes(PAPERBACK, 0, str, indent); 373 374 str.append(indent); 375 str.append("Price"); str.append(indent+"\t"); str.append("<"); o = this.getPrice(); 379 str.append((o==null?"null":o.toString().trim())); str.append(">\n"); this.dumpAttributes(PRICE, 0, str, indent); 382 383 } 384 public String dumpBeanNode(){ 385 StringBuffer str = new StringBuffer (); 386 str.append("Book\n"); this.dump(str, "\n "); return str.toString(); 389 }} 390 391 393 394 409 | Popular Tags |