FileDocCategorySizeDatePackage
DomainXMLHelper.javaAPI DocGlassfish v2 API6122Fri May 04 22:34:44 BST 2007com.sun.enterprise.diagnostics.collect

DomainXMLHelper

public class DomainXMLHelper extends Object
A helper which reads/loads domain.xml and provides information such as list of confidential attributes.
author
Manisha Umbarje

Fields Summary
private Document
configDoc
private static final String
PASSWORD
private static final String
NAME
private static Logger
logger
private String
repositoryDir
Constructors Summary
public DomainXMLHelper(String repositoryDir)
Creates a new instance of DomainXMLHelper

           
       
        this.repositoryDir = repositoryDir;
    
Methods Summary
public java.lang.StringgetAttribute(org.w3c.dom.Element element, java.lang.String attrName)
Gets attribute value

param
element element
param
attrName name of attribute
return
value of attribute

        if(element != null) 
            return element.getAttribute(attrName); //old value was config-ref    
        return null;
    
public java.util.ListgetAttrs()

        if(configDoc == null)
            loadXML();
        ArrayList list = new ArrayList(5);
        XmlUtils.getAttributes(configDoc.getDocumentElement(),
            PASSWORD, list);
        return list;
    
public org.w3c.dom.ElementgetElement(java.lang.String tagName, java.lang.String elementName)
Returns specified xml node

param
tagName name of tag
param
elementName value of tag
return
element corresponding to combination of tagName and elementName

        if( tagName == null && elementName == null)
            return null;
        
	if (configDoc == null)
	    loadXML();

        NodeList list = configDoc.getDocumentElement().getElementsByTagName(tagName);
        if (list != null) {
            int length = list.getLength();
            Element element = null;
            for (int i = 0; i < length ; i++) {
                element = (Element) list.item(i);
                if(element.getAttribute(NAME).equals(elementName))
                    return element;
            }
        }// if (list != null)

	return null;
    
public org.w3c.dom.ElementgetElement(org.w3c.dom.Element element, java.lang.String tagName)
Assumes that there is only one child with given tag name

param
element element
param
tagName name of child element
return
first child matching the tagName

	NodeList list = element.getElementsByTagName(tagName);

	if (list != null) {
	    return (Element)list.item(0);
	}//if
	return null;
    
private voidloadXML()
Loads XML - domain.xml in local mode

	try {
	    String configFile = repositoryDir + 
                    Constants.DOMAIN_XML;
            String configDtdFile = DiagnosticServiceHelper.getInstallationRoot()+
                    Constants.DOMAIN_XML_DTD;
	    logger.log(Level.FINE,
                    "diagnostic-service.loadxml_configfile", configFile);
	    configDoc = XmlUtils.loadXML(configFile , configDtdFile);
            
	} catch (SAXException ex) {
	    logger.log(Level.SEVERE,
            	      "diagnostic-service.error_loading_xml",ex.getMessage());
	    throw new DiagnosticException (ex.getMessage());
	} catch (IOException ioe) {
	    logger.log(Level.SEVERE,
	          "diagnostic-service.error_loading_xml",ioe.getMessage());
	    throw new DiagnosticException (ioe.getMessage());
	} catch (ParserConfigurationException pce) {
	    logger.log(Level.SEVERE,
	          "diagnostic-service.error_loading_xml",pce.getMessage());
	    throw new DiagnosticException (pce.getMessage());
	}