KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > base > config > JNDIConfigUtil


1 /*
2  * $Id: JNDIConfigUtil.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.base.config;
26
27 import java.util.*;
28 import org.w3c.dom.*;
29
30 import org.ofbiz.base.util.*;
31
32 /**
33  * JNDIConfigUtil
34  *
35  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
36  * @version $Rev: 5462 $
37  * @since 2.0
38  */

39 public class JNDIConfigUtil {
40     
41     public static final String JavaDoc module = JNDIConfigUtil.class.getName();
42     public static final String JavaDoc JNDI_CONFIG_XML_FILENAME = "jndiservers.xml";
43     protected static Map jndiServerInfos = new HashMap();
44
45     protected static Element getXmlRootElement() throws GenericConfigException {
46         try {
47             return ResourceLoader.getXmlRootElement(JNDIConfigUtil.JNDI_CONFIG_XML_FILENAME);
48         } catch (GenericConfigException e) {
49             throw new GenericConfigException("Could not get JNDI XML root element", e);
50         }
51     }
52
53     protected static Document getXmlDocument() throws GenericConfigException {
54         try {
55             return ResourceLoader.getXmlDocument(JNDIConfigUtil.JNDI_CONFIG_XML_FILENAME);
56         } catch (GenericConfigException e) {
57             throw new GenericConfigException("Could not get JNDI XML document", e);
58         }
59     }
60
61     static {
62         try {
63             initialize(getXmlRootElement());
64         } catch (Exception JavaDoc e) {
65             Debug.logError(e, "Error loading JNDI config XML file " + JNDI_CONFIG_XML_FILENAME, module);
66         }
67     }
68     public static void initialize(Element rootElement) throws GenericConfigException {
69         List childElements = null;
70         Iterator elementIter = null;
71
72         // jndi-server - jndiServerInfos
73
childElements = UtilXml.childElementList(rootElement, "jndi-server");
74         elementIter = childElements.iterator();
75         while (elementIter.hasNext()) {
76             Element curElement = (Element) elementIter.next();
77             JNDIConfigUtil.JndiServerInfo jndiServerInfo = new JNDIConfigUtil.JndiServerInfo(curElement);
78
79             JNDIConfigUtil.jndiServerInfos.put(jndiServerInfo.name, jndiServerInfo);
80         }
81     }
82
83     public static JNDIConfigUtil.JndiServerInfo getJndiServerInfo(String JavaDoc name) {
84         return (JNDIConfigUtil.JndiServerInfo) jndiServerInfos.get(name);
85     }
86
87     public static class JndiServerInfo {
88         public String JavaDoc name;
89         public String JavaDoc contextProviderUrl;
90         public String JavaDoc initialContextFactory;
91         public String JavaDoc urlPkgPrefixes;
92         public String JavaDoc securityPrincipal;
93         public String JavaDoc securityCredentials;
94
95         public JndiServerInfo(Element element) {
96             this.name = element.getAttribute("name");
97             this.contextProviderUrl = element.getAttribute("context-provider-url");
98             this.initialContextFactory = element.getAttribute("initial-context-factory");
99             this.urlPkgPrefixes = element.getAttribute("url-pkg-prefixes");
100             this.securityPrincipal = element.getAttribute("security-principal");
101             this.securityCredentials = element.getAttribute("security-credentials");
102         }
103     }
104 }
105
Popular Tags