1 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 39 public class JNDIConfigUtil { 40 41 public static final String module = JNDIConfigUtil.class.getName(); 42 public static final String 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 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 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 name) { 84 return (JNDIConfigUtil.JndiServerInfo) jndiServerInfos.get(name); 85 } 86 87 public static class JndiServerInfo { 88 public String name; 89 public String contextProviderUrl; 90 public String initialContextFactory; 91 public String urlPkgPrefixes; 92 public String securityPrincipal; 93 public String 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 |