1 23 24 28 29 package com.sun.enterprise.config.serverbeans; 30 31 import org.w3c.dom.*; 32 import org.netbeans.modules.schema2beans.*; 33 import java.beans.*; 34 import java.util.*; 35 import java.io.*; 36 import java.io.Serializable ; 37 import com.sun.enterprise.config.ConfigBean; 38 import com.sun.enterprise.config.ConfigException; 39 import com.sun.enterprise.config.StaleWriteConfigException; 40 import com.sun.enterprise.util.i18n.StringManager; 41 42 44 public class Domain extends ConfigBean implements Serializable 45 { 46 47 static Vector comparators = new Vector(); 48 private static final org.netbeans.modules.schema2beans.Version runtimeVersion = new org.netbeans.modules.schema2beans.Version(4, 2, 0); 49 50 static public final String APPLICATIONS = "Applications"; 51 static public final String RESOURCES = "Resources"; 52 static public final String CONFIGS = "Configs"; 53 static public final String SERVERS = "Servers"; 54 static public final String CLUSTERS = "Clusters"; 55 static public final String NODE_AGENTS = "NodeAgents"; 56 static public final String LB_CONFIGS = "LbConfigs"; 57 static public final String LOAD_BALANCERS = "LoadBalancers"; 58 static public final String SYSTEM_PROPERTY = "SystemProperty"; 59 static public final String ELEMENT_PROPERTY = "ElementProperty"; 60 61 public Domain() { 62 this(null, Common.USE_DEFAULT_VALUES); 63 } 64 65 public Domain(org.w3c.dom.Node doc, int options) { 66 this(Common.NO_DEFAULT_VALUES); 67 try { 68 initFromNode(doc, options); 69 } 70 catch (Schema2BeansException e) { 71 throw new RuntimeException (e); 72 } 73 } 74 protected void initFromNode(org.w3c.dom.Node doc, int options) throws Schema2BeansException 75 { 76 if (doc == null) 77 { 78 doc = GraphManager.createRootElementNode("domain"); if (doc == null) 80 throw new Schema2BeansException(Common.getMessage( 81 "CantCreateDOMRoot_msg", "domain")); 82 } 83 Node n = GraphManager.getElementNode("domain", doc); if (n == null) 85 throw new Schema2BeansException(Common.getMessage( 86 "DocRootNotInDOMGraph_msg", "domain", doc.getFirstChild().getNodeName())); 87 88 this.graphManager.setXmlDocument(doc); 89 90 this.createBean(n, this.graphManager()); 92 this.initialize(options); 93 } 94 public Domain(int options) 95 { 96 super(comparators, runtimeVersion); 97 initOptions(options); 98 } 99 protected void initOptions(int options) 100 { 101 this.graphManager = new GraphManager(this); 103 this.createRoot("domain", "Domain", Common.TYPE_1 | Common.TYPE_BEAN, Domain.class); 105 106 initPropertyTables(10); 108 this.createProperty("applications", APPLICATIONS, 109 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 110 Applications.class); 111 this.createProperty("resources", RESOURCES, 112 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 113 Resources.class); 114 this.createProperty("configs", CONFIGS, 115 Common.TYPE_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 116 Configs.class); 117 this.createProperty("servers", SERVERS, 118 Common.TYPE_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 119 Servers.class); 120 this.createProperty("clusters", CLUSTERS, 121 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 122 Clusters.class); 123 this.createProperty("node-agents", NODE_AGENTS, 124 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 125 NodeAgents.class); 126 this.createProperty("lb-configs", LB_CONFIGS, 127 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 128 LbConfigs.class); 129 this.createProperty("load-balancers", LOAD_BALANCERS, 130 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 131 LoadBalancers.class); 132 this.createProperty("system-property", SYSTEM_PROPERTY, 133 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 134 SystemProperty.class); 135 this.createAttribute(SYSTEM_PROPERTY, "name", "Name", 136 AttrProp.CDATA | AttrProp.REQUIRED, 137 null, null); 138 this.createAttribute(SYSTEM_PROPERTY, "value", "Value", 139 AttrProp.CDATA | AttrProp.REQUIRED, 140 null, null); 141 this.createProperty("property", ELEMENT_PROPERTY, 142 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 143 ElementProperty.class); 144 this.createAttribute(ELEMENT_PROPERTY, "name", "Name", 145 AttrProp.CDATA | AttrProp.REQUIRED, 146 null, null); 147 this.createAttribute(ELEMENT_PROPERTY, "value", "Value", 148 AttrProp.CDATA | AttrProp.REQUIRED, 149 null, null); 150 this.createAttribute("application-root", "ApplicationRoot", 151 AttrProp.CDATA | AttrProp.IMPLIED, 152 null, null); 153 this.createAttribute("log-root", "LogRoot", 154 AttrProp.CDATA | AttrProp.IMPLIED, 155 null, null); 156 this.createAttribute("locale", "Locale", 157 AttrProp.CDATA | AttrProp.IMPLIED, 158 null, null); 159 this.initialize(options); 160 } 161 162 void initialize(int options) { 164 165 } 166 167 public void setApplications(Applications value) { 169 this.setValue(APPLICATIONS, value); 170 } 171 172 public Applications getApplications() { 174 return (Applications)this.getValue(APPLICATIONS); 175 } 176 177 public void setResources(Resources value) { 179 this.setValue(RESOURCES, value); 180 } 181 182 public Resources getResources() { 184 return (Resources)this.getValue(RESOURCES); 185 } 186 187 public void setConfigs(Configs value) { 189 this.setValue(CONFIGS, value); 190 } 191 192 public Configs getConfigs() { 194 return (Configs)this.getValue(CONFIGS); 195 } 196 197 public void setServers(Servers value) { 199 this.setValue(SERVERS, value); 200 } 201 202 public Servers getServers() { 204 return (Servers)this.getValue(SERVERS); 205 } 206 207 public void setClusters(Clusters value) { 209 this.setValue(CLUSTERS, value); 210 } 211 212 public Clusters getClusters() { 214 return (Clusters)this.getValue(CLUSTERS); 215 } 216 217 public void setNodeAgents(NodeAgents value) { 219 this.setValue(NODE_AGENTS, value); 220 } 221 222 public NodeAgents getNodeAgents() { 224 return (NodeAgents)this.getValue(NODE_AGENTS); 225 } 226 227 public void setLbConfigs(LbConfigs value) { 229 this.setValue(LB_CONFIGS, value); 230 } 231 232 public LbConfigs getLbConfigs() { 234 return (LbConfigs)this.getValue(LB_CONFIGS); 235 } 236 237 public void setLoadBalancers(LoadBalancers value) { 239 this.setValue(LOAD_BALANCERS, value); 240 } 241 242 public LoadBalancers getLoadBalancers() { 244 return (LoadBalancers)this.getValue(LOAD_BALANCERS); 245 } 246 247 public void setSystemProperty(int index, SystemProperty value) { 249 this.setValue(SYSTEM_PROPERTY, index, value); 250 } 251 252 public SystemProperty getSystemProperty(int index) { 254 return (SystemProperty)this.getValue(SYSTEM_PROPERTY, index); 255 } 256 257 public void setSystemProperty(SystemProperty[] value) { 259 this.setValue(SYSTEM_PROPERTY, value); 260 } 261 262 public SystemProperty[] getSystemProperty() { 264 return (SystemProperty[])this.getValues(SYSTEM_PROPERTY); 265 } 266 267 public int sizeSystemProperty() { 269 return this.size(SYSTEM_PROPERTY); 270 } 271 272 public int addSystemProperty(SystemProperty value) 274 throws ConfigException{ 275 return addSystemProperty(value, true); 276 } 277 278 public int addSystemProperty(SystemProperty value, boolean overwrite) 280 throws ConfigException{ 281 SystemProperty old = getSystemPropertyByName(value.getName()); 282 if(old != null) { 283 throw new ConfigException(StringManager.getManager(Domain.class).getString("cannotAddDuplicate", "SystemProperty")); 284 } 285 return this.addValue(SYSTEM_PROPERTY, value, overwrite); 286 } 287 288 public int removeSystemProperty(SystemProperty value){ 293 return this.removeValue(SYSTEM_PROPERTY, value); 294 } 295 296 public int removeSystemProperty(SystemProperty value, boolean overwrite) 302 throws StaleWriteConfigException{ 303 return this.removeValue(SYSTEM_PROPERTY, value, overwrite); 304 } 305 306 public SystemProperty getSystemPropertyByName(String id) { 307 if (null != id) { id = id.trim(); } 308 SystemProperty[] o = getSystemProperty(); 309 if (o == null) return null; 310 311 for (int i=0; i < o.length; i++) { 312 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 313 return o[i]; 314 } 315 } 316 317 return null; 318 319 } 320 public void setElementProperty(int index, ElementProperty value) { 322 this.setValue(ELEMENT_PROPERTY, index, value); 323 } 324 325 public ElementProperty getElementProperty(int index) { 327 return (ElementProperty)this.getValue(ELEMENT_PROPERTY, index); 328 } 329 330 public void setElementProperty(ElementProperty[] value) { 332 this.setValue(ELEMENT_PROPERTY, value); 333 } 334 335 public ElementProperty[] getElementProperty() { 337 return (ElementProperty[])this.getValues(ELEMENT_PROPERTY); 338 } 339 340 public int sizeElementProperty() { 342 return this.size(ELEMENT_PROPERTY); 343 } 344 345 public int addElementProperty(ElementProperty value) 347 throws ConfigException{ 348 return addElementProperty(value, true); 349 } 350 351 public int addElementProperty(ElementProperty value, boolean overwrite) 353 throws ConfigException{ 354 ElementProperty old = getElementPropertyByName(value.getName()); 355 if(old != null) { 356 throw new ConfigException(StringManager.getManager(Domain.class).getString("cannotAddDuplicate", "ElementProperty")); 357 } 358 return this.addValue(ELEMENT_PROPERTY, value, overwrite); 359 } 360 361 public int removeElementProperty(ElementProperty value){ 366 return this.removeValue(ELEMENT_PROPERTY, value); 367 } 368 369 public int removeElementProperty(ElementProperty value, boolean overwrite) 375 throws StaleWriteConfigException{ 376 return this.removeValue(ELEMENT_PROPERTY, value, overwrite); 377 } 378 379 public ElementProperty getElementPropertyByName(String id) { 380 if (null != id) { id = id.trim(); } 381 ElementProperty[] o = getElementProperty(); 382 if (o == null) return null; 383 384 for (int i=0; i < o.length; i++) { 385 if(o[i].getAttributeValue(Common.convertName(ServerTags.NAME)).equals(id)) { 386 return o[i]; 387 } 388 } 389 390 return null; 391 392 } 393 397 public String getApplicationRoot() { 398 return getAttributeValue(ServerTags.APPLICATION_ROOT); 399 } 400 405 public void setApplicationRoot(String v, boolean overwrite) throws StaleWriteConfigException { 406 setAttributeValue(ServerTags.APPLICATION_ROOT, v, overwrite); 407 } 408 412 public void setApplicationRoot(String v) { 413 setAttributeValue(ServerTags.APPLICATION_ROOT, v); 414 } 415 419 public String getLogRoot() { 420 return getAttributeValue(ServerTags.LOG_ROOT); 421 } 422 427 public void setLogRoot(String v, boolean overwrite) throws StaleWriteConfigException { 428 setAttributeValue(ServerTags.LOG_ROOT, v, overwrite); 429 } 430 434 public void setLogRoot(String v) { 435 setAttributeValue(ServerTags.LOG_ROOT, v); 436 } 437 441 public String getLocale() { 442 return getAttributeValue(ServerTags.LOCALE); 443 } 444 449 public void setLocale(String v, boolean overwrite) throws StaleWriteConfigException { 450 setAttributeValue(ServerTags.LOCALE, v, overwrite); 451 } 452 456 public void setLocale(String v) { 457 setAttributeValue(ServerTags.LOCALE, v); 458 } 459 463 public Applications newApplications() { 464 return new Applications(); 465 } 466 467 471 public Resources newResources() { 472 return new Resources(); 473 } 474 475 479 public Configs newConfigs() { 480 return new Configs(); 481 } 482 483 487 public Servers newServers() { 488 return new Servers(); 489 } 490 491 495 public Clusters newClusters() { 496 return new Clusters(); 497 } 498 499 503 public NodeAgents newNodeAgents() { 504 return new NodeAgents(); 505 } 506 507 511 public LbConfigs newLbConfigs() { 512 return new LbConfigs(); 513 } 514 515 519 public LoadBalancers newLoadBalancers() { 520 return new LoadBalancers(); 521 } 522 523 527 public SystemProperty newSystemProperty() { 528 return new SystemProperty(); 529 } 530 531 535 public ElementProperty newElementProperty() { 536 return new ElementProperty(); 537 } 538 539 544 protected String getRelativeXPath() { 545 String ret = null; 546 ret = "domain"; 547 return (null != ret ? ret.trim() : null); 548 } 549 550 553 public static String getDefaultAttributeValue(String attr) { 554 if(attr == null) return null; 555 attr = attr.trim(); 556 return null; 557 } 558 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 560 comparators.add(c); 561 } 562 563 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 565 comparators.remove(c); 566 } 567 public static Domain createGraph(org.w3c.dom.Node doc) { 572 return new Domain(doc, Common.NO_DEFAULT_VALUES); 573 } 574 575 public static Domain createGraph(java.io.File f) throws java.io.IOException { 576 java.io.InputStream in = new java.io.FileInputStream (f); 577 try { 578 return createGraph(in, false); 579 } finally { 580 in.close(); 581 } 582 } 583 584 public static Domain createGraph(java.io.InputStream in) { 585 return createGraph(in, false); 586 } 587 588 public static Domain createGraph(java.io.InputStream in, boolean validate) { 589 try { 590 Document doc = GraphManager.createXmlDocument(in, validate); 591 return createGraph(doc); 592 } 593 catch (Exception t) { 594 throw new RuntimeException (Common.getMessage( 595 "DOMGraphCreateFailed_msg", 596 t)); 597 } 598 } 599 600 public static Domain createGraph() { 604 return new Domain(); 605 } 606 607 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 608 } 609 610 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 612 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 613 write(baos); 614 String str = baos.toString();; 615 out.writeUTF(str); 617 } 618 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 620 try{ 621 init(comparators, runtimeVersion); 622 String strDocument = in.readUTF(); 623 ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes()); 625 Document doc = GraphManager.createXmlDocument(bais, false); 626 initOptions(Common.NO_DEFAULT_VALUES); 627 initFromNode(doc, Common.NO_DEFAULT_VALUES); 628 } 629 catch (Schema2BeansException e) { 630 throw new RuntimeException (e); 631 } 632 } 633 634 public void _setSchemaLocation(String location) { 635 if (beanProp().getAttrProp("xsi:schemaLocation", true) == null) { 636 createAttribute("xmlns:xsi", "xmlns:xsi", AttrProp.CDATA | AttrProp.IMPLIED, null, "http://www.w3.org/2001/XMLSchema-instance"); 637 setAttributeValue("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); 638 createAttribute("xsi:schemaLocation", "xsi:schemaLocation", AttrProp.CDATA | AttrProp.IMPLIED, null, location); 639 } 640 setAttributeValue("xsi:schemaLocation", location); 641 } 642 643 public String _getSchemaLocation() { 644 if (beanProp().getAttrProp("xsi:schemaLocation", true) == null) { 645 createAttribute("xmlns:xsi", "xmlns:xsi", AttrProp.CDATA | AttrProp.IMPLIED, null, "http://www.w3.org/2001/XMLSchema-instance"); 646 setAttributeValue("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); 647 createAttribute("xsi:schemaLocation", "xsi:schemaLocation", AttrProp.CDATA | AttrProp.IMPLIED, null, null); 648 } 649 return getAttributeValue("xsi:schemaLocation"); 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("Applications"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getApplications(); 660 if (n != null) 661 n.dump(str, indent + "\t"); else 663 str.append(indent+"\tnull"); this.dumpAttributes(APPLICATIONS, 0, str, indent); 665 666 str.append(indent); 667 str.append("Resources"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getResources(); 669 if (n != null) 670 n.dump(str, indent + "\t"); else 672 str.append(indent+"\tnull"); this.dumpAttributes(RESOURCES, 0, str, indent); 674 675 str.append(indent); 676 str.append("Configs"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getConfigs(); 678 if (n != null) 679 n.dump(str, indent + "\t"); else 681 str.append(indent+"\tnull"); this.dumpAttributes(CONFIGS, 0, str, indent); 683 684 str.append(indent); 685 str.append("Servers"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getServers(); 687 if (n != null) 688 n.dump(str, indent + "\t"); else 690 str.append(indent+"\tnull"); this.dumpAttributes(SERVERS, 0, str, indent); 692 693 str.append(indent); 694 str.append("Clusters"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getClusters(); 696 if (n != null) 697 n.dump(str, indent + "\t"); else 699 str.append(indent+"\tnull"); this.dumpAttributes(CLUSTERS, 0, str, indent); 701 702 str.append(indent); 703 str.append("NodeAgents"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getNodeAgents(); 705 if (n != null) 706 n.dump(str, indent + "\t"); else 708 str.append(indent+"\tnull"); this.dumpAttributes(NODE_AGENTS, 0, str, indent); 710 711 str.append(indent); 712 str.append("LbConfigs"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getLbConfigs(); 714 if (n != null) 715 n.dump(str, indent + "\t"); else 717 str.append(indent+"\tnull"); this.dumpAttributes(LB_CONFIGS, 0, str, indent); 719 720 str.append(indent); 721 str.append("LoadBalancers"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getLoadBalancers(); 723 if (n != null) 724 n.dump(str, indent + "\t"); else 726 str.append(indent+"\tnull"); this.dumpAttributes(LOAD_BALANCERS, 0, str, indent); 728 729 str.append(indent); 730 str.append("SystemProperty["+this.sizeSystemProperty()+"]"); for(int i=0; i<this.sizeSystemProperty(); i++) 732 { 733 str.append(indent+"\t"); 734 str.append("#"+i+":"); 735 n = (org.netbeans.modules.schema2beans.BaseBean) this.getSystemProperty(i); 736 if (n != null) 737 n.dump(str, indent + "\t"); else 739 str.append(indent+"\tnull"); this.dumpAttributes(SYSTEM_PROPERTY, i, str, indent); 741 } 742 743 str.append(indent); 744 str.append("ElementProperty["+this.sizeElementProperty()+"]"); for(int i=0; i<this.sizeElementProperty(); i++) 746 { 747 str.append(indent+"\t"); 748 str.append("#"+i+":"); 749 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElementProperty(i); 750 if (n != null) 751 n.dump(str, indent + "\t"); else 753 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT_PROPERTY, i, str, indent); 755 } 756 757 } 758 public String dumpBeanNode(){ 759 StringBuffer str = new StringBuffer (); 760 str.append("Domain\n"); this.dump(str, "\n "); return str.toString(); 763 }} 764 765 767 | Popular Tags |