KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > mbean > config > ResourcesXMLParser


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.server.core.mbean.config;
25
26 import java.net.URL JavaDoc;
27
28 import javax.xml.parsers.DocumentBuilder JavaDoc;
29 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
30 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
31 import javax.xml.parsers.ParserConfigurationException JavaDoc;
32  
33 import org.xml.sax.SAXException JavaDoc;
34 import org.xml.sax.SAXParseException JavaDoc;
35 import org.xml.sax.InputSource JavaDoc;
36
37 import java.io.File JavaDoc;
38 import java.io.IOException JavaDoc;
39
40 import org.w3c.dom.Document JavaDoc;
41 import org.w3c.dom.DOMException JavaDoc;
42 import org.w3c.dom.Node JavaDoc;
43 import org.w3c.dom.NodeList JavaDoc;
44 import org.w3c.dom.NamedNodeMap JavaDoc;
45
46 import java.util.Vector JavaDoc;
47 import java.util.Properties JavaDoc;
48 import java.util.Iterator JavaDoc;
49 import java.util.Enumeration JavaDoc;
50
51 import com.sun.enterprise.config.serverbeans.ElementProperty;
52 import com.sun.enterprise.admin.common.constant.AdminConstants;
53
54 import java.util.logging.Level JavaDoc;
55 import java.util.logging.Logger JavaDoc;
56
57 //i18n import
58
import com.sun.enterprise.util.i18n.StringManager;
59
60 /**
61  *This Class reads the Properties (resources) from the xml file supplied
62  *to constructor
63  */

64 public class ResourcesXMLParser
65 {
66
67     private File JavaDoc resourceFile = null;
68     private Document JavaDoc document;
69     private Vector JavaDoc resources;
70     
71     // node name constants
72
private static final String JavaDoc CUSTOM_RESOURCE = "custom-resource";
73     private static final String JavaDoc EXT_JNDI_RESOURCE = "external-jndi-resource";
74     private static final String JavaDoc JDBC_RESOURCE = "jdbc-resource";
75     private static final String JavaDoc JDBC_CONN_POOL = "jdbc-connection-pool";
76     private static final String JavaDoc MAIL_RESOURCE = "mail-resource";
77     private static final String JavaDoc PERSISTENCE_RESOURCE =
78                                         "persistence-manager-factory-resource";
79     private static final String JavaDoc JMS_RESOURCE = "jms-resource";
80
81     // i18n StringManager
82
private static StringManager localStrings =
83         StringManager.getManager( ResourcesXMLParser.class );
84     
85     //Attribute names constants
86
// JDBC Resource
87
public static final String JavaDoc JNDI_NAME = "jndi-name";
88     public static final String JavaDoc POOL_NAME = "pool-name";
89     // JMS Resource
90
public static final String JavaDoc RES_TYPE = "res-type";
91     public static final String JavaDoc FACTORY_CLASS = "factory-class";
92     public static final String JavaDoc ENABLED = "enabled";
93
94     // External JNDI Resource
95
public static final String JavaDoc JNDI_LOOKUP = "jndi-lookup-name";
96     
97     // JDBC Connection pool
98
//public static final String ID = "id";
99
public static final String JavaDoc CONNECTION_POOL_NAME = "name";
100     public static final String JavaDoc STEADY_POOL_SIZE = "steady-pool-size";
101     public static final String JavaDoc MAX_POOL_SIZE = "max-pool-size";
102     public static final String JavaDoc MAX_WAIT_TIME_IN_MILLIS = "max-wait-time-in-millis";
103     public static final String JavaDoc POOL_SIZE_QUANTITY = "pool-resize-quantity";
104     public static final String JavaDoc IDLE_TIME_OUT_IN_SECONDS = "idle-timeout-in-seconds";
105     public static final String JavaDoc IS_CONNECTION_VALIDATION_REQUIRED = "is-connection-validation-required";
106     public static final String JavaDoc CONNECTION_VALIDATION_METHOD = "connection-validation-method";
107     public static final String JavaDoc FAIL_ALL_CONNECTIONS = "fail-all-connections";
108     public static final String JavaDoc VALIDATION_TABLE_NAME = "validation-table-name";
109     public static final String JavaDoc DATASOURCE_CLASS = "datasource-classname";
110     public static final String JavaDoc TRANS_ISOLATION_LEVEL = "transaction-isolation-level";
111     public static final String JavaDoc IS_ISOLATION_LEVEL_GUARANTEED = "is-isolation-level-guaranteed";
112
113     //Mail resource
114
public static final String JavaDoc MAIL_HOST = "host";
115     public static final String JavaDoc MAIL_USER = "user";
116     public static final String JavaDoc MAIL_FROM_ADDRESS = "from";
117     public static final String JavaDoc MAIL_STORE_PROTO = "store-protocol";
118     public static final String JavaDoc MAIL_STORE_PROTO_CLASS = "store-protocol-class";
119     public static final String JavaDoc MAIL_TRANS_PROTO = "transport-protocol";
120     public static final String JavaDoc MAIL_TRANS_PROTO_CLASS = "transport-protocol-class";
121     public static final String JavaDoc MAIL_DEBUG = "debug";
122
123     //Persistence Manager Factory resource
124
public static final String JavaDoc JDBC_RESOURCE_JNDI_NAME = "jdbc-resource-jndi-name";
125   
126     /** Creates new ResourcesXMLParser */
127     public ResourcesXMLParser(String JavaDoc resourceFileName) throws Exception JavaDoc
128     {
129         resourceFile = new File JavaDoc(resourceFileName);
130         initProperties();
131         resources = new Vector JavaDoc();
132         generateResourceObjects();
133     }
134
135     /**
136      *Parse the XML Properties file and populate it into document object
137      */

138     public void initProperties() throws Exception JavaDoc
139     {
140         DocumentBuilderFactory JavaDoc factory =
141             DocumentBuilderFactory.newInstance();
142         try
143         {
144             factory.setValidating(false);
145             DocumentBuilder JavaDoc builder = factory.newDocumentBuilder();
146             if (resourceFile == null)
147             {
148                 String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.no_resource_file" );
149                 throw new Exception JavaDoc( msg );
150             }
151             InputSource JavaDoc is = new InputSource JavaDoc(resourceFile.toString());
152             document = builder.parse(is);
153
154         }
155         catch (SAXException JavaDoc sxe)
156         {
157             Exception JavaDoc x = sxe;
158             if (sxe.getException() != null)
159                x = sxe.getException();
160             //x.printStackTrace();
161
throw new Exception JavaDoc(x.getLocalizedMessage());
162
163         }
164         catch (ParserConfigurationException JavaDoc pce)
165         {
166             // Parser with specified options can't be built
167
throw new Exception JavaDoc(pce.getLocalizedMessage());
168         }
169         catch (IOException JavaDoc ioe)
170         {
171             // I/O error
172
throw new Exception JavaDoc(ioe.getLocalizedMessage());
173         }
174     }
175     
176     /**
177      * Get All the resources from the document object.
178      *
179      */

180     private void generateResourceObjects() throws Exception JavaDoc
181     {
182         if (document != null)
183         {
184             for (Node JavaDoc nextKid = document.getDocumentElement().getFirstChild();
185                     nextKid != null; nextKid = nextKid.getNextSibling())
186             {
187                 String JavaDoc nodeName = nextKid.getNodeName();
188                 if (nodeName.equalsIgnoreCase(CUSTOM_RESOURCE))
189                 {
190                     generateCustomResource(nextKid);
191                 }
192                 else if (nodeName.equalsIgnoreCase(EXT_JNDI_RESOURCE))
193                 {
194                     generateJNDIResource(nextKid);
195                 }
196                 else if (nodeName.equalsIgnoreCase(JDBC_RESOURCE))
197                 {
198                     generateJDBCResource(nextKid);
199                 }
200                 else if (nodeName.equalsIgnoreCase(JDBC_CONN_POOL))
201                 {
202                     generateJDBCConnectionPoolResource(nextKid);
203                 }
204                 else if (nodeName.equalsIgnoreCase(MAIL_RESOURCE))
205                 {
206                     generateMailResource(nextKid);
207                 }
208                 else if (nodeName.equalsIgnoreCase(PERSISTENCE_RESOURCE))
209                 {
210                     generatePersistenceResource(nextKid);
211                 }
212                 else if (nodeName.equalsIgnoreCase(JMS_RESOURCE))
213                 {
214                     generateJMSResource(nextKid);
215                 }
216                 
217             }
218         }
219     }
220     
221     /*
222      * Generate the Custom resource
223      */

224     private void generateCustomResource(Node JavaDoc nextKid) throws Exception JavaDoc
225     {
226         NamedNodeMap JavaDoc attributes = nextKid.getAttributes();
227         if (attributes == null)
228             return;
229         
230         Node JavaDoc jndiNameNode = attributes.getNamedItem(JNDI_NAME);
231         String JavaDoc jndiName = jndiNameNode.getNodeValue();
232         Node JavaDoc resTypeNode = attributes.getNamedItem(RES_TYPE);
233         String JavaDoc resType = resTypeNode.getNodeValue();
234         Node JavaDoc factoryClassNode =
235                 attributes.getNamedItem(FACTORY_CLASS);
236         String JavaDoc factoryClass = factoryClassNode.getNodeValue();
237         Node JavaDoc enabledNode = attributes.getNamedItem(ENABLED);
238         
239         Resource customResource = new Resource(Resource.CUSTOM_RESOURCE);
240         customResource.setAttribute(JNDI_NAME, jndiName);
241         customResource.setAttribute(RES_TYPE, resType);
242         customResource.setAttribute(FACTORY_CLASS, factoryClass);
243         if (enabledNode != null) {
244            String JavaDoc sEnabled = enabledNode.getNodeValue();
245            customResource.setAttribute(ENABLED, sEnabled);
246         }
247         
248         NodeList JavaDoc children = nextKid.getChildNodes();
249         generatePropertyElement(customResource, children);
250         resources.add(customResource);
251         
252         //debug strings
253
printResourceElements(customResource);
254     }
255     
256     /*
257      * Generate the JNDI resource
258      */

259     private void generateJNDIResource(Node JavaDoc nextKid) throws Exception JavaDoc
260     {
261         NamedNodeMap JavaDoc attributes = nextKid.getAttributes();
262         if (attributes == null)
263             return;
264         
265         Node JavaDoc jndiNameNode = attributes.getNamedItem(JNDI_NAME);
266         String JavaDoc jndiName = jndiNameNode.getNodeValue();
267         Node JavaDoc jndiLookupNode = attributes.getNamedItem(JNDI_LOOKUP);
268         String JavaDoc jndiLookup = jndiLookupNode.getNodeValue();
269         Node JavaDoc resTypeNode = attributes.getNamedItem(RES_TYPE);
270         String JavaDoc resType = resTypeNode.getNodeValue();
271         Node JavaDoc factoryClassNode = attributes.getNamedItem(FACTORY_CLASS);
272         String JavaDoc factoryClass = factoryClassNode.getNodeValue();
273         Node JavaDoc enabledNode = attributes.getNamedItem(ENABLED);
274         
275         Resource jndiResource = new Resource(Resource.EXT_JNDI_RESOURCE);
276         jndiResource.setAttribute(JNDI_NAME, jndiName);
277         jndiResource.setAttribute(JNDI_LOOKUP, jndiLookup);
278         jndiResource.setAttribute(RES_TYPE, resType);
279         jndiResource.setAttribute(FACTORY_CLASS, factoryClass);
280         if (enabledNode != null) {
281            String JavaDoc sEnabled = enabledNode.getNodeValue();
282            jndiResource.setAttribute(ENABLED, sEnabled);
283         }
284         
285         NodeList JavaDoc children = nextKid.getChildNodes();
286         generatePropertyElement(jndiResource, children);
287         resources.add(jndiResource);
288         
289         //debug strings
290
printResourceElements(jndiResource);
291     }
292     
293     /*
294      * Generate the JDBC resource
295      */

296     private void generateJDBCResource(Node JavaDoc nextKid) throws Exception JavaDoc
297     {
298         NamedNodeMap JavaDoc attributes = nextKid.getAttributes();
299         if (attributes == null)
300             return;
301         
302         Node JavaDoc jndiNameNode = attributes.getNamedItem(JNDI_NAME);
303         String JavaDoc jndiName = jndiNameNode.getNodeValue();
304         Node JavaDoc poolNameNode = attributes.getNamedItem(POOL_NAME);
305         String JavaDoc poolName = poolNameNode.getNodeValue();
306         Node JavaDoc enabledNode = attributes.getNamedItem(ENABLED);
307
308         Resource jdbcResource = new Resource(Resource.JDBC_RESOURCE);
309         jdbcResource.setAttribute(JNDI_NAME, jndiName);
310         jdbcResource.setAttribute(POOL_NAME, poolName);
311         if (enabledNode != null) {
312            String JavaDoc enabledName = enabledNode.getNodeValue();
313            jdbcResource.setAttribute(ENABLED, enabledName);
314         }
315         
316         NodeList JavaDoc children = nextKid.getChildNodes();
317         //get description
318
if (children != null)
319         {
320             for (int ii=0; ii<children.getLength(); ii++)
321             {
322                 if (children.item(ii).getNodeName().equals("description"))
323                     jdbcResource.setDescription(
324                     children.item(ii).getFirstChild().getNodeValue());
325             }
326         }
327
328         resources.add(jdbcResource);
329         
330         //debug strings
331
printResourceElements(jdbcResource);
332     }
333     
334     /*
335      * Generate the JDBC Connection pool Resource
336      */

337     private void generateJDBCConnectionPoolResource(Node JavaDoc nextKid) throws Exception JavaDoc
338     {
339         NamedNodeMap JavaDoc attributes = nextKid.getAttributes();
340         if (attributes == null)
341             return;
342         
343         Node JavaDoc nameNode = attributes.getNamedItem(CONNECTION_POOL_NAME);
344         String JavaDoc name = nameNode.getNodeValue();
345         Node JavaDoc nSteadyPoolSizeNode = attributes.getNamedItem(STEADY_POOL_SIZE);
346         Node JavaDoc nMaxPoolSizeNode = attributes.getNamedItem(MAX_POOL_SIZE);
347         Node JavaDoc nMaxWaitTimeInMillisNode =
348              attributes.getNamedItem(MAX_WAIT_TIME_IN_MILLIS);
349         Node JavaDoc nPoolSizeQuantityNode =
350              attributes.getNamedItem(POOL_SIZE_QUANTITY);
351         Node JavaDoc nIdleTimeoutInSecNode =
352              attributes.getNamedItem(IDLE_TIME_OUT_IN_SECONDS);
353         Node JavaDoc nIsConnectionValidationRequiredNode =
354              attributes.getNamedItem(IS_CONNECTION_VALIDATION_REQUIRED);
355         Node JavaDoc nConnectionValidationMethodNode =
356              attributes.getNamedItem(CONNECTION_VALIDATION_METHOD);
357         Node JavaDoc nFailAllConnectionsNode =
358              attributes.getNamedItem(FAIL_ALL_CONNECTIONS);
359         Node JavaDoc nValidationTableNameNode =
360              attributes.getNamedItem(VALIDATION_TABLE_NAME);
361         Node JavaDoc nResType = attributes.getNamedItem(RES_TYPE);
362         Node JavaDoc nTransIsolationLevel =
363              attributes.getNamedItem(TRANS_ISOLATION_LEVEL);
364         Node JavaDoc nIsIsolationLevelQuaranteed =
365              attributes.getNamedItem(IS_ISOLATION_LEVEL_GUARANTEED);
366         Node JavaDoc datasourceNode = attributes.getNamedItem(DATASOURCE_CLASS);
367         String JavaDoc datasource = datasourceNode.getNodeValue();
368         
369         Resource jdbcResource = new Resource(Resource.JDBC_CONN_POOL);
370         jdbcResource.setAttribute(CONNECTION_POOL_NAME, name);
371         jdbcResource.setAttribute(DATASOURCE_CLASS, datasource);
372         if (nSteadyPoolSizeNode != null) {
373            String JavaDoc sSteadyPoolSize = nSteadyPoolSizeNode.getNodeValue();
374            jdbcResource.setAttribute(STEADY_POOL_SIZE, sSteadyPoolSize);
375         }
376         if (nMaxPoolSizeNode != null) {
377            String JavaDoc sMaxPoolSize = nMaxPoolSizeNode.getNodeValue();
378            jdbcResource.setAttribute(MAX_POOL_SIZE, sMaxPoolSize);
379         }
380         if (nMaxWaitTimeInMillisNode != null) {
381            String JavaDoc sMaxWaitTimeInMillis = nMaxWaitTimeInMillisNode.getNodeValue();
382            jdbcResource.setAttribute(MAX_WAIT_TIME_IN_MILLIS, sMaxWaitTimeInMillis);
383         }
384         if (nPoolSizeQuantityNode != null) {
385            String JavaDoc sPoolSizeQuantity = nPoolSizeQuantityNode.getNodeValue();
386            jdbcResource.setAttribute(POOL_SIZE_QUANTITY, sPoolSizeQuantity);
387         }
388         if (nIdleTimeoutInSecNode != null) {
389            String JavaDoc sIdleTimeoutInSec = nIdleTimeoutInSecNode.getNodeValue();
390            jdbcResource.setAttribute(IDLE_TIME_OUT_IN_SECONDS, sIdleTimeoutInSec);
391         }
392         if (nIsConnectionValidationRequiredNode != null) {
393            String JavaDoc sIsConnectionValidationRequired = nIsConnectionValidationRequiredNode.getNodeValue();
394            jdbcResource.setAttribute(IS_CONNECTION_VALIDATION_REQUIRED, sIsConnectionValidationRequired);
395         }
396         if (nConnectionValidationMethodNode != null) {
397            String JavaDoc sConnectionValidationMethod = nConnectionValidationMethodNode.getNodeValue();
398            jdbcResource.setAttribute(CONNECTION_VALIDATION_METHOD, sConnectionValidationMethod);
399         }
400         if (nFailAllConnectionsNode != null) {
401            String JavaDoc sFailAllConnection = nFailAllConnectionsNode.getNodeValue();
402            jdbcResource.setAttribute(FAIL_ALL_CONNECTIONS, sFailAllConnection);
403         }
404         if (nValidationTableNameNode != null) {
405            String JavaDoc sValidationTableName = nValidationTableNameNode.getNodeValue();
406            jdbcResource.setAttribute(VALIDATION_TABLE_NAME, sValidationTableName);
407         }
408         if (nResType != null) {
409            String JavaDoc sResType = nResType.getNodeValue();
410            jdbcResource.setAttribute(RES_TYPE, sResType);
411         }
412         if (nTransIsolationLevel != null) {
413            String JavaDoc sTransIsolationLevel = nTransIsolationLevel.getNodeValue();
414            jdbcResource.setAttribute(TRANS_ISOLATION_LEVEL, sTransIsolationLevel);
415         }
416         if (nIsIsolationLevelQuaranteed != null) {
417            String JavaDoc sIsIsolationLevelQuaranteed =
418                   nIsIsolationLevelQuaranteed.getNodeValue();
419            jdbcResource.setAttribute(IS_ISOLATION_LEVEL_GUARANTEED,
420                                      sIsIsolationLevelQuaranteed);
421         }
422         
423         NodeList JavaDoc children = nextKid.getChildNodes();
424         generatePropertyElement(jdbcResource, children);
425         resources.add(jdbcResource);
426         
427         //debug strings
428
printResourceElements(jdbcResource);
429     }
430     
431     /*
432      * Generate the Mail resource
433      */

434     private void generateMailResource(Node JavaDoc nextKid) throws Exception JavaDoc
435     {
436         NamedNodeMap JavaDoc attributes = nextKid.getAttributes();
437         if (attributes == null)
438             return;
439
440         Node JavaDoc jndiNameNode = attributes.getNamedItem(JNDI_NAME);
441         Node JavaDoc hostNode = attributes.getNamedItem(MAIL_HOST);
442         Node JavaDoc userNode = attributes.getNamedItem(MAIL_USER);
443         Node JavaDoc fromAddressNode = attributes.getNamedItem(MAIL_FROM_ADDRESS);
444         Node JavaDoc storeProtoNode = attributes.getNamedItem(MAIL_STORE_PROTO);
445         Node JavaDoc storeProtoClassNode = attributes.getNamedItem(MAIL_STORE_PROTO_CLASS);
446         Node JavaDoc transProtoNode = attributes.getNamedItem(MAIL_TRANS_PROTO);
447         Node JavaDoc transProtoClassNode = attributes.getNamedItem(MAIL_TRANS_PROTO_CLASS);
448         Node JavaDoc debugNode = attributes.getNamedItem(MAIL_DEBUG);
449         Node JavaDoc enabledNode = attributes.getNamedItem(ENABLED);
450
451         String JavaDoc jndiName = jndiNameNode.getNodeValue();
452         String JavaDoc host = hostNode.getNodeValue();
453         String JavaDoc user = userNode.getNodeValue();
454         String JavaDoc fromAddress = fromAddressNode.getNodeValue();
455         
456         Resource mailResource = new Resource(Resource.MAIL_RESOURCE);
457
458         mailResource.setAttribute(JNDI_NAME, jndiName);
459         mailResource.setAttribute(MAIL_HOST, host);
460         mailResource.setAttribute(MAIL_USER, user);
461         mailResource.setAttribute(MAIL_FROM_ADDRESS, fromAddress);
462         if (storeProtoNode != null) {
463            String JavaDoc sStoreProto = storeProtoNode.getNodeValue();
464            mailResource.setAttribute(MAIL_STORE_PROTO, sStoreProto);
465         }
466         if (storeProtoClassNode != null) {
467            String JavaDoc sStoreProtoClass = storeProtoClassNode.getNodeValue();
468            mailResource.setAttribute(MAIL_STORE_PROTO_CLASS, sStoreProtoClass);
469         }
470         if (transProtoNode != null) {
471            String JavaDoc sTransProto = transProtoNode.getNodeValue();
472            mailResource.setAttribute(MAIL_TRANS_PROTO, sTransProto);
473         }
474         if (transProtoClassNode != null) {
475            String JavaDoc sTransProtoClass = transProtoClassNode.getNodeValue();
476            mailResource.setAttribute(MAIL_TRANS_PROTO_CLASS, sTransProtoClass);
477         }
478         if (debugNode != null) {
479            String JavaDoc sDebug = debugNode.getNodeValue();
480            mailResource.setAttribute(MAIL_DEBUG, sDebug);
481         }
482         if (enabledNode != null) {
483            String JavaDoc sEnabled = enabledNode.getNodeValue();
484            mailResource.setAttribute(ENABLED, sEnabled);
485         }
486
487         NodeList JavaDoc children = nextKid.getChildNodes();
488         generatePropertyElement(mailResource, children);
489         resources.add(mailResource);
490         
491         //debug strings
492
printResourceElements(mailResource);
493     }
494     
495     /*
496      * Generate the Persistence Factory Manager resource
497      */

498     private void generatePersistenceResource(Node JavaDoc nextKid) throws Exception JavaDoc
499     {
500         NamedNodeMap JavaDoc attributes = nextKid.getAttributes();
501         if (attributes == null)
502             return;
503         
504         Node JavaDoc jndiNameNode = attributes.getNamedItem(JNDI_NAME);
505         String JavaDoc jndiName = jndiNameNode.getNodeValue();
506         Node JavaDoc factoryClassNode = attributes.getNamedItem(FACTORY_CLASS);
507         Node JavaDoc poolNameNode = attributes.getNamedItem(JDBC_RESOURCE_JNDI_NAME);
508         Node JavaDoc enabledNode = attributes.getNamedItem(ENABLED);
509
510         Resource persistenceResource =
511                     new Resource(Resource.PERSISTENCE_RESOURCE);
512         persistenceResource.setAttribute(JNDI_NAME, jndiName);
513         if (factoryClassNode != null) {
514            String JavaDoc factoryClass = factoryClassNode.getNodeValue();
515            persistenceResource.setAttribute(FACTORY_CLASS, factoryClass);
516         }
517         if (poolNameNode != null) {
518            String JavaDoc poolName = poolNameNode.getNodeValue();
519            persistenceResource.setAttribute(JDBC_RESOURCE_JNDI_NAME, poolName);
520         }
521         if (enabledNode != null) {
522            String JavaDoc sEnabled = enabledNode.getNodeValue();
523            persistenceResource.setAttribute(ENABLED, sEnabled);
524         }
525         
526         NodeList JavaDoc children = nextKid.getChildNodes();
527         generatePropertyElement(persistenceResource, children);
528         resources.add(persistenceResource);
529         
530         //debug strings
531
printResourceElements(persistenceResource);
532     }
533     
534     /*
535      * Generate the JMS resource
536      */

537     private void generateJMSResource(Node JavaDoc nextKid) throws Exception JavaDoc
538     {
539         NamedNodeMap JavaDoc attributes = nextKid.getAttributes();
540         if (attributes == null)
541             return;
542         
543         Node JavaDoc jndiNameNode = attributes.getNamedItem(JNDI_NAME);
544         String JavaDoc jndiName = jndiNameNode.getNodeValue();
545         Node JavaDoc resTypeNode = attributes.getNamedItem(RES_TYPE);
546         String JavaDoc resType = resTypeNode.getNodeValue();
547         Node JavaDoc enabledNode = attributes.getNamedItem(ENABLED);
548         
549         Resource jmsResource = new Resource(Resource.JMS_RESOURCE);
550         jmsResource.setAttribute(JNDI_NAME, jndiName);
551         jmsResource.setAttribute(RES_TYPE, resType);
552         if (enabledNode != null) {
553            String JavaDoc sEnabled = enabledNode.getNodeValue();
554            jmsResource.setAttribute(ENABLED, sEnabled);
555         }
556         
557         NodeList JavaDoc children = nextKid.getChildNodes();
558         generatePropertyElement(jmsResource, children);
559         resources.add(jmsResource);
560
561         //debug strings
562
printResourceElements(jmsResource);
563     }
564
565     private void generatePropertyElement(Resource rs, NodeList JavaDoc children) throws Exception JavaDoc
566     {
567        if (children != null) {
568            for (int ii=0; ii<children.getLength(); ii++) {
569               if (children.item(ii).getNodeName().equals("property")) {
570                  NamedNodeMap JavaDoc attNodeMap = children.item(ii).getAttributes();
571                  Node JavaDoc nameNode = attNodeMap.getNamedItem("name");
572                  Node JavaDoc valueNode = attNodeMap.getNamedItem("value");
573                  if (nameNode != null && valueNode != null) {
574                     boolean bDescFound = false;
575                     String JavaDoc sName = nameNode.getNodeValue();
576                     String JavaDoc sValue = valueNode.getNodeValue();
577                     //get property description
578
Node JavaDoc descNode = children.item(ii).getFirstChild();
579                     while (descNode != null && !bDescFound) {
580                        if (descNode.getNodeName().equalsIgnoreCase("description")) {
581                           try {
582                              rs.setElementProperty(sName, sValue, descNode.getFirstChild().getNodeValue());
583                              bDescFound = true;
584                           }
585                           catch (DOMException JavaDoc dome) {
586                              // DOM Error
587
throw new Exception JavaDoc(dome.getLocalizedMessage());
588                           }
589                        }
590                        descNode = descNode.getNextSibling();
591                     }
592                     if (!bDescFound) {
593                        rs.setElementProperty(sName, sValue);
594                     }
595                  }
596               }
597               if (children.item(ii).getNodeName().equals("description")) {
598                  rs.setDescription(children.item(ii).getFirstChild().getNodeValue());
599               }
600            }
601         }
602     }
603     
604     public Iterator JavaDoc getResources()
605     {
606         return resources.iterator();
607     }
608     
609     /*
610      * Print(Debug) the resource
611      */

612     private void printResourceElements(Resource resource)
613     {
614         Properties JavaDoc attributes = resource.getAttributes();
615         Enumeration JavaDoc properties = attributes.propertyNames();
616         while (properties.hasMoreElements())
617         {
618             String JavaDoc name = (String JavaDoc) properties.nextElement();
619             Logger JavaDoc logger = Logger.getLogger(AdminConstants.kLoggerName);
620             logger.log(Level.FINE, "general.print_attr_name", name);
621         }
622     }
623 }
624
625
Popular Tags