1 23 24 package com.sun.enterprise.resource; 25 26 import javax.xml.parsers.DocumentBuilder ; 27 import javax.xml.parsers.DocumentBuilderFactory ; 28 import javax.xml.parsers.ParserConfigurationException ; 29 30 import org.xml.sax.SAXException ; 31 import org.xml.sax.SAXParseException ; 32 import org.xml.sax.InputSource ; 33 import org.xml.sax.ErrorHandler ; 34 import org.xml.sax.EntityResolver ; 35 36 import java.io.File ; 37 import java.io.IOException ; 38 import java.util.ArrayList ; 39 import java.util.List ; 40 import java.util.Vector ; 41 import java.util.Iterator ; 42 import java.util.logging.Level ; 43 import java.util.logging.Logger ; 44 import java.util.StringTokenizer ; 45 46 import org.w3c.dom.Document ; 47 import org.w3c.dom.DOMException ; 48 import org.w3c.dom.Node ; 49 import org.w3c.dom.NodeList ; 50 import org.w3c.dom.NamedNodeMap ; 51 52 import com.sun.enterprise.util.SystemPropertyConstants; 53 import com.sun.enterprise.admin.common.constant.AdminConstants; 54 55 import javax.management.Attribute ; 56 import javax.management.AttributeList ; 57 58 import com.sun.enterprise.util.i18n.StringManager; 60 61 import static com.sun.enterprise.resource.ResourceConstants.*; 62 63 67 public class ResourcesXMLParser implements EntityResolver 68 { 69 70 private File resourceFile = null; 71 private Document document; 72 private List <Resource> vResources; 73 76 78 80 82 private static StringManager localStrings = 84 StringManager.getManager( ResourcesXMLParser.class ); 85 86 private static final int NONCONNECTOR = 2; 87 private static final int CONNECTOR = 1; 88 89 90 public ResourcesXMLParser(String resourceFileName) throws Exception 91 { 92 resourceFile = new File (resourceFileName); 93 initProperties(); 94 vResources = new ArrayList <Resource>(); 95 generateResourceObjects(); 96 } 97 98 101 public void initProperties() throws Exception 102 { 103 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 104 try { 105 AddResourcesErrorHandler errorHandler = new AddResourcesErrorHandler(); 106 factory.setValidating(true); 107 DocumentBuilder builder = factory.newDocumentBuilder(); 108 builder.setEntityResolver((EntityResolver )this); 109 builder.setErrorHandler(errorHandler); 110 if (resourceFile == null) { 111 String msg = localStrings.getString( "admin.server.core.mbean.config.no_resource_file" ); 112 throw new Exception ( msg ); 113 } 114 InputSource is = new InputSource (resourceFile.toString()); 115 document = builder.parse(is); 116 }catch (SAXException sxe) { 119 Exception x = sxe; 120 if (sxe.getException() != null) 121 x = sxe.getException(); 122 throw new Exception (x.getLocalizedMessage()); 123 } 124 catch (ParserConfigurationException pce) { 125 throw new Exception (pce.getLocalizedMessage()); 127 } 128 catch (IOException ioe) { 129 throw new Exception (ioe.getLocalizedMessage()); 130 } 131 } 132 133 137 private void generateResourceObjects() throws Exception 138 { 139 if (document != null) { 140 for (Node nextKid = document.getDocumentElement().getFirstChild(); 141 nextKid != null; nextKid = nextKid.getNextSibling()) 142 { 143 String nodeName = nextKid.getNodeName(); 144 if (nodeName.equalsIgnoreCase(Resource.CUSTOM_RESOURCE)) { 145 generateCustomResource(nextKid); 146 } 147 else if (nodeName.equalsIgnoreCase(Resource.EXTERNAL_JNDI_RESOURCE)) 148 { 149 generateJNDIResource(nextKid); 150 } 151 else if (nodeName.equalsIgnoreCase(Resource.JDBC_RESOURCE)) 152 { 153 generateJDBCResource(nextKid); 154 } 155 else if (nodeName.equalsIgnoreCase(Resource.JDBC_CONNECTION_POOL)) 156 { 157 generateJDBCConnectionPoolResource(nextKid); 158 } 159 else if (nodeName.equalsIgnoreCase(Resource.MAIL_RESOURCE)) 160 { 161 generateMailResource(nextKid); 162 } 163 else if (nodeName.equalsIgnoreCase(Resource.PERSISTENCE_MANAGER_FACTORY_RESOURCE)) 164 { 165 generatePersistenceResource(nextKid); 166 } 167 else if (nodeName.equalsIgnoreCase(Resource.ADMIN_OBJECT_RESOURCE)) 168 { 169 generateAdminObjectResource(nextKid); 170 } 171 else if (nodeName.equalsIgnoreCase(Resource.CONNECTOR_RESOURCE)) 172 { 173 generateConnectorResource(nextKid); 174 } 175 else if (nodeName.equalsIgnoreCase(Resource.CONNECTOR_CONNECTION_POOL)) 176 { 177 generateConnectorConnectionPoolResource(nextKid); 178 } 179 else if (nodeName.equalsIgnoreCase(Resource.RESOURCE_ADAPTER_CONFIG)) 180 { 181 generateResourceAdapterConfig(nextKid); 182 } 183 } 184 } 185 } 186 187 208 private static List <Resource> getResourcesOfType(List <Resource> resources, 209 int type, boolean isResourceCreation) { 210 List <Resource> nonConnectorResources = new ArrayList <Resource>(); 211 List <Resource> connectorResources = new ArrayList <Resource>(); 212 213 for (Resource res : resources) { 214 if (isConnectorResource(res)) { 215 if (res.getType().equals(Resource.RESOURCE_ADAPTER_CONFIG)) { 216 if(isResourceCreation) { 217 nonConnectorResources.add(res); 221 } else { 222 connectorResources.add(res); 223 } 224 } else { 225 connectorResources.add(res); 226 } 227 } else { 228 nonConnectorResources.add(res); 229 } 230 } 231 232 List <Resource> finalSortedConnectorList = sortConnectorResources(connectorResources); 233 if (type == CONNECTOR) { 234 return finalSortedConnectorList; 235 } else { 236 return nonConnectorResources; 237 } 238 } 239 240 249 private static List <Resource> sortConnectorResources(List <Resource> connectorResources) { 250 List <Resource> raconfigs = new ArrayList <Resource>(); 251 List <Resource> ccps = new ArrayList <Resource>(); 252 List <Resource> others = new ArrayList <Resource>(); 253 254 List <Resource> finalSortedConnectorList = new ArrayList <Resource>(); 255 256 for (Resource resource : connectorResources) { 257 if (resource.getType().equals(Resource.RESOURCE_ADAPTER_CONFIG)){ 258 raconfigs.add(resource); 259 } else if (resource.getType().equals(Resource.CONNECTOR_CONNECTION_POOL)) { 260 ccps.add(resource); 261 } else { 262 others.add(resource); 263 } 264 } 265 266 finalSortedConnectorList.addAll(raconfigs); 267 finalSortedConnectorList.addAll(ccps); 268 finalSortedConnectorList.addAll(others); 269 return finalSortedConnectorList; 270 } 271 272 280 private static boolean isConnectorResource(Resource res) { 281 String type = res.getType(); 282 return ( 283 (type.equals(Resource.ADMIN_OBJECT_RESOURCE)) || 284 (type.equals(Resource.CONNECTOR_CONNECTION_POOL)) || 285 (type.equals(Resource.CONNECTOR_RESOURCE)) || 286 (type.equals(Resource.CONNECTOR_SECURITY_MAP)) || 287 (type.equals(Resource.RESOURCE_ADAPTER_CONFIG)) 288 ); 289 } 290 291 294 private void generateCustomResource(Node nextKid) throws Exception 295 { 296 NamedNodeMap attributes = nextKid.getAttributes(); 297 298 if (attributes == null) 299 return; 300 301 Node jndiNameNode = attributes.getNamedItem(JNDI_NAME); 302 String jndiName = jndiNameNode.getNodeValue(); 303 304 Node resTypeNode = attributes.getNamedItem(RES_TYPE); 305 String resType = resTypeNode.getNodeValue(); 306 307 Node factoryClassNode = attributes.getNamedItem(FACTORY_CLASS); 308 String factoryClass = factoryClassNode.getNodeValue(); 309 310 Node enabledNode = attributes.getNamedItem(ENABLED); 311 312 Resource customResource = new Resource(Resource.CUSTOM_RESOURCE); 313 customResource.setAttribute(JNDI_NAME, jndiName); 314 customResource.setAttribute(RES_TYPE, resType); 315 customResource.setAttribute(FACTORY_CLASS, factoryClass); 316 if (enabledNode != null) { 317 String sEnabled = enabledNode.getNodeValue(); 318 customResource.setAttribute(ENABLED, sEnabled); 319 } 320 321 NodeList children = nextKid.getChildNodes(); 322 generatePropertyElement(customResource, children); 323 vResources.add(customResource); 324 325 printResourceElements(customResource); 327 } 328 329 332 private void generateJNDIResource(Node nextKid) throws Exception 333 { 334 NamedNodeMap attributes = nextKid.getAttributes(); 335 if (attributes == null) 336 return; 337 338 Node jndiNameNode = attributes.getNamedItem(JNDI_NAME); 339 String jndiName = jndiNameNode.getNodeValue(); 340 Node jndiLookupNode = attributes.getNamedItem(JNDI_LOOKUP); 341 String jndiLookup = jndiLookupNode.getNodeValue(); 342 Node resTypeNode = attributes.getNamedItem(RES_TYPE); 343 String resType = resTypeNode.getNodeValue(); 344 Node factoryClassNode = attributes.getNamedItem(FACTORY_CLASS); 345 String factoryClass = factoryClassNode.getNodeValue(); 346 Node enabledNode = attributes.getNamedItem(ENABLED); 347 348 Resource jndiResource = new Resource(Resource.EXTERNAL_JNDI_RESOURCE); 349 jndiResource.setAttribute(JNDI_NAME, jndiName); 350 jndiResource.setAttribute(JNDI_LOOKUP, jndiLookup); 351 jndiResource.setAttribute(RES_TYPE, resType); 352 jndiResource.setAttribute(FACTORY_CLASS, factoryClass); 353 if (enabledNode != null) { 354 String sEnabled = enabledNode.getNodeValue(); 355 jndiResource.setAttribute(ENABLED, sEnabled); 356 } 357 358 NodeList children = nextKid.getChildNodes(); 359 generatePropertyElement(jndiResource, children); 360 vResources.add(jndiResource); 361 362 printResourceElements(jndiResource); 364 } 365 366 369 private void generateJDBCResource(Node nextKid) throws Exception 370 { 371 NamedNodeMap attributes = nextKid.getAttributes(); 372 if (attributes == null) 373 return; 374 375 Node jndiNameNode = attributes.getNamedItem(JNDI_NAME); 376 String jndiName = jndiNameNode.getNodeValue(); 377 Node poolNameNode = attributes.getNamedItem(POOL_NAME); 378 String poolName = poolNameNode.getNodeValue(); 379 Node enabledNode = attributes.getNamedItem(ENABLED); 380 381 Resource jdbcResource = new Resource(Resource.JDBC_RESOURCE); 382 jdbcResource.setAttribute(JNDI_NAME, jndiName); 383 jdbcResource.setAttribute(POOL_NAME, poolName); 384 if (enabledNode != null) { 385 String enabledName = enabledNode.getNodeValue(); 386 jdbcResource.setAttribute(ENABLED, enabledName); 387 } 388 389 NodeList children = nextKid.getChildNodes(); 390 if (children != null) 392 { 393 for (int ii=0; ii<children.getLength(); ii++) 394 { 395 if (children.item(ii).getNodeName().equals("description")) { 396 if (children.item(ii).getFirstChild() != null) { 397 jdbcResource.setDescription( 398 children.item(ii).getFirstChild().getNodeValue()); 399 } 400 } 401 } 402 } 403 404 vResources.add(jdbcResource); 405 406 printResourceElements(jdbcResource); 408 } 409 410 413 private void generateJDBCConnectionPoolResource(Node nextKid) throws Exception 414 { 415 NamedNodeMap attributes = nextKid.getAttributes(); 416 if (attributes == null) 417 return; 418 419 Node nameNode = attributes.getNamedItem(CONNECTION_POOL_NAME); 420 String name = nameNode.getNodeValue(); 421 Node nSteadyPoolSizeNode = attributes.getNamedItem(STEADY_POOL_SIZE); 422 Node nMaxPoolSizeNode = attributes.getNamedItem(MAX_POOL_SIZE); 423 Node nMaxWaitTimeInMillisNode = 424 attributes.getNamedItem(MAX_WAIT_TIME_IN_MILLIS); 425 Node nPoolSizeQuantityNode = 426 attributes.getNamedItem(POOL_SIZE_QUANTITY); 427 Node nIdleTimeoutInSecNode = 428 attributes.getNamedItem(IDLE_TIME_OUT_IN_SECONDS); 429 Node nIsConnectionValidationRequiredNode = 430 attributes.getNamedItem(IS_CONNECTION_VALIDATION_REQUIRED); 431 Node nConnectionValidationMethodNode = 432 attributes.getNamedItem(CONNECTION_VALIDATION_METHOD); 433 Node nFailAllConnectionsNode = 434 attributes.getNamedItem(FAIL_ALL_CONNECTIONS); 435 Node nValidationTableNameNode = 436 attributes.getNamedItem(VALIDATION_TABLE_NAME); 437 Node nResType = attributes.getNamedItem(RES_TYPE); 438 Node nTransIsolationLevel = 439 attributes.getNamedItem(TRANS_ISOLATION_LEVEL); 440 Node nIsIsolationLevelQuaranteed = 441 attributes.getNamedItem(IS_ISOLATION_LEVEL_GUARANTEED); 442 Node datasourceNode = attributes.getNamedItem(DATASOURCE_CLASS); 443 String datasource = datasourceNode.getNodeValue(); 444 445 Resource jdbcResource = new Resource(Resource.JDBC_CONNECTION_POOL); 446 jdbcResource.setAttribute(CONNECTION_POOL_NAME, name); 447 jdbcResource.setAttribute(DATASOURCE_CLASS, datasource); 448 if (nSteadyPoolSizeNode != null) { 449 String sSteadyPoolSize = nSteadyPoolSizeNode.getNodeValue(); 450 jdbcResource.setAttribute(STEADY_POOL_SIZE, sSteadyPoolSize); 451 } 452 if (nMaxPoolSizeNode != null) { 453 String sMaxPoolSize = nMaxPoolSizeNode.getNodeValue(); 454 jdbcResource.setAttribute(MAX_POOL_SIZE, sMaxPoolSize); 455 } 456 if (nMaxWaitTimeInMillisNode != null) { 457 String sMaxWaitTimeInMillis = nMaxWaitTimeInMillisNode.getNodeValue(); 458 jdbcResource.setAttribute(MAX_WAIT_TIME_IN_MILLIS, sMaxWaitTimeInMillis); 459 } 460 if (nPoolSizeQuantityNode != null) { 461 String sPoolSizeQuantity = nPoolSizeQuantityNode.getNodeValue(); 462 jdbcResource.setAttribute(POOL_SIZE_QUANTITY, sPoolSizeQuantity); 463 } 464 if (nIdleTimeoutInSecNode != null) { 465 String sIdleTimeoutInSec = nIdleTimeoutInSecNode.getNodeValue(); 466 jdbcResource.setAttribute(IDLE_TIME_OUT_IN_SECONDS, sIdleTimeoutInSec); 467 } 468 if (nIsConnectionValidationRequiredNode != null) { 469 String sIsConnectionValidationRequired = nIsConnectionValidationRequiredNode.getNodeValue(); 470 jdbcResource.setAttribute(IS_CONNECTION_VALIDATION_REQUIRED, sIsConnectionValidationRequired); 471 } 472 if (nConnectionValidationMethodNode != null) { 473 String sConnectionValidationMethod = nConnectionValidationMethodNode.getNodeValue(); 474 jdbcResource.setAttribute(CONNECTION_VALIDATION_METHOD, sConnectionValidationMethod); 475 } 476 if (nFailAllConnectionsNode != null) { 477 String sFailAllConnection = nFailAllConnectionsNode.getNodeValue(); 478 jdbcResource.setAttribute(FAIL_ALL_CONNECTIONS, sFailAllConnection); 479 } 480 if (nValidationTableNameNode != null) { 481 String sValidationTableName = nValidationTableNameNode.getNodeValue(); 482 jdbcResource.setAttribute(VALIDATION_TABLE_NAME, sValidationTableName); 483 } 484 if (nResType != null) { 485 String sResType = nResType.getNodeValue(); 486 jdbcResource.setAttribute(RES_TYPE, sResType); 487 } 488 if (nTransIsolationLevel != null) { 489 String sTransIsolationLevel = nTransIsolationLevel.getNodeValue(); 490 jdbcResource.setAttribute(TRANS_ISOLATION_LEVEL, sTransIsolationLevel); 491 } 492 if (nIsIsolationLevelQuaranteed != null) { 493 String sIsIsolationLevelQuaranteed = 494 nIsIsolationLevelQuaranteed.getNodeValue(); 495 jdbcResource.setAttribute(IS_ISOLATION_LEVEL_GUARANTEED, 496 sIsIsolationLevelQuaranteed); 497 } 498 499 NodeList children = nextKid.getChildNodes(); 500 generatePropertyElement(jdbcResource, children); 501 vResources.add(jdbcResource); 502 503 printResourceElements(jdbcResource); 505 } 506 507 510 private void generateMailResource(Node nextKid) throws Exception 511 { 512 NamedNodeMap attributes = nextKid.getAttributes(); 513 if (attributes == null) 514 return; 515 516 Node jndiNameNode = attributes.getNamedItem(JNDI_NAME); 517 Node hostNode = attributes.getNamedItem(MAIL_HOST); 518 Node userNode = attributes.getNamedItem(MAIL_USER); 519 Node fromAddressNode = attributes.getNamedItem(MAIL_FROM_ADDRESS); 520 Node storeProtoNode = attributes.getNamedItem(MAIL_STORE_PROTO); 521 Node storeProtoClassNode = attributes.getNamedItem(MAIL_STORE_PROTO_CLASS); 522 Node transProtoNode = attributes.getNamedItem(MAIL_TRANS_PROTO); 523 Node transProtoClassNode = attributes.getNamedItem(MAIL_TRANS_PROTO_CLASS); 524 Node debugNode = attributes.getNamedItem(MAIL_DEBUG); 525 Node enabledNode = attributes.getNamedItem(ENABLED); 526 527 String jndiName = jndiNameNode.getNodeValue(); 528 String host = hostNode.getNodeValue(); 529 String user = userNode.getNodeValue(); 530 String fromAddress = fromAddressNode.getNodeValue(); 531 532 Resource mailResource = new Resource(Resource.MAIL_RESOURCE); 533 534 mailResource.setAttribute(JNDI_NAME, jndiName); 535 mailResource.setAttribute(MAIL_HOST, host); 536 mailResource.setAttribute(MAIL_USER, user); 537 mailResource.setAttribute(MAIL_FROM_ADDRESS, fromAddress); 538 if (storeProtoNode != null) { 539 String sStoreProto = storeProtoNode.getNodeValue(); 540 mailResource.setAttribute(MAIL_STORE_PROTO, sStoreProto); 541 } 542 if (storeProtoClassNode != null) { 543 String sStoreProtoClass = storeProtoClassNode.getNodeValue(); 544 mailResource.setAttribute(MAIL_STORE_PROTO_CLASS, sStoreProtoClass); 545 } 546 if (transProtoNode != null) { 547 String sTransProto = transProtoNode.getNodeValue(); 548 mailResource.setAttribute(MAIL_TRANS_PROTO, sTransProto); 549 } 550 if (transProtoClassNode != null) { 551 String sTransProtoClass = transProtoClassNode.getNodeValue(); 552 mailResource.setAttribute(MAIL_TRANS_PROTO_CLASS, sTransProtoClass); 553 } 554 if (debugNode != null) { 555 String sDebug = debugNode.getNodeValue(); 556 mailResource.setAttribute(MAIL_DEBUG, sDebug); 557 } 558 if (enabledNode != null) { 559 String sEnabled = enabledNode.getNodeValue(); 560 mailResource.setAttribute(ENABLED, sEnabled); 561 } 562 563 NodeList children = nextKid.getChildNodes(); 564 generatePropertyElement(mailResource, children); 565 vResources.add(mailResource); 566 567 printResourceElements(mailResource); 569 } 570 571 574 private void generatePersistenceResource(Node nextKid) throws Exception 575 { 576 NamedNodeMap attributes = nextKid.getAttributes(); 577 if (attributes == null) 578 return; 579 580 Node jndiNameNode = attributes.getNamedItem(JNDI_NAME); 581 String jndiName = jndiNameNode.getNodeValue(); 582 Node factoryClassNode = attributes.getNamedItem(FACTORY_CLASS); 583 Node poolNameNode = attributes.getNamedItem(JDBC_RESOURCE_JNDI_NAME); 584 Node enabledNode = attributes.getNamedItem(ENABLED); 585 586 Resource persistenceResource = 587 new Resource(Resource.PERSISTENCE_MANAGER_FACTORY_RESOURCE); 588 persistenceResource.setAttribute(JNDI_NAME, jndiName); 589 if (factoryClassNode != null) { 590 String factoryClass = factoryClassNode.getNodeValue(); 591 persistenceResource.setAttribute(FACTORY_CLASS, factoryClass); 592 } 593 if (poolNameNode != null) { 594 String poolName = poolNameNode.getNodeValue(); 595 persistenceResource.setAttribute(JDBC_RESOURCE_JNDI_NAME, poolName); 596 } 597 if (enabledNode != null) { 598 String sEnabled = enabledNode.getNodeValue(); 599 persistenceResource.setAttribute(ENABLED, sEnabled); 600 } 601 602 NodeList children = nextKid.getChildNodes(); 603 generatePropertyElement(persistenceResource, children); 604 vResources.add(persistenceResource); 605 606 printResourceElements(persistenceResource); 608 } 609 610 613 private void generateAdminObjectResource(Node nextKid) throws Exception 614 { 615 NamedNodeMap attributes = nextKid.getAttributes(); 616 if (attributes == null) 617 return; 618 619 Node jndiNameNode = attributes.getNamedItem(JNDI_NAME); 620 String jndiName = jndiNameNode.getNodeValue(); 621 Node resTypeNode = attributes.getNamedItem(RES_TYPE); 622 String resType = resTypeNode.getNodeValue(); 623 Node resAdapterNode = attributes.getNamedItem(RES_ADAPTER); 624 String resAdapter = resAdapterNode.getNodeValue(); 625 Node enabledNode = attributes.getNamedItem(ENABLED); 626 627 Resource adminObjectResource = 628 new Resource(Resource.ADMIN_OBJECT_RESOURCE); 629 adminObjectResource.setAttribute(JNDI_NAME, jndiName); 630 adminObjectResource.setAttribute(RES_TYPE, resType); 631 adminObjectResource.setAttribute(RES_ADAPTER, resAdapter); 632 633 if (enabledNode != null) { 634 String sEnabled = enabledNode.getNodeValue(); 635 adminObjectResource.setAttribute(ENABLED, sEnabled); 636 } 637 638 NodeList children = nextKid.getChildNodes(); 639 generatePropertyElement(adminObjectResource, children); 640 vResources.add(adminObjectResource); 641 642 printResourceElements(adminObjectResource); 644 } 645 646 649 private void generateConnectorResource(Node nextKid) throws Exception 650 { 651 NamedNodeMap attributes = nextKid.getAttributes(); 652 if (attributes == null) 653 return; 654 655 Node jndiNameNode = attributes.getNamedItem(JNDI_NAME); 656 String jndiName = jndiNameNode.getNodeValue(); 657 Node poolNameNode = attributes.getNamedItem(POOL_NAME); 658 String poolName = poolNameNode.getNodeValue(); 659 Node resTypeNode = attributes.getNamedItem(RESOURCE_TYPE); 660 Node enabledNode = attributes.getNamedItem(ENABLED); 661 662 Resource connectorResource = 663 new Resource(Resource.CONNECTOR_RESOURCE); 664 connectorResource.setAttribute(JNDI_NAME, jndiName); 665 connectorResource.setAttribute(POOL_NAME, poolName); 666 if (resTypeNode != null) { 667 String resType = resTypeNode.getNodeValue(); 668 connectorResource.setAttribute(RESOURCE_TYPE, resType); 669 } 670 if (enabledNode != null) { 671 String sEnabled = enabledNode.getNodeValue(); 672 connectorResource.setAttribute(ENABLED, sEnabled); 673 } 674 675 NodeList children = nextKid.getChildNodes(); 676 generatePropertyElement(connectorResource, children); 677 vResources.add(connectorResource); 678 679 printResourceElements(connectorResource); 681 } 682 683 private void generatePropertyElement(Resource rs, NodeList children) throws Exception 684 { 685 if (children != null) { 686 for (int i=0; i<children.getLength(); i++) { 687 if (children.item(i).getNodeName().equals("property")) { 688 NamedNodeMap attNodeMap = children.item(i).getAttributes(); 689 Node nameNode = attNodeMap.getNamedItem("name"); 690 Node valueNode = attNodeMap.getNamedItem("value"); 691 if (nameNode != null && valueNode != null) { 692 boolean bDescFound = false; 693 String sName = nameNode.getNodeValue(); 694 String sValue = valueNode.getNodeValue(); 695 Node descNode = children.item(i).getFirstChild(); 700 while (descNode != null && !bDescFound) { 701 if (descNode.getNodeName().equalsIgnoreCase("description")) { 702 try { 703 rs.setProperty(sName, sValue); 705 bDescFound = true; 706 } 707 catch (DOMException dome) { 708 throw new Exception (dome.getLocalizedMessage()); 710 } 711 } 712 descNode = descNode.getNextSibling(); 713 } 714 if (!bDescFound) { 715 rs.setProperty(sName, sValue); 716 } 717 } 718 } 719 if (children.item(i).getNodeName().equals("description")) { 720 rs.setDescription(children.item(i).getFirstChild().getNodeValue()); 721 } 722 } 723 } 724 } 725 726 729 private void generateConnectorConnectionPoolResource(Node nextKid) throws Exception 730 { 731 NamedNodeMap attributes = nextKid.getAttributes(); 732 if (attributes == null) 733 return ; 734 735 Node nameNode 736 = attributes.getNamedItem(CONNECTOR_CONNECTION_POOL_NAME); 737 Node raConfigNode 738 = attributes.getNamedItem(RESOURCE_ADAPTER_CONFIG_NAME); 739 Node conDefNode 740 = attributes.getNamedItem(CONN_DEF_NAME); 741 Node steadyPoolSizeNode 742 = attributes.getNamedItem(CONN_STEADY_POOL_SIZE); 743 Node maxPoolSizeNode 744 = attributes.getNamedItem(CONN_MAX_POOL_SIZE); 745 Node poolResizeNode 746 = attributes.getNamedItem(CONN_POOL_RESIZE_QUANTITY); 747 Node idleTimeOutNode 748 = attributes.getNamedItem(CONN_IDLE_TIME_OUT); 749 Node failAllConnNode 750 = attributes.getNamedItem(CONN_FAIL_ALL_CONNECTIONS); 751 752 String poolName = null; 753 754 Resource connectorConnPoolResource = new Resource(Resource.CONNECTOR_CONNECTION_POOL); 755 if(nameNode != null){ 756 poolName = nameNode.getNodeValue(); 757 connectorConnPoolResource.setAttribute(CONNECTION_POOL_NAME, poolName); 758 } 759 if(raConfigNode != null){ 760 String raConfig = raConfigNode.getNodeValue(); 761 connectorConnPoolResource.setAttribute(RESOURCE_ADAPTER_CONFIG_NAME,raConfig); 762 } 763 if(conDefNode != null){ 764 String conDef = conDefNode.getNodeValue(); 765 connectorConnPoolResource.setAttribute(CONN_DEF_NAME,conDef); 766 } 767 if(steadyPoolSizeNode != null){ 768 String steadyPoolSize = steadyPoolSizeNode.getNodeValue(); 769 connectorConnPoolResource.setAttribute(CONN_STEADY_POOL_SIZE,steadyPoolSize); 770 } 771 if(maxPoolSizeNode != null){ 772 String maxPoolSize = maxPoolSizeNode.getNodeValue(); 773 connectorConnPoolResource.setAttribute(CONN_MAX_POOL_SIZE,maxPoolSize); 774 } 775 if(poolResizeNode != null){ 776 String poolResize = poolResizeNode.getNodeValue(); 777 connectorConnPoolResource.setAttribute(CONN_POOL_RESIZE_QUANTITY,poolResize); 778 } 779 if(idleTimeOutNode != null){ 780 String idleTimeOut = idleTimeOutNode.getNodeValue(); 781 connectorConnPoolResource.setAttribute(CONN_IDLE_TIME_OUT,idleTimeOut); 782 } 783 if(failAllConnNode != null){ 784 String failAllConn = failAllConnNode.getNodeValue(); 785 connectorConnPoolResource.setAttribute(CONN_FAIL_ALL_CONNECTIONS,failAllConn); 786 } 787 788 NodeList children = nextKid.getChildNodes(); 789 generatePropertyElement(connectorConnPoolResource, children); 791 792 vResources.add(connectorConnPoolResource); 793 if (children != null){ 795 for (int i=0; i<children.getLength(); i++) { 796 if((children.item(i).getNodeName().equals(SECURITY_MAP))) 797 generateSecurityMap(poolName,children.item(i)); 798 799 } 800 } 801 802 803 804 printResourceElements(connectorConnPoolResource); 806 } 807 808 private void generateSecurityMap(String poolName,Node mapNode) throws Exception { 809 810 NamedNodeMap attributes = mapNode.getAttributes(); 811 if (attributes == null) 812 return ; 813 Node nameNode 814 = attributes.getNamedItem(SECURITY_MAP_NAME); 815 816 817 Resource map = new Resource(Resource.CONNECTOR_SECURITY_MAP); 818 if(nameNode != null){ 819 String name = nameNode.getNodeValue(); 820 map.setAttribute(SECURITY_MAP_NAME, name); 821 } 822 if(poolName != null) 823 map.setAttribute(POOL_NAME,poolName); 824 825 StringBuffer principal = new StringBuffer (); 826 StringBuffer usergroup = new StringBuffer (); 827 828 NodeList children = mapNode.getChildNodes(); 829 830 if(children != null){ 831 for (int i=0; i<children.getLength(); i++){ 832 Node gChild = children.item(i); 833 String strNodeName = gChild.getNodeName(); 834 if(strNodeName.equals(PRINCIPAL)){ 835 String p = (gChild.getFirstChild()).getNodeValue(); 836 principal.append(p+","); 837 } 838 if(strNodeName.equals(USERGROUP)){ 839 String u = (gChild.getFirstChild()).getNodeValue(); 840 usergroup.append(u+","); 841 } 842 if((strNodeName.equals(BACKEND_PRINCIPAL))){ 843 NamedNodeMap attributes1 = (children.item(i)).getAttributes(); 844 if(attributes1 != null){ 845 Node userNode = attributes1.getNamedItem(USER_NAME); 846 if(userNode != null){ 847 String userName =userNode.getNodeValue(); 848 map.setAttribute(USER_NAME,userName); 849 } 850 Node passwordNode = attributes1.getNamedItem(PASSWORD); 851 if(passwordNode != null){ 852 String pwd = passwordNode.getNodeValue(); 853 map.setAttribute(PASSWORD,pwd); 854 } 855 } 856 } 857 } 858 } 859 if(principal != null) 860 map.setAttribute(PRINCIPAL,convertToStringArray(principal.toString())); 861 if(usergroup != null) 862 map.setAttribute("user_group",convertToStringArray(usergroup.toString())); 863 vResources.add(map); 864 } 866 867 871 872 873 private void generateResourceAdapterConfig(Node nextKid) throws Exception 874 { NamedNodeMap attributes = nextKid.getAttributes(); 875 if (attributes == null) 876 return; 877 878 Resource resAdapterConfigResource = new Resource(Resource.RESOURCE_ADAPTER_CONFIG); 879 Node resAdapConfigNode = attributes.getNamedItem(RES_ADAPTER_CONFIG); 880 if(resAdapConfigNode != null){ 881 String resAdapConfig = resAdapConfigNode.getNodeValue(); 882 resAdapterConfigResource.setAttribute(RES_ADAPTER_CONFIG,resAdapConfig); 883 } 884 Node poolIdNode = attributes.getNamedItem(THREAD_POOL_IDS); 885 if(poolIdNode != null){ 886 String threadPoolId = poolIdNode.getNodeValue(); 887 resAdapterConfigResource.setAttribute(THREAD_POOL_IDS,threadPoolId); 888 } 889 Node resAdapNameNode = attributes.getNamedItem(RES_ADAPTER_NAME); 890 if(resAdapNameNode != null){ 891 String resAdapName = resAdapNameNode.getNodeValue(); 892 resAdapterConfigResource.setAttribute(RES_ADAPTER_NAME,resAdapName); 893 } 894 895 NodeList children = nextKid.getChildNodes(); 896 generatePropertyElement(resAdapterConfigResource, children); 897 vResources.add(resAdapterConfigResource); 898 899 printResourceElements(resAdapterConfigResource); 901 } 902 903 908 public Iterator <Resource> getResources() 909 { 910 return vResources.iterator(); 911 } 912 913 public List getResourcesList() { 914 return vResources; 915 } 916 917 929 public static List getNonConnectorResourcesList(List <Resource> resources, 930 boolean isResourceCreation) { 931 return getResourcesOfType(resources, NONCONNECTOR, isResourceCreation); 932 } 933 934 946 947 public static List getConnectorResourcesList(List <Resource> resources, boolean isResourceCreation) { 948 return getResourcesOfType(resources, CONNECTOR, isResourceCreation); 949 } 950 951 954 private void printResourceElements(Resource resource) 955 { 956 AttributeList attrList = resource.getAttributes(); 957 958 for (int i=0; i<attrList.size(); i++) 959 { 960 Attribute attr = (Attribute )attrList.get(i); 961 Logger logger = Logger.getLogger(AdminConstants.kLoggerName); 962 logger.log(Level.FINE, "general.print_attr_name", attr.getName()); 963 } 964 } 965 966 private String [] convertToStringArray(Object sOptions){ 968 StringTokenizer optionTokenizer = new StringTokenizer ((String )sOptions,","); 969 int size = optionTokenizer.countTokens(); 970 String [] sOptionsList = new String [size]; 971 for (int ii=0; ii<size; ii++){ 972 sOptionsList[ii] = optionTokenizer.nextToken(); 973 } 974 return sOptionsList; 975 } 976 977 978 class AddResourcesErrorHandler implements ErrorHandler { 979 public void error(SAXParseException e) throws org.xml.sax.SAXException { 980 throw e ; 981 } 982 public void fatalError(SAXParseException e) throws org.xml.sax.SAXException { 983 throw e ; 984 } 985 public void warning(SAXParseException e) throws org.xml.sax.SAXException { 986 throw e ; 987 } 988 } 989 990 991 public InputSource resolveEntity(String publicId,String systemId) 992 throws SAXException { 993 InputSource is = null; 994 try { 995 String dtd = System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY) + 996 File.separator + "lib" + File.separator + "dtds" + File.separator + 997 "sun-resources_1_2.dtd"; 998 is = new InputSource (new java.io.FileInputStream (dtd)); 999 } catch(Exception e) { 1000 throw new SAXException ("cannot resolve dtd", e); 1001 } 1002 return is; 1003 } 1004} 1005 1006 | Popular Tags |