001: /*
002: * $Id: JNDIConfigUtil.java,v 1.1 2003/08/15 20:23:20 ajzeneski Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: */
025: package org.ofbiz.base.config;
026:
027: import java.util.*;
028: import org.w3c.dom.*;
029:
030: import org.ofbiz.base.util.*;
031:
032: /**
033: * JNDIConfigUtil
034: *
035: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
036: * @version $Revision: 1.1 $
037: * @since 2.0
038: */
039: public class JNDIConfigUtil {
040:
041: public static final String module = JNDIConfigUtil.class.getName();
042: public static final String JNDI_CONFIG_XML_FILENAME = "jndiservers.xml";
043: protected static Map jndiServerInfos = new HashMap();
044:
045: protected static Element getXmlRootElement()
046: throws GenericConfigException {
047: try {
048: return ResourceLoader
049: .getXmlRootElement(JNDIConfigUtil.JNDI_CONFIG_XML_FILENAME);
050: } catch (GenericConfigException e) {
051: throw new GenericConfigException(
052: "Could not get JNDI XML root element", e);
053: }
054: }
055:
056: protected static Document getXmlDocument()
057: throws GenericConfigException {
058: try {
059: return ResourceLoader
060: .getXmlDocument(JNDIConfigUtil.JNDI_CONFIG_XML_FILENAME);
061: } catch (GenericConfigException e) {
062: throw new GenericConfigException(
063: "Could not get JNDI XML document", e);
064: }
065: }
066:
067: static {
068: try {
069: initialize(getXmlRootElement());
070: } catch (Exception e) {
071: Debug.logError(e, "Error loading JNDI config XML file "
072: + JNDI_CONFIG_XML_FILENAME, module);
073: }
074: }
075:
076: public static void initialize(Element rootElement)
077: throws GenericConfigException {
078: List childElements = null;
079: Iterator elementIter = null;
080:
081: // jndi-server - jndiServerInfos
082: childElements = UtilXml.childElementList(rootElement,
083: "jndi-server");
084: elementIter = childElements.iterator();
085: while (elementIter.hasNext()) {
086: Element curElement = (Element) elementIter.next();
087: JNDIConfigUtil.JndiServerInfo jndiServerInfo = new JNDIConfigUtil.JndiServerInfo(
088: curElement);
089:
090: JNDIConfigUtil.jndiServerInfos.put(jndiServerInfo.name,
091: jndiServerInfo);
092: }
093: }
094:
095: public static JNDIConfigUtil.JndiServerInfo getJndiServerInfo(
096: String name) {
097: return (JNDIConfigUtil.JndiServerInfo) jndiServerInfos
098: .get(name);
099: }
100:
101: public static class JndiServerInfo {
102: public String name;
103: public String contextProviderUrl;
104: public String initialContextFactory;
105: public String urlPkgPrefixes;
106: public String securityPrincipal;
107: public String securityCredentials;
108:
109: public JndiServerInfo(Element element) {
110: this .name = element.getAttribute("name");
111: this .contextProviderUrl = element
112: .getAttribute("context-provider-url");
113: this .initialContextFactory = element
114: .getAttribute("initial-context-factory");
115: this .urlPkgPrefixes = element
116: .getAttribute("url-pkg-prefixes");
117: this .securityPrincipal = element
118: .getAttribute("security-principal");
119: this .securityCredentials = element
120: .getAttribute("security-credentials");
121: }
122: }
123: }
|