1 19 20 75 76 package org.netbeans.modules.j2ee.sun.validation.samples.simple.beans; 77 78 import org.w3c.dom.*; 79 import org.netbeans.modules.schema2beans.*; 80 import java.beans.*; 81 import java.util.*; 82 import java.io.*; 83 84 86 public class RootElement extends org.netbeans.modules.schema2beans.BaseBean 87 { 88 89 static Vector comparators = new Vector(); 90 91 static public final String NON_ZERO_LENGTH_PROPERTY = "NonZeroLengthProperty"; static public final String NUMBER_PROPERTY = "NumberProperty"; static public final String BOOLEAN_PROPERTY = "BooleanProperty"; static public final String RANGE_PROPERTY = "RangeProperty"; static public final String ENUMERATION_PROPERTY = "EnumerationProperty"; static public final String OBJECT_ONE = "ObjectOne"; static public final String OBJECT_TWO = "ObjectTwo"; static public final String OBJECT_THREE = "ObjectThree"; static public final String OBJECT_FOUR = "ObjectFour"; static public final String OBJECT_FIVE = "ObjectFive"; static public final String OBJECT_SIX = "ObjectSix"; static public final String OBJECT_SEVEN = "ObjectSeven"; static public final String OBJECT_EIGHT = "ObjectEight"; 105 public RootElement() throws org.netbeans.modules.schema2beans.Schema2BeansException { 106 this(null, Common.USE_DEFAULT_VALUES); 107 } 108 109 public RootElement(org.w3c.dom.Node doc, int options) throws org.netbeans.modules.schema2beans.Schema2BeansException { 110 this(Common.NO_DEFAULT_VALUES); 111 initFromNode(doc, options); 112 } 113 protected void initFromNode(org.w3c.dom.Node doc, int options) throws Schema2BeansException 114 { 115 if (doc == null) 116 { 117 doc = GraphManager.createRootElementNode("root-element"); if (doc == null) 119 throw new Schema2BeansException(Common.getMessage( 120 "CantCreateDOMRoot_msg", "root-element")); 121 } 122 Node n = GraphManager.getElementNode("root-element", doc); if (n == null) 124 throw new Schema2BeansException(Common.getMessage( 125 "DocRootNotInDOMGraph_msg", "root-element", doc.getFirstChild().getNodeName())); 126 127 this.graphManager.setXmlDocument(doc); 128 129 this.createBean(n, this.graphManager()); 131 this.initialize(options); 132 } 133 public RootElement(int options) 134 { 135 super(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 136 initOptions(options); 137 } 138 protected void initOptions(int options) 139 { 140 this.graphManager = new GraphManager(this); 142 this.createRoot("root-element", "RootElement", Common.TYPE_1 | Common.TYPE_BEAN, RootElement.class); 144 145 this.createProperty("non-zero-length-property", NON_ZERO_LENGTH_PROPERTY, 148 Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY, 149 String .class); 150 this.createProperty("number-property", NUMBER_PROPERTY, 152 Common.TYPE_1_N | Common.TYPE_STRING | Common.TYPE_KEY, 153 String .class); 154 this.createProperty("boolean-property", BOOLEAN_PROPERTY, 156 Common.TYPE_0_N | Common.TYPE_STRING | Common.TYPE_KEY, 157 String .class); 158 this.createProperty("range-property", RANGE_PROPERTY, 160 Common.TYPE_0_1 | Common.TYPE_STRING | Common.TYPE_KEY, 161 String .class); 162 this.createProperty("enumeration-property", ENUMERATION_PROPERTY, 164 Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY, 165 String .class); 166 this.createProperty("object-one", OBJECT_ONE, 168 Common.TYPE_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 169 ObjectOne.class); 170 this.createProperty("object-two", OBJECT_TWO, 172 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 173 ObjectTwo.class); 174 this.createProperty("object-three", OBJECT_THREE, 176 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 177 ObjectThree.class); 178 this.createProperty("object-four", OBJECT_FOUR, 180 Common.TYPE_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 181 ObjectFour.class); 182 this.createProperty("object-five", OBJECT_FIVE, 184 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 185 ObjectFive.class); 186 this.createProperty("object-six", OBJECT_SIX, 188 Common.TYPE_1_N | Common.TYPE_BEAN | Common.TYPE_KEY, 189 ObjectSix.class); 190 this.createProperty("object-seven", OBJECT_SEVEN, 192 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 193 ObjectSeven.class); 194 this.createProperty("object-eight", OBJECT_EIGHT, 196 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 197 ObjectEight.class); 198 this.initialize(options); 199 } 200 201 void initialize(int options) 203 { 204 205 } 206 207 public void setNonZeroLengthProperty(String value) { 209 this.setValue(NON_ZERO_LENGTH_PROPERTY, value); 210 } 211 212 public String getNonZeroLengthProperty() { 214 return (String )this.getValue(NON_ZERO_LENGTH_PROPERTY); 215 } 216 217 public void setNumberProperty(int index, String value) { 219 this.setValue(NUMBER_PROPERTY, index, value); 220 } 221 222 public String getNumberProperty(int index) { 224 return (String )this.getValue(NUMBER_PROPERTY, index); 225 } 226 227 public void setNumberProperty(String [] value) { 229 this.setValue(NUMBER_PROPERTY, value); 230 } 231 232 public String [] getNumberProperty() { 234 return (String [])this.getValues(NUMBER_PROPERTY); 235 } 236 237 public int sizeNumberProperty() { 239 return this.size(NUMBER_PROPERTY); 240 } 241 242 public int addNumberProperty(String value) { 244 return this.addValue(NUMBER_PROPERTY, value); 245 } 246 247 public int removeNumberProperty(String value) { 252 return this.removeValue(NUMBER_PROPERTY, value); 253 } 254 255 public void setBooleanProperty(int index, String value) { 257 this.setValue(BOOLEAN_PROPERTY, index, value); 258 } 259 260 public String getBooleanProperty(int index) { 262 return (String )this.getValue(BOOLEAN_PROPERTY, index); 263 } 264 265 public void setBooleanProperty(String [] value) { 267 this.setValue(BOOLEAN_PROPERTY, value); 268 } 269 270 public String [] getBooleanProperty() { 272 return (String [])this.getValues(BOOLEAN_PROPERTY); 273 } 274 275 public int sizeBooleanProperty() { 277 return this.size(BOOLEAN_PROPERTY); 278 } 279 280 public int addBooleanProperty(String value) { 282 return this.addValue(BOOLEAN_PROPERTY, value); 283 } 284 285 public int removeBooleanProperty(String value) { 290 return this.removeValue(BOOLEAN_PROPERTY, value); 291 } 292 293 public void setRangeProperty(String value) { 295 this.setValue(RANGE_PROPERTY, value); 296 } 297 298 public String getRangeProperty() { 300 return (String )this.getValue(RANGE_PROPERTY); 301 } 302 303 public void setEnumerationProperty(String value) { 305 this.setValue(ENUMERATION_PROPERTY, value); 306 } 307 308 public String getEnumerationProperty() { 310 return (String )this.getValue(ENUMERATION_PROPERTY); 311 } 312 313 public void setObjectOne(ObjectOne value) { 315 this.setValue(OBJECT_ONE, value); 316 } 317 318 public ObjectOne getObjectOne() { 320 return (ObjectOne)this.getValue(OBJECT_ONE); 321 } 322 323 public void setObjectTwo(ObjectTwo value) { 325 this.setValue(OBJECT_TWO, value); 326 } 327 328 public ObjectTwo getObjectTwo() { 330 return (ObjectTwo)this.getValue(OBJECT_TWO); 331 } 332 333 public void setObjectThree(ObjectThree value) { 335 this.setValue(OBJECT_THREE, value); 336 } 337 338 public ObjectThree getObjectThree() { 340 return (ObjectThree)this.getValue(OBJECT_THREE); 341 } 342 343 public void setObjectFour(ObjectFour value) { 345 this.setValue(OBJECT_FOUR, value); 346 } 347 348 public ObjectFour getObjectFour() { 350 return (ObjectFour)this.getValue(OBJECT_FOUR); 351 } 352 353 public void setObjectFive(int index, ObjectFive value) { 355 this.setValue(OBJECT_FIVE, index, value); 356 } 357 358 public ObjectFive getObjectFive(int index) { 360 return (ObjectFive)this.getValue(OBJECT_FIVE, index); 361 } 362 363 public void setObjectFive(ObjectFive[] value) { 365 this.setValue(OBJECT_FIVE, value); 366 } 367 368 public ObjectFive[] getObjectFive() { 370 return (ObjectFive[])this.getValues(OBJECT_FIVE); 371 } 372 373 public int sizeObjectFive() { 375 return this.size(OBJECT_FIVE); 376 } 377 378 public int addObjectFive(org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectFive value) { 380 return this.addValue(OBJECT_FIVE, value); 381 } 382 383 public int removeObjectFive(org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectFive value) { 388 return this.removeValue(OBJECT_FIVE, value); 389 } 390 391 public void setObjectSix(int index, ObjectSix value) { 393 this.setValue(OBJECT_SIX, index, value); 394 } 395 396 public ObjectSix getObjectSix(int index) { 398 return (ObjectSix)this.getValue(OBJECT_SIX, index); 399 } 400 401 public void setObjectSix(ObjectSix[] value) { 403 this.setValue(OBJECT_SIX, value); 404 } 405 406 public ObjectSix[] getObjectSix() { 408 return (ObjectSix[])this.getValues(OBJECT_SIX); 409 } 410 411 public int sizeObjectSix() { 413 return this.size(OBJECT_SIX); 414 } 415 416 public int addObjectSix(org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectSix value) { 418 return this.addValue(OBJECT_SIX, value); 419 } 420 421 public int removeObjectSix(org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectSix value) { 426 return this.removeValue(OBJECT_SIX, value); 427 } 428 429 public void setObjectSeven(int index, ObjectSeven value) { 431 this.setValue(OBJECT_SEVEN, index, value); 432 } 433 434 public ObjectSeven getObjectSeven(int index) { 436 return (ObjectSeven)this.getValue(OBJECT_SEVEN, index); 437 } 438 439 public void setObjectSeven(ObjectSeven[] value) { 441 this.setValue(OBJECT_SEVEN, value); 442 } 443 444 public ObjectSeven[] getObjectSeven() { 446 return (ObjectSeven[])this.getValues(OBJECT_SEVEN); 447 } 448 449 public int sizeObjectSeven() { 451 return this.size(OBJECT_SEVEN); 452 } 453 454 public int addObjectSeven(org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectSeven value) { 456 return this.addValue(OBJECT_SEVEN, value); 457 } 458 459 public int removeObjectSeven(org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectSeven value) { 464 return this.removeValue(OBJECT_SEVEN, value); 465 } 466 467 public void setObjectEight(int index, ObjectEight value) { 469 this.setValue(OBJECT_EIGHT, index, value); 470 } 471 472 public ObjectEight getObjectEight(int index) { 474 return (ObjectEight)this.getValue(OBJECT_EIGHT, index); 475 } 476 477 public void setObjectEight(ObjectEight[] value) { 479 this.setValue(OBJECT_EIGHT, value); 480 } 481 482 public ObjectEight[] getObjectEight() { 484 return (ObjectEight[])this.getValues(OBJECT_EIGHT); 485 } 486 487 public int sizeObjectEight() { 489 return this.size(OBJECT_EIGHT); 490 } 491 492 public int addObjectEight(org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectEight value) { 494 return this.addValue(OBJECT_EIGHT, value); 495 } 496 497 public int removeObjectEight(org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectEight value) { 502 return this.removeValue(OBJECT_EIGHT, value); 503 } 504 505 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 507 comparators.add(c); 508 } 509 510 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 512 comparators.remove(c); 513 } 514 public static RootElement createGraph(org.w3c.dom.Node doc) throws org.netbeans.modules.schema2beans.Schema2BeansException { 519 return new RootElement(doc, Common.NO_DEFAULT_VALUES); 520 } 521 522 public static RootElement createGraph(java.io.InputStream in) throws org.netbeans.modules.schema2beans.Schema2BeansException { 523 return createGraph(in, false); 524 } 525 526 public static RootElement createGraph(java.io.InputStream in, boolean validate) throws org.netbeans.modules.schema2beans.Schema2BeansException { 527 Document doc = GraphManager.createXmlDocument(in, validate); 528 return createGraph(doc); 529 } 530 531 public static RootElement createGraph() { 535 try { 536 return new RootElement(); 537 } 538 catch (Schema2BeansException e) { 539 throw new RuntimeException (e.getMessage()); 540 } 541 } 542 543 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 544 boolean restrictionFailure = false; 545 if (getNonZeroLengthProperty() == null) { 547 throw new org.netbeans.modules.schema2beans.ValidateException("getNonZeroLengthProperty() == null", "nonZeroLengthProperty", this); } 549 if (sizeNumberProperty() == 0) { 551 throw new org.netbeans.modules.schema2beans.ValidateException("sizeNumberProperty() == 0", "numberProperty", this); } 553 for (int _index = 0; _index < sizeNumberProperty(); ++_index) { 554 String element = getNumberProperty(_index); 555 if (element != null) { 556 } 557 } 558 for (int _index = 0; _index < sizeBooleanProperty(); ++_index) { 560 String element = getBooleanProperty(_index); 561 if (element != null) { 562 } 563 } 564 if (getRangeProperty() != null) { 566 } 567 if (getEnumerationProperty() == null) { 569 throw new org.netbeans.modules.schema2beans.ValidateException("getEnumerationProperty() == null", "enumerationProperty", this); } 571 if (getObjectOne() == null) { 573 throw new org.netbeans.modules.schema2beans.ValidateException("getObjectOne() == null", "objectOne", this); } 575 getObjectOne().validate(); 576 if (getObjectTwo() != null) { 578 getObjectTwo().validate(); 579 } 580 if (getObjectThree() != null) { 582 getObjectThree().validate(); 583 } 584 if (getObjectFour() == null) { 586 throw new org.netbeans.modules.schema2beans.ValidateException("getObjectFour() == null", "objectFour", this); } 588 getObjectFour().validate(); 589 for (int _index = 0; _index < sizeObjectFive(); ++_index) { 591 org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectFive element = getObjectFive(_index); 592 if (element != null) { 593 element.validate(); 594 } 595 } 596 if (sizeObjectSix() == 0) { 598 throw new org.netbeans.modules.schema2beans.ValidateException("sizeObjectSix() == 0", "objectSix", this); } 600 for (int _index = 0; _index < sizeObjectSix(); ++_index) { 601 org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectSix element = getObjectSix(_index); 602 if (element != null) { 603 element.validate(); 604 } 605 } 606 for (int _index = 0; _index < sizeObjectSeven(); ++_index) { 608 org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectSeven element = getObjectSeven(_index); 609 if (element != null) { 610 element.validate(); 611 } 612 } 613 for (int _index = 0; _index < sizeObjectEight(); ++_index) { 615 org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.ObjectEight element = getObjectEight(_index); 616 if (element != null) { 617 element.validate(); 618 } 619 } 620 } 621 622 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 624 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 625 write(baos); 626 String str = baos.toString();; 627 out.writeUTF(str); 629 } 630 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 632 try{ 633 init(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 634 String strDocument = in.readUTF(); 635 ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes()); 637 Document doc = GraphManager.createXmlDocument(bais, false); 638 initOptions(Common.NO_DEFAULT_VALUES); 639 initFromNode(doc, Common.NO_DEFAULT_VALUES); 640 } 641 catch (Schema2BeansException e) { 642 e.printStackTrace(); 643 throw new RuntimeException (e.getMessage()); 644 } 645 } 646 647 public void dump(StringBuffer str, String indent){ 649 String s; 650 Object o; 651 org.netbeans.modules.schema2beans.BaseBean n; 652 str.append(indent); 653 str.append("NonZeroLengthProperty"); str.append(indent+"\t"); str.append("<"); s = this.getNonZeroLengthProperty(); 657 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(NON_ZERO_LENGTH_PROPERTY, 0, str, indent); 660 661 str.append(indent); 662 str.append("NumberProperty["+this.sizeNumberProperty()+"]"); for(int i=0; i<this.sizeNumberProperty(); i++) 664 { 665 str.append(indent+"\t"); 666 str.append("#"+i+":"); 667 str.append(indent+"\t"); str.append("<"); s = this.getNumberProperty(i); 670 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(NUMBER_PROPERTY, i, str, indent); 673 } 674 675 str.append(indent); 676 str.append("BooleanProperty["+this.sizeBooleanProperty()+"]"); for(int i=0; i<this.sizeBooleanProperty(); i++) 678 { 679 str.append(indent+"\t"); 680 str.append("#"+i+":"); 681 str.append(indent+"\t"); str.append("<"); s = this.getBooleanProperty(i); 684 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(BOOLEAN_PROPERTY, i, str, indent); 687 } 688 689 str.append(indent); 690 str.append("RangeProperty"); str.append(indent+"\t"); str.append("<"); s = this.getRangeProperty(); 694 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(RANGE_PROPERTY, 0, str, indent); 697 698 str.append(indent); 699 str.append("EnumerationProperty"); str.append(indent+"\t"); str.append("<"); s = this.getEnumerationProperty(); 703 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(ENUMERATION_PROPERTY, 0, str, indent); 706 707 str.append(indent); 708 str.append("ObjectOne"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectOne(); 710 if (n != null) 711 n.dump(str, indent + "\t"); else 713 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_ONE, 0, str, indent); 715 716 str.append(indent); 717 str.append("ObjectTwo"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectTwo(); 719 if (n != null) 720 n.dump(str, indent + "\t"); else 722 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_TWO, 0, str, indent); 724 725 str.append(indent); 726 str.append("ObjectThree"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectThree(); 728 if (n != null) 729 n.dump(str, indent + "\t"); else 731 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_THREE, 0, str, indent); 733 734 str.append(indent); 735 str.append("ObjectFour"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectFour(); 737 if (n != null) 738 n.dump(str, indent + "\t"); else 740 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_FOUR, 0, str, indent); 742 743 str.append(indent); 744 str.append("ObjectFive["+this.sizeObjectFive()+"]"); for(int i=0; i<this.sizeObjectFive(); i++) 746 { 747 str.append(indent+"\t"); 748 str.append("#"+i+":"); 749 n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectFive(i); 750 if (n != null) 751 n.dump(str, indent + "\t"); else 753 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_FIVE, i, str, indent); 755 } 756 757 str.append(indent); 758 str.append("ObjectSix["+this.sizeObjectSix()+"]"); for(int i=0; i<this.sizeObjectSix(); i++) 760 { 761 str.append(indent+"\t"); 762 str.append("#"+i+":"); 763 n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectSix(i); 764 if (n != null) 765 n.dump(str, indent + "\t"); else 767 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_SIX, i, str, indent); 769 } 770 771 str.append(indent); 772 str.append("ObjectSeven["+this.sizeObjectSeven()+"]"); for(int i=0; i<this.sizeObjectSeven(); i++) 774 { 775 str.append(indent+"\t"); 776 str.append("#"+i+":"); 777 n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectSeven(i); 778 if (n != null) 779 n.dump(str, indent + "\t"); else 781 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_SEVEN, i, str, indent); 783 } 784 785 str.append(indent); 786 str.append("ObjectEight["+this.sizeObjectEight()+"]"); for(int i=0; i<this.sizeObjectEight(); i++) 788 { 789 str.append(indent+"\t"); 790 str.append("#"+i+":"); 791 n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectEight(i); 792 if (n != null) 793 n.dump(str, indent + "\t"); else 795 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_EIGHT, i, str, indent); 797 } 798 799 } 800 public String dumpBeanNode(){ 801 StringBuffer str = new StringBuffer (); 802 str.append("RootElement\n"); this.dump(str, "\n "); return str.toString(); 805 }} 806 807 809 810 903 | Popular Tags |