1 23 24 28 29 package com.sun.enterprise.config.clientbeans; 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 ClientContainer 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 TARGET_SERVER = "TargetServer"; 51 static public final String AUTH_REALM = "AuthRealm"; 52 static public final String CLIENT_CREDENTIAL = "ClientCredential"; 53 static public final String LOG_SERVICE = "LogService"; 54 static public final String MESSAGE_SECURITY_CONFIG = "MessageSecurityConfig"; 55 static public final String ELEMENT_PROPERTY = "ElementProperty"; 56 57 public ClientContainer() { 58 this(null, Common.USE_DEFAULT_VALUES); 59 } 60 61 public ClientContainer(org.w3c.dom.Node doc, int options) { 62 this(Common.NO_DEFAULT_VALUES); 63 try { 64 initFromNode(doc, options); 65 } 66 catch (Schema2BeansException e) { 67 throw new RuntimeException (e); 68 } 69 } 70 protected void initFromNode(org.w3c.dom.Node doc, int options) throws Schema2BeansException 71 { 72 if (doc == null) 73 { 74 doc = GraphManager.createRootElementNode("client-container"); if (doc == null) 76 throw new Schema2BeansException(Common.getMessage( 77 "CantCreateDOMRoot_msg", "client-container")); 78 } 79 Node n = GraphManager.getElementNode("client-container", doc); if (n == null) 81 throw new Schema2BeansException(Common.getMessage( 82 "DocRootNotInDOMGraph_msg", "client-container", doc.getFirstChild().getNodeName())); 83 84 this.graphManager.setXmlDocument(doc); 85 86 this.createBean(n, this.graphManager()); 88 this.initialize(options); 89 } 90 public ClientContainer(int options) 91 { 92 super(comparators, runtimeVersion); 93 initOptions(options); 94 } 95 protected void initOptions(int options) 96 { 97 this.graphManager = new GraphManager(this); 99 this.createRoot("client-container", "ClientContainer", Common.TYPE_1 | Common.TYPE_BEAN, ClientContainer.class); 101 102 initPropertyTables(6); 104 this.createProperty("target-server", TARGET_SERVER, 105 Common.TYPE_1_N | Common.TYPE_BEAN | Common.TYPE_KEY, 106 TargetServer.class); 107 this.createAttribute(TARGET_SERVER, "name", "Name", 108 AttrProp.CDATA | AttrProp.REQUIRED, 109 null, null); 110 this.createAttribute(TARGET_SERVER, "address", "Address", 111 AttrProp.CDATA | AttrProp.REQUIRED, 112 null, null); 113 this.createAttribute(TARGET_SERVER, "port", "Port", 114 AttrProp.CDATA | AttrProp.REQUIRED, 115 null, null); 116 this.createProperty("auth-realm", AUTH_REALM, 117 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 118 AuthRealm.class); 119 this.createAttribute(AUTH_REALM, "name", "Name", 120 AttrProp.CDATA | AttrProp.REQUIRED, 121 null, null); 122 this.createAttribute(AUTH_REALM, "classname", "Classname", 123 AttrProp.CDATA | AttrProp.REQUIRED, 124 null, null); 125 this.createProperty("client-credential", CLIENT_CREDENTIAL, 126 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 127 ClientCredential.class); 128 this.createAttribute(CLIENT_CREDENTIAL, "user-name", "UserName", 129 AttrProp.CDATA | AttrProp.REQUIRED, 130 null, null); 131 this.createAttribute(CLIENT_CREDENTIAL, "password", "Password", 132 AttrProp.CDATA | AttrProp.REQUIRED, 133 null, null); 134 this.createAttribute(CLIENT_CREDENTIAL, "realm", "Realm", 135 AttrProp.CDATA | AttrProp.IMPLIED, 136 null, null); 137 this.createProperty("log-service", LOG_SERVICE, 138 Common.TYPE_0_1 | Common.TYPE_BEAN | Common.TYPE_KEY, 139 LogService.class); 140 this.createAttribute(LOG_SERVICE, "file", "File", 141 AttrProp.CDATA | AttrProp.IMPLIED, 142 null, null); 143 this.createAttribute(LOG_SERVICE, "level", "Level", 144 AttrProp.CDATA, 145 null, "SEVERE"); 146 this.createProperty("message-security-config", MESSAGE_SECURITY_CONFIG, 147 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 148 MessageSecurityConfig.class); 149 this.createAttribute(MESSAGE_SECURITY_CONFIG, "auth-layer", "AuthLayer", 150 AttrProp.CDATA | AttrProp.REQUIRED, 151 null, null); 152 this.createAttribute(MESSAGE_SECURITY_CONFIG, "default-provider", "DefaultProvider", 153 AttrProp.CDATA | AttrProp.IMPLIED, 154 null, null); 155 this.createAttribute(MESSAGE_SECURITY_CONFIG, "default-client-provider", "DefaultClientProvider", 156 AttrProp.CDATA | AttrProp.IMPLIED, 157 null, null); 158 this.createProperty("property", ELEMENT_PROPERTY, 159 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY, 160 ElementProperty.class); 161 this.createAttribute(ELEMENT_PROPERTY, "name", "Name", 162 AttrProp.CDATA | AttrProp.REQUIRED, 163 null, null); 164 this.createAttribute(ELEMENT_PROPERTY, "value", "Value", 165 AttrProp.CDATA | AttrProp.REQUIRED, 166 null, null); 167 this.createAttribute("send-password", "SendPassword", 168 AttrProp.CDATA, 169 null, "true"); 170 this.initialize(options); 171 } 172 173 void initialize(int options) { 175 176 } 177 178 public void setTargetServer(int index, TargetServer value) { 180 this.setValue(TARGET_SERVER, index, value); 181 } 182 183 public TargetServer getTargetServer(int index) { 185 return (TargetServer)this.getValue(TARGET_SERVER, index); 186 } 187 188 public void setTargetServer(TargetServer[] value) { 190 this.setValue(TARGET_SERVER, value); 191 } 192 193 public TargetServer[] getTargetServer() { 195 return (TargetServer[])this.getValues(TARGET_SERVER); 196 } 197 198 public int sizeTargetServer() { 200 return this.size(TARGET_SERVER); 201 } 202 203 public int addTargetServer(TargetServer value) 205 throws ConfigException{ 206 return addTargetServer(value, true); 207 } 208 209 public int addTargetServer(TargetServer value, boolean overwrite) 211 throws ConfigException{ 212 TargetServer old = getTargetServerByName(value.getName()); 213 if(old != null) { 214 throw new ConfigException(StringManager.getManager(ClientContainer.class).getString("cannotAddDuplicate", "TargetServer")); 215 } 216 return this.addValue(TARGET_SERVER, value, overwrite); 217 } 218 219 public int removeTargetServer(TargetServer value){ 224 return this.removeValue(TARGET_SERVER, value); 225 } 226 227 public int removeTargetServer(TargetServer value, boolean overwrite) 233 throws StaleWriteConfigException{ 234 return this.removeValue(TARGET_SERVER, value, overwrite); 235 } 236 237 public TargetServer getTargetServerByName(String id) { 238 if (null != id) { id = id.trim(); } 239 TargetServer[] o = getTargetServer(); 240 if (o == null) return null; 241 242 for (int i=0; i < o.length; i++) { 243 if(o[i].getAttributeValue(Common.convertName(ClientTags.NAME)).equals(id)) { 244 return o[i]; 245 } 246 } 247 248 return null; 249 250 } 251 public void setAuthRealm(AuthRealm value) { 253 this.setValue(AUTH_REALM, value); 254 } 255 256 public AuthRealm getAuthRealm() { 258 return (AuthRealm)this.getValue(AUTH_REALM); 259 } 260 261 public void setClientCredential(ClientCredential value) { 263 this.setValue(CLIENT_CREDENTIAL, value); 264 } 265 266 public ClientCredential getClientCredential() { 268 return (ClientCredential)this.getValue(CLIENT_CREDENTIAL); 269 } 270 271 public void setLogService(LogService value) { 273 this.setValue(LOG_SERVICE, value); 274 } 275 276 public LogService getLogService() { 278 return (LogService)this.getValue(LOG_SERVICE); 279 } 280 281 public void setMessageSecurityConfig(int index, MessageSecurityConfig value) { 283 this.setValue(MESSAGE_SECURITY_CONFIG, index, value); 284 } 285 286 public MessageSecurityConfig getMessageSecurityConfig(int index) { 288 return (MessageSecurityConfig)this.getValue(MESSAGE_SECURITY_CONFIG, index); 289 } 290 291 public void setMessageSecurityConfig(MessageSecurityConfig[] value) { 293 this.setValue(MESSAGE_SECURITY_CONFIG, value); 294 } 295 296 public MessageSecurityConfig[] getMessageSecurityConfig() { 298 return (MessageSecurityConfig[])this.getValues(MESSAGE_SECURITY_CONFIG); 299 } 300 301 public int sizeMessageSecurityConfig() { 303 return this.size(MESSAGE_SECURITY_CONFIG); 304 } 305 306 public int addMessageSecurityConfig(MessageSecurityConfig value) 308 throws ConfigException{ 309 return addMessageSecurityConfig(value, true); 310 } 311 312 public int addMessageSecurityConfig(MessageSecurityConfig value, boolean overwrite) 314 throws ConfigException{ 315 MessageSecurityConfig old = getMessageSecurityConfigByAuthLayer(value.getAuthLayer()); 316 if(old != null) { 317 throw new ConfigException(StringManager.getManager(ClientContainer.class).getString("cannotAddDuplicate", "MessageSecurityConfig")); 318 } 319 return this.addValue(MESSAGE_SECURITY_CONFIG, value, overwrite); 320 } 321 322 public int removeMessageSecurityConfig(MessageSecurityConfig value){ 327 return this.removeValue(MESSAGE_SECURITY_CONFIG, value); 328 } 329 330 public int removeMessageSecurityConfig(MessageSecurityConfig value, boolean overwrite) 336 throws StaleWriteConfigException{ 337 return this.removeValue(MESSAGE_SECURITY_CONFIG, value, overwrite); 338 } 339 340 public MessageSecurityConfig getMessageSecurityConfigByAuthLayer(String id) { 341 if (null != id) { id = id.trim(); } 342 MessageSecurityConfig[] o = getMessageSecurityConfig(); 343 if (o == null) return null; 344 345 for (int i=0; i < o.length; i++) { 346 if(o[i].getAttributeValue(Common.convertName(ClientTags.AUTH_LAYER)).equals(id)) { 347 return o[i]; 348 } 349 } 350 351 return null; 352 353 } 354 public void setElementProperty(int index, ElementProperty value) { 356 this.setValue(ELEMENT_PROPERTY, index, value); 357 } 358 359 public ElementProperty getElementProperty(int index) { 361 return (ElementProperty)this.getValue(ELEMENT_PROPERTY, index); 362 } 363 364 public void setElementProperty(ElementProperty[] value) { 366 this.setValue(ELEMENT_PROPERTY, value); 367 } 368 369 public ElementProperty[] getElementProperty() { 371 return (ElementProperty[])this.getValues(ELEMENT_PROPERTY); 372 } 373 374 public int sizeElementProperty() { 376 return this.size(ELEMENT_PROPERTY); 377 } 378 379 public int addElementProperty(ElementProperty value) 381 throws ConfigException{ 382 return addElementProperty(value, true); 383 } 384 385 public int addElementProperty(ElementProperty value, boolean overwrite) 387 throws ConfigException{ 388 ElementProperty old = getElementPropertyByName(value.getName()); 389 if(old != null) { 390 throw new ConfigException(StringManager.getManager(ClientContainer.class).getString("cannotAddDuplicate", "ElementProperty")); 391 } 392 return this.addValue(ELEMENT_PROPERTY, value, overwrite); 393 } 394 395 public int removeElementProperty(ElementProperty value){ 400 return this.removeValue(ELEMENT_PROPERTY, value); 401 } 402 403 public int removeElementProperty(ElementProperty value, boolean overwrite) 409 throws StaleWriteConfigException{ 410 return this.removeValue(ELEMENT_PROPERTY, value, overwrite); 411 } 412 413 public ElementProperty getElementPropertyByName(String id) { 414 if (null != id) { id = id.trim(); } 415 ElementProperty[] o = getElementProperty(); 416 if (o == null) return null; 417 418 for (int i=0; i < o.length; i++) { 419 if(o[i].getAttributeValue(Common.convertName(ClientTags.NAME)).equals(id)) { 420 return o[i]; 421 } 422 } 423 424 return null; 425 426 } 427 431 public boolean isSendPassword() { 432 return toBoolean(getAttributeValue(ClientTags.SEND_PASSWORD)); 433 } 434 439 public void setSendPassword(boolean v, boolean overwrite) throws StaleWriteConfigException { 440 setAttributeValue(ClientTags.SEND_PASSWORD, ""+(v==true), overwrite); 441 } 442 446 public void setSendPassword(boolean v) { 447 setAttributeValue(ClientTags.SEND_PASSWORD, ""+(v==true)); 448 } 449 452 public static String getDefaultSendPassword() { 453 return "true".trim(); 454 } 455 459 public TargetServer newTargetServer() { 460 return new TargetServer(); 461 } 462 463 467 public AuthRealm newAuthRealm() { 468 return new AuthRealm(); 469 } 470 471 475 public ClientCredential newClientCredential() { 476 return new ClientCredential(); 477 } 478 479 483 public LogService newLogService() { 484 return new LogService(); 485 } 486 487 491 public MessageSecurityConfig newMessageSecurityConfig() { 492 return new MessageSecurityConfig(); 493 } 494 495 499 public ElementProperty newElementProperty() { 500 return new ElementProperty(); 501 } 502 503 508 protected String getRelativeXPath() { 509 String ret = null; 510 ret = "client-container"; 511 return (null != ret ? ret.trim() : null); 512 } 513 514 517 public static String getDefaultAttributeValue(String attr) { 518 if(attr == null) return null; 519 attr = attr.trim(); 520 if(attr.equals(ClientTags.SEND_PASSWORD)) return "true".trim(); 521 return null; 522 } 523 public static void addComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 525 comparators.add(c); 526 } 527 528 public static void removeComparator(org.netbeans.modules.schema2beans.BeanComparator c) { 530 comparators.remove(c); 531 } 532 public static ClientContainer createGraph(org.w3c.dom.Node doc) { 537 return new ClientContainer(doc, Common.NO_DEFAULT_VALUES); 538 } 539 540 public static ClientContainer createGraph(java.io.File f) throws java.io.IOException { 541 java.io.InputStream in = new java.io.FileInputStream (f); 542 try { 543 return createGraph(in, false); 544 } finally { 545 in.close(); 546 } 547 } 548 549 public static ClientContainer createGraph(java.io.InputStream in) { 550 return createGraph(in, false); 551 } 552 553 public static ClientContainer createGraph(java.io.InputStream in, boolean validate) { 554 try { 555 Document doc = GraphManager.createXmlDocument(in, validate); 556 return createGraph(doc); 557 } 558 catch (Exception t) { 559 throw new RuntimeException (Common.getMessage( 560 "DOMGraphCreateFailed_msg", 561 t)); 562 } 563 } 564 565 public static ClientContainer createGraph() { 569 return new ClientContainer(); 570 } 571 572 public void validate() throws org.netbeans.modules.schema2beans.ValidateException { 573 } 574 575 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 577 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 578 write(baos); 579 String str = baos.toString();; 580 out.writeUTF(str); 582 } 583 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 585 try{ 586 init(comparators, runtimeVersion); 587 String strDocument = in.readUTF(); 588 ByteArrayInputStream bais = new ByteArrayInputStream(strDocument.getBytes()); 590 Document doc = GraphManager.createXmlDocument(bais, false); 591 initOptions(Common.NO_DEFAULT_VALUES); 592 initFromNode(doc, Common.NO_DEFAULT_VALUES); 593 } 594 catch (Schema2BeansException e) { 595 throw new RuntimeException (e); 596 } 597 } 598 599 public void _setSchemaLocation(String location) { 600 if (beanProp().getAttrProp("xsi:schemaLocation", true) == null) { 601 createAttribute("xmlns:xsi", "xmlns:xsi", AttrProp.CDATA | AttrProp.IMPLIED, null, "http://www.w3.org/2001/XMLSchema-instance"); 602 setAttributeValue("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); 603 createAttribute("xsi:schemaLocation", "xsi:schemaLocation", AttrProp.CDATA | AttrProp.IMPLIED, null, location); 604 } 605 setAttributeValue("xsi:schemaLocation", location); 606 } 607 608 public String _getSchemaLocation() { 609 if (beanProp().getAttrProp("xsi:schemaLocation", true) == null) { 610 createAttribute("xmlns:xsi", "xmlns:xsi", AttrProp.CDATA | AttrProp.IMPLIED, null, "http://www.w3.org/2001/XMLSchema-instance"); 611 setAttributeValue("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); 612 createAttribute("xsi:schemaLocation", "xsi:schemaLocation", AttrProp.CDATA | AttrProp.IMPLIED, null, null); 613 } 614 return getAttributeValue("xsi:schemaLocation"); 615 } 616 617 public void dump(StringBuffer str, String indent){ 619 String s; 620 Object o; 621 org.netbeans.modules.schema2beans.BaseBean n; 622 str.append(indent); 623 str.append("TargetServer["+this.sizeTargetServer()+"]"); for(int i=0; i<this.sizeTargetServer(); i++) 625 { 626 str.append(indent+"\t"); 627 str.append("#"+i+":"); 628 n = (org.netbeans.modules.schema2beans.BaseBean) this.getTargetServer(i); 629 if (n != null) 630 n.dump(str, indent + "\t"); else 632 str.append(indent+"\tnull"); this.dumpAttributes(TARGET_SERVER, i, str, indent); 634 } 635 636 str.append(indent); 637 str.append("AuthRealm"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getAuthRealm(); 639 if (n != null) 640 n.dump(str, indent + "\t"); else 642 str.append(indent+"\tnull"); this.dumpAttributes(AUTH_REALM, 0, str, indent); 644 645 str.append(indent); 646 str.append("ClientCredential"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getClientCredential(); 648 if (n != null) 649 n.dump(str, indent + "\t"); else 651 str.append(indent+"\tnull"); this.dumpAttributes(CLIENT_CREDENTIAL, 0, str, indent); 653 654 str.append(indent); 655 str.append("LogService"); n = (org.netbeans.modules.schema2beans.BaseBean) this.getLogService(); 657 if (n != null) 658 n.dump(str, indent + "\t"); else 660 str.append(indent+"\tnull"); this.dumpAttributes(LOG_SERVICE, 0, str, indent); 662 663 str.append(indent); 664 str.append("MessageSecurityConfig["+this.sizeMessageSecurityConfig()+"]"); for(int i=0; i<this.sizeMessageSecurityConfig(); i++) 666 { 667 str.append(indent+"\t"); 668 str.append("#"+i+":"); 669 n = (org.netbeans.modules.schema2beans.BaseBean) this.getMessageSecurityConfig(i); 670 if (n != null) 671 n.dump(str, indent + "\t"); else 673 str.append(indent+"\tnull"); this.dumpAttributes(MESSAGE_SECURITY_CONFIG, i, str, indent); 675 } 676 677 str.append(indent); 678 str.append("ElementProperty["+this.sizeElementProperty()+"]"); for(int i=0; i<this.sizeElementProperty(); i++) 680 { 681 str.append(indent+"\t"); 682 str.append("#"+i+":"); 683 n = (org.netbeans.modules.schema2beans.BaseBean) this.getElementProperty(i); 684 if (n != null) 685 n.dump(str, indent + "\t"); else 687 str.append(indent+"\tnull"); this.dumpAttributes(ELEMENT_PROPERTY, i, str, indent); 689 } 690 691 } 692 public String dumpBeanNode(){ 693 StringBuffer str = new StringBuffer (); 694 str.append("ClientContainer\n"); this.dump(str, "\n "); return str.toString(); 697 }} 698 699 701 | Popular Tags |