001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.base.config;
019:
020: import java.util.*;
021: import org.w3c.dom.*;
022:
023: import org.ofbiz.base.util.*;
024:
025: /**
026: * JNDIConfigUtil
027: *
028: */
029: public class JNDIConfigUtil {
030:
031: public static final String module = JNDIConfigUtil.class.getName();
032: public static final String JNDI_CONFIG_XML_FILENAME = "jndiservers.xml";
033: protected static Map jndiServerInfos = new HashMap();
034:
035: protected static Element getXmlRootElement()
036: throws GenericConfigException {
037: try {
038: return ResourceLoader
039: .getXmlRootElement(JNDIConfigUtil.JNDI_CONFIG_XML_FILENAME);
040: } catch (GenericConfigException e) {
041: throw new GenericConfigException(
042: "Could not get JNDI XML root element", e);
043: }
044: }
045:
046: protected static Document getXmlDocument()
047: throws GenericConfigException {
048: try {
049: return ResourceLoader
050: .getXmlDocument(JNDIConfigUtil.JNDI_CONFIG_XML_FILENAME);
051: } catch (GenericConfigException e) {
052: throw new GenericConfigException(
053: "Could not get JNDI XML document", e);
054: }
055: }
056:
057: static {
058: try {
059: initialize(getXmlRootElement());
060: } catch (Exception e) {
061: Debug.logError(e, "Error loading JNDI config XML file "
062: + JNDI_CONFIG_XML_FILENAME, module);
063: }
064: }
065:
066: public static void initialize(Element rootElement)
067: throws GenericConfigException {
068: List childElements = null;
069: Iterator elementIter = null;
070:
071: // jndi-server - jndiServerInfos
072: childElements = UtilXml.childElementList(rootElement,
073: "jndi-server");
074: elementIter = childElements.iterator();
075: while (elementIter.hasNext()) {
076: Element curElement = (Element) elementIter.next();
077: JNDIConfigUtil.JndiServerInfo jndiServerInfo = new JNDIConfigUtil.JndiServerInfo(
078: curElement);
079:
080: JNDIConfigUtil.jndiServerInfos.put(jndiServerInfo.name,
081: jndiServerInfo);
082: }
083: }
084:
085: public static JNDIConfigUtil.JndiServerInfo getJndiServerInfo(
086: String name) {
087: return (JNDIConfigUtil.JndiServerInfo) jndiServerInfos
088: .get(name);
089: }
090:
091: public static class JndiServerInfo {
092: public String name;
093: public String contextProviderUrl;
094: public String initialContextFactory;
095: public String urlPkgPrefixes;
096: public String securityPrincipal;
097: public String securityCredentials;
098:
099: public JndiServerInfo(Element element) {
100: this .name = element.getAttribute("name");
101: this .contextProviderUrl = element
102: .getAttribute("context-provider-url");
103: this .initialContextFactory = element
104: .getAttribute("initial-context-factory");
105: this .urlPkgPrefixes = element
106: .getAttribute("url-pkg-prefixes");
107: this .securityPrincipal = element
108: .getAttribute("security-principal");
109: this .securityCredentials = element
110: .getAttribute("security-credentials");
111: }
112: }
113: }
|