1 23 24 80 81 package com.sun.enterprise.tools.common.validation.samples.simple.beans; 82 83 import org.w3c.dom.*; 84 import org.netbeans.modules.schema2beans.*; 85 import java.beans.*; 86 import java.util.*; 87 import java.io.*; 88 89 91 public class RootElement extends org.netbeans.modules.schema2beans.BaseBean 92 { 93 94 static Vector comparators = new Vector(); 95 96 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"; 110 public RootElement() throws org.netbeans.modules.schema2beans.Schema2BeansException { 111 this(null, Common.USE_DEFAULT_VALUES); 112 } 113 114 public RootElement(org.w3c.dom.Node doc, int options) throws org.netbeans.modules.schema2beans.Schema2BeansException { 115 this(Common.NO_DEFAULT_VALUES); 116 initFromNode(doc, options); 117 } 118 protected void initFromNode(org.w3c.dom.Node doc, int options) throws Schema2BeansException 119 { 120 if (doc == null) 121 { 122 doc = GraphManager.createRootElementNode("root-element"); if (doc == null) 124 throw new Schema2BeansException(Common.getMessage( 125 "CantCreateDOMRoot_msg", "root-element")); 126 } 127 Node n = GraphManager.getElementNode("root-element", doc); if (n == null) 129 throw new Schema2BeansException(Common.getMessage( 130 "DocRootNotInDOMGraph_msg", "root-element", doc.getFirstChild().getNodeName())); 131 132 this.graphManager.setXmlDocument(doc); 133 134 this.createBean(n, this.graphManager()); 136 this.initialize(options); 137 } 138 public RootElement(int options) 139 { 140 super(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 141 initOptions(options); 142 } 143 protected void initOptions(int options) 144 { 145 this.graphManager = new GraphManager(this); 147 this.createRoot("root-element", "RootElement", Common.TYPE_1 | Common.TYPE_BEAN, RootElement.class); 149 150 this.createProperty("non-zero-length-property", NON_ZERO_LENGTH_PROPERTY, 153 Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY, 154 String .class); 155 this.createProperty("number-property", NUMBER_PROPERTY, 157 Common.TYPE_1_N | Common.TYPE_STRING | Common.TYPE_KEY, 158 String .class); 159 this.createProperty("boolean-property", BOOLEAN_PROPERTY, 161 Common.TYPE_0_N | Common.TYPE_STRING | Common.TYPE_KEY, 162 String .class); 163 this.createProperty("range-property", RANGE_PROPERTY, 165 Common.TYPE_0_1 | Common.TYPE_STRING | Common.TYPE_KEY, 166 String .class); 167 this.createProperty("enumeration-property", ENUMERATION_PROPERTY, 169 Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY, 170 String .class); 171 this.createProperty("object-one", OBJECT_ONE, 173 Common.TYPE_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 174 ObjectOne.class); 175 this.createProperty("object-two", OBJECT_TWO, 177 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 178 ObjectTwo.class); 179 this.createProperty("object-three", OBJECT_THREE, 181 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 182 ObjectThree.class); 183 this.createProperty("object-four", OBJECT_FOUR, 185 Common.TYPE_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 186 ObjectFour.class); 187 this.createProperty("object-five", OBJECT_FIVE, 189 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 190 ObjectFive.class); 191 this.createProperty("object-six", OBJECT_SIX, 193 Common.TYPE_1_N | Common.TYPE_BEAN | Common.TYPE_KEY, 194 ObjectSix.class); 195 this.createProperty("object-seven", OBJECT_SEVEN, 197 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 198 ObjectSeven.class); 199 this.createProperty("object-eight", OBJECT_EIGHT, 201 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 202 ObjectEight.class); 203 this.initialize(options); 204 } 205 206 void initialize(int options) 208 { 209 210 } 211 212 public void setNonZeroLengthProperty(String value) { 214 this.setValue(NON_ZERO_LENGTH_PROPERTY, value); 215 } 216 217 public String getNonZeroLengthProperty() { 219 return (String )this.getValue(NON_ZERO_LENGTH_PROPERTY); 220 } 221 222 public void setNumberProperty(int index, String value) { 224 this.setValue(NUMBER_PROPERTY, index, value); 225 } 226 227 public String getNumberProperty(int index) { 229 return (String )this.getValue(NUMBER_PROPERTY, index); 230 } 231 232 public void setNumberProperty(String [] value) { 234 this.setValue(NUMBER_PROPERTY, value); 235 } 236 237 public String [] getNumberProperty() { 239 return (String [])this.getValues(NUMBER_PROPERTY); 240 } 241 242 public int sizeNumberProperty() { 244 return this.size(NUMBER_PROPERTY); 245 } 246 247 public int addNumberProperty(String value) { 249 return this.addValue(NUMBER_PROPERTY, value); 250 } 251 252 public int removeNumberProperty(String value) { 257 return this.removeValue(NUMBER_PROPERTY, value); 258 } 259 260 public void setBooleanProperty(int index, String value) { 262 this.setValue(BOOLEAN_PROPERTY, index, value); 263 } 264 265 public String getBooleanProperty(int index) { 267 return (String )this.getValue(BOOLEAN_PROPERTY, index); 268 } 269 270 public void setBooleanProperty(String [] value) { 272 this.setValue(BOOLEAN_PROPERTY, value); 273 } 274 275 public String [] getBooleanProperty() { 277 return (String [])this.getValues(BOOLEAN_PROPERTY); 278 } 279 280 public int sizeBooleanProperty() { 282 return this.size(BOOLEAN_PROPERTY); 283 } 284 285 public int addBooleanProperty(String value) { 287 return this.addValue(BOOLEAN_PROPERTY, value); 288 } 289 290 public int removeBooleanProperty(String value) { 295 return this.removeValue(BOOLEAN_PROPERTY, value); 296 } 297 298 public void setRangeProperty(String value) { 300 this.setValue(RANGE_PROPERTY, value); 301 } 302 303 public String getRangeProperty() { 305 return (String )this.getValue(RANGE_PROPERTY); 306 } 307 308 public void setEnumerationProperty(String value) { 310 this.setValue(ENUMERATION_PROPERTY, value); 311 } 312 313 public String getEnumerationProperty() { 315 return (String )this.getValue(ENUMERATION_PROPERTY); 316 } 317 318 public void setObjectOne(ObjectOne value) { 320 this.setValue(OBJECT_ONE, value); 321 } 322 323 public ObjectOne getObjectOne() { 325 return (ObjectOne)this.getValue(OBJECT_ONE); 326 } 327 328 public void setObjectTwo(ObjectTwo value) { 330 this.setValue(OBJECT_TWO, value); 331 } 332 333 public ObjectTwo getObjectTwo() { 335 return (ObjectTwo)this.getValue(OBJECT_TWO); 336 } 337 338 public void setObjectThree(ObjectThree value) { 340 this.setValue(OBJECT_THREE, value); 341 } 342 343 public ObjectThree getObjectThree() { 345 return (ObjectThree)this.getValue(OBJECT_THREE); 346 } 347 348 public void setObjectFour(ObjectFour value) { 350 this.setValue(OBJECT_FOUR, value); 351 } 352 353 public ObjectFour getObjectFour() { 355 return (ObjectFour)this.getValue(OBJECT_FOUR); 356 } 357 358 public void setObjectFive(int index, ObjectFive value) { 360 this.setValue(OBJECT_FIVE, index, value); 361 } 362 363 public ObjectFive getObjectFive(int index) { 365 return (ObjectFive)this.getValue(OBJECT_FIVE, index); 366 } 367 368 public void setObjectFive(ObjectFive[] value) { 370 this.setValue(OBJECT_FIVE, value); 371 } 372 373 public ObjectFive[] getObjectFive() { 375 return (ObjectFive[])this.getValues(OBJECT_FIVE); 376 } 377 378 public int sizeObjectFive() { 380 return this.size(OBJECT_FIVE); 381 } 382 383 public int addObjectFive(com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectFive value) { 385 return this.addValue(OBJECT_FIVE, value); 386 } 387 388 public int removeObjectFive(com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectFive value) { 393 return this.removeValue(OBJECT_FIVE, value); 394 } 395 396 public void setObjectSix(int index, ObjectSix value) { 398 this.setValue(OBJECT_SIX, index, value); 399 } 400 401 public ObjectSix getObjectSix(int index) { 403 return (ObjectSix)this.getValue(OBJECT_SIX, index); 404 } 405 406 public void setObjectSix(ObjectSix[] value) { 408 this.setValue(OBJECT_SIX, value); 409 } 410 411 public ObjectSix[] getObjectSix() { 413 return (ObjectSix[])this.getValues(OBJECT_SIX); 414 } 415 416 public int sizeObjectSix() { 418 return this.size(OBJECT_SIX); 419 } 420 421 public int addObjectSix(com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectSix value) { 423 return this.addValue(OBJECT_SIX, value); 424 } 425 426 public int removeObjectSix(com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectSix value) { 431 return this.removeValue(OBJECT_SIX, value); 432 } 433 434 public void setObjectSeven(int index, ObjectSeven value) { 436 this.setValue(OBJECT_SEVEN, index, value); 437 } 438 439 public ObjectSeven getObjectSeven(int index) { 441 return (ObjectSeven)this.getValue(OBJECT_SEVEN, index); 442 } 443 444 public void setObjectSeven(ObjectSeven[] value) { 446 this.setValue(OBJECT_SEVEN, value); 447 } 448 449 public ObjectSeven[] getObjectSeven() { 451 return (ObjectSeven[])this.getValues(OBJECT_SEVEN); 452 } 453 454 public int sizeObjectSeven() { 456 return this.size(OBJECT_SEVEN); 457 } 458 459 public int addObjectSeven(com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectSeven value) { 461 return this.addValue(OBJECT_SEVEN, value); 462 } 463 464 public int removeObjectSeven(com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectSeven value) { 469 return this.removeValue(OBJECT_SEVEN, value); 470 } 471 472 public void setObjectEight(int index, ObjectEight value) { 474 this.setValue(OBJECT_EIGHT, index, value); 475 } 476 477 public ObjectEight getObjectEight(int index) { 479 return (ObjectEight)this.getValue(OBJECT_EIGHT, index); 480 } 481 482 public void setObjectEight(ObjectEight[] value) { 484 this.setValue(OBJECT_EIGHT, value); 485 } 486 487 public ObjectEight[] getObjectEight() { 489 return (ObjectEight[])this.getValues(OBJECT_EIGHT); 490 } 491 492 public int sizeObjectEight() { 494 return this.size(OBJECT_EIGHT); 495 } 496 497 public int addObjectEight(com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectEight value) { 499 return this.addValue(OBJECT_EIGHT, value); 500 } 501 502 public int removeObjectEight(com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectEight value) { 507 return this.removeValue(OBJECT_EIGHT, value); 508 } 509 510 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 512 comparators.add(c); 513 } 514 515 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 517 comparators.remove(c); 518 } 519 public static RootElement createGraph(org.w3c.dom.Node doc) throws org.netbeans.modules.schema2beans.Schema2BeansException { 524 return new RootElement(doc, Common.NO_DEFAULT_VALUES); 525 } 526 527 public static RootElement createGraph(java.io.InputStream in) throws org.netbeans.modules.schema2beans.Schema2BeansException { 528 return createGraph(in, false); 529 } 530 531 public static RootElement createGraph(java.io.InputStream in, boolean validate) throws org.netbeans.modules.schema2beans.Schema2BeansException { 532 Document doc = GraphManager.createXmlDocument(in, validate); 533 return createGraph(doc); 534 } 535 536 public static RootElement createGraph() { 540 try { 541 return new RootElement(); 542 } 543 catch (Schema2BeansException e) { 544 throw new RuntimeException (e.getMessage()); 545 } 546 } 547 548 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 549 boolean restrictionFailure = false; 550 if (getNonZeroLengthProperty() == null) { 552 throw new org.netbeans.modules.schema2beans.ValidateException("getNonZeroLengthProperty() == null", "nonZeroLengthProperty", this); } 554 if (sizeNumberProperty() == 0) { 556 throw new org.netbeans.modules.schema2beans.ValidateException("sizeNumberProperty() == 0", "numberProperty", this); } 558 for (int _index = 0; _index < sizeNumberProperty(); ++_index) { 559 String element = getNumberProperty(_index); 560 if (element != null) { 561 } 562 } 563 for (int _index = 0; _index < sizeBooleanProperty(); ++_index) { 565 String element = getBooleanProperty(_index); 566 if (element != null) { 567 } 568 } 569 if (getRangeProperty() != null) { 571 } 572 if (getEnumerationProperty() == null) { 574 throw new org.netbeans.modules.schema2beans.ValidateException("getEnumerationProperty() == null", "enumerationProperty", this); } 576 if (getObjectOne() == null) { 578 throw new org.netbeans.modules.schema2beans.ValidateException("getObjectOne() == null", "objectOne", this); } 580 getObjectOne().validate(); 581 if (getObjectTwo() != null) { 583 getObjectTwo().validate(); 584 } 585 if (getObjectThree() != null) { 587 getObjectThree().validate(); 588 } 589 if (getObjectFour() == null) { 591 throw new org.netbeans.modules.schema2beans.ValidateException("getObjectFour() == null", "objectFour", this); } 593 getObjectFour().validate(); 594 for (int _index = 0; _index < sizeObjectFive(); ++_index) { 596 com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectFive element = getObjectFive(_index); 597 if (element != null) { 598 element.validate(); 599 } 600 } 601 if (sizeObjectSix() == 0) { 603 throw new org.netbeans.modules.schema2beans.ValidateException("sizeObjectSix() == 0", "objectSix", this); } 605 for (int _index = 0; _index < sizeObjectSix(); ++_index) { 606 com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectSix element = getObjectSix(_index); 607 if (element != null) { 608 element.validate(); 609 } 610 } 611 for (int _index = 0; _index < sizeObjectSeven(); ++_index) { 613 com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectSeven element = getObjectSeven(_index); 614 if (element != null) { 615 element.validate(); 616 } 617 } 618 for (int _index = 0; _index < sizeObjectEight(); ++_index) { 620 com.sun.enterprise.tools.common.validation.samples.simple.beans.ObjectEight element = getObjectEight(_index); 621 if (element != null) { 622 element.validate(); 623 } 624 } 625 } 626 627 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 629 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 630 write(baos); 631 String str = baos.toString();; 632 out.writeUTF(str); 634 } 635 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 637 try{ 638 init(comparators, new org.netbeans.modules.schema2beans.Version(1, 2, 0)); 639 String strDocument = in.readUTF(); 640 ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes()); 642 Document doc = GraphManager.createXmlDocument(bais, false); 643 initOptions(Common.NO_DEFAULT_VALUES); 644 initFromNode(doc, Common.NO_DEFAULT_VALUES); 645 } 646 catch (Schema2BeansException e) { 647 e.printStackTrace(); 648 throw new RuntimeException (e.getMessage()); 649 } 650 } 651 652 public void dump(StringBuffer str, String indent){ 654 String s; 655 Object o; 656 org.netbeans.modules.schema2beans.BaseBean n; 657 str.append(indent); 658 str.append("NonZeroLengthProperty"); str.append(indent+"\t"); str.append("<"); s = this.getNonZeroLengthProperty(); 662 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(NON_ZERO_LENGTH_PROPERTY, 0, str, indent); 665 666 str.append(indent); 667 str.append("NumberProperty["+this.sizeNumberProperty()+"]"); for(int i=0; i<this.sizeNumberProperty(); i++) 669 { 670 str.append(indent+"\t"); 671 str.append("#"+i+":"); 672 str.append(indent+"\t"); str.append("<"); s = this.getNumberProperty(i); 675 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(NUMBER_PROPERTY, i, str, indent); 678 } 679 680 str.append(indent); 681 str.append("BooleanProperty["+this.sizeBooleanProperty()+"]"); for(int i=0; i<this.sizeBooleanProperty(); i++) 683 { 684 str.append(indent+"\t"); 685 str.append("#"+i+":"); 686 str.append(indent+"\t"); str.append("<"); s = this.getBooleanProperty(i); 689 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(BOOLEAN_PROPERTY, i, str, indent); 692 } 693 694 str.append(indent); 695 str.append("RangeProperty"); str.append(indent+"\t"); str.append("<"); s = this.getRangeProperty(); 699 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(RANGE_PROPERTY, 0, str, indent); 702 703 str.append(indent); 704 str.append("EnumerationProperty"); str.append(indent+"\t"); str.append("<"); s = this.getEnumerationProperty(); 708 str.append((s==null?"null":s.trim())); str.append(">\n"); this.dumpAttributes(ENUMERATION_PROPERTY, 0, str, indent); 711 712 str.append(indent); 713 str.append("ObjectOne"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectOne(); 715 if (n != null) 716 n.dump(str, indent + "\t"); else 718 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_ONE, 0, str, indent); 720 721 str.append(indent); 722 str.append("ObjectTwo"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectTwo(); 724 if (n != null) 725 n.dump(str, indent + "\t"); else 727 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_TWO, 0, str, indent); 729 730 str.append(indent); 731 str.append("ObjectThree"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectThree(); 733 if (n != null) 734 n.dump(str, indent + "\t"); else 736 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_THREE, 0, str, indent); 738 739 str.append(indent); 740 str.append("ObjectFour"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectFour(); 742 if (n != null) 743 n.dump(str, indent + "\t"); else 745 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_FOUR, 0, str, indent); 747 748 str.append(indent); 749 str.append("ObjectFive["+this.sizeObjectFive()+"]"); for(int i=0; i<this.sizeObjectFive(); i++) 751 { 752 str.append(indent+"\t"); 753 str.append("#"+i+":"); 754 n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectFive(i); 755 if (n != null) 756 n.dump(str, indent + "\t"); else 758 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_FIVE, i, str, indent); 760 } 761 762 str.append(indent); 763 str.append("ObjectSix["+this.sizeObjectSix()+"]"); for(int i=0; i<this.sizeObjectSix(); i++) 765 { 766 str.append(indent+"\t"); 767 str.append("#"+i+":"); 768 n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectSix(i); 769 if (n != null) 770 n.dump(str, indent + "\t"); else 772 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_SIX, i, str, indent); 774 } 775 776 str.append(indent); 777 str.append("ObjectSeven["+this.sizeObjectSeven()+"]"); for(int i=0; i<this.sizeObjectSeven(); i++) 779 { 780 str.append(indent+"\t"); 781 str.append("#"+i+":"); 782 n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectSeven(i); 783 if (n != null) 784 n.dump(str, indent + "\t"); else 786 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_SEVEN, i, str, indent); 788 } 789 790 str.append(indent); 791 str.append("ObjectEight["+this.sizeObjectEight()+"]"); for(int i=0; i<this.sizeObjectEight(); i++) 793 { 794 str.append(indent+"\t"); 795 str.append("#"+i+":"); 796 n = (org.netbeans.modules.schema2beans.BaseBean) this.getObjectEight(i); 797 if (n != null) 798 n.dump(str, indent + "\t"); else 800 str.append(indent+"\tnull"); this.dumpAttributes(OBJECT_EIGHT, i, str, indent); 802 } 803 804 } 805 public String dumpBeanNode(){ 806 StringBuffer str = new StringBuffer (); 807 str.append("RootElement\n"); this.dump(str, "\n "); return str.toString(); 810 }} 811 812 814 815 908 | Popular Tags |