1 23 package com.sun.enterprise.diagnostics.collect; 24 25 import com.sun.enterprise.diagnostics.util.DiagnosticServiceHelper; 26 import com.sun.enterprise.diagnostics.util.XmlUtils; 27 import org.w3c.dom.*; 28 import java.util.List ; 29 import java.util.ArrayList ; 30 import java.io.IOException ; 31 import javax.xml.parsers.ParserConfigurationException ; 32 import org.xml.sax.SAXException ; 33 import java.util.logging.Level ; 34 import java.util.logging.Logger ; 35 import com.sun.logging.LogDomains; 36 import com.sun.enterprise.diagnostics.*; 37 42 public class DomainXMLHelper { 43 44 private Document configDoc; 45 private static final String PASSWORD = "password"; 46 private static final String NAME = "name"; 47 private static Logger logger = 48 LogDomains.getLogger(LogDomains.ADMIN_LOGGER); 49 50 private String repositoryDir; 51 52 public DomainXMLHelper(String repositoryDir) { 53 this.repositoryDir = repositoryDir; 54 } 55 56 public List <String > getAttrs() throws DiagnosticException { 57 if(configDoc == null) 58 loadXML(); 59 ArrayList list = new ArrayList (5); 60 XmlUtils.getAttributes(configDoc.getDocumentElement(), 61 PASSWORD, list); 62 return list; 63 } 64 65 68 private void loadXML() throws DiagnosticException { 69 try { 70 String configFile = repositoryDir + 71 Constants.DOMAIN_XML; 72 String configDtdFile = DiagnosticServiceHelper.getInstallationRoot()+ 73 Constants.DOMAIN_XML_DTD; 74 logger.log(Level.FINE, 75 "diagnostic-service.loadxml_configfile", configFile); 76 configDoc = XmlUtils.loadXML(configFile , configDtdFile); 77 78 } catch (SAXException ex) { 79 logger.log(Level.SEVERE, 80 "diagnostic-service.error_loading_xml",ex.getMessage()); 81 throw new DiagnosticException (ex.getMessage()); 82 } catch (IOException ioe) { 83 logger.log(Level.SEVERE, 84 "diagnostic-service.error_loading_xml",ioe.getMessage()); 85 throw new DiagnosticException (ioe.getMessage()); 86 } catch (ParserConfigurationException pce) { 87 logger.log(Level.SEVERE, 88 "diagnostic-service.error_loading_xml",pce.getMessage()); 89 throw new DiagnosticException (pce.getMessage()); 90 } 91 92 } 93 99 public Element getElement(String tagName, String elementName) 100 throws DiagnosticException { 101 if( tagName == null && elementName == null) 102 return null; 103 104 if (configDoc == null) 105 loadXML(); 106 107 NodeList list = configDoc.getDocumentElement().getElementsByTagName(tagName); 108 if (list != null) { 109 int length = list.getLength(); 110 Element element = null; 111 for (int i = 0; i < length ; i++) { 112 element = (Element) list.item(i); 113 if(element.getAttribute(NAME).equals(elementName)) 114 return element; 115 } 116 } 118 return null; 119 } 121 127 public Element getElement(Element element, String tagName) { 128 NodeList list = element.getElementsByTagName(tagName); 129 130 if (list != null) { 131 return (Element)list.item(0); 132 } return null; 134 } 136 142 public String getAttribute(Element element , String attrName) { 143 if(element != null) 144 return element.getAttribute(attrName); return null; 146 } 147 148 } 149 | Popular Tags |