FileDocCategorySizeDatePackage
ModulesXMLHelper.javaAPI DocGlassfish v2 API13957Fri May 04 22:33:56 BST 2007com.sun.enterprise.admin.server.core.mbean.config

ModulesXMLHelper

public class ModulesXMLHelper extends Object

Fields Summary
public static final int
MODULE_TYPE_EJB
public static final int
MODULE_TYPE_WEB
public static final int
MODULE_TYPE_JAVA
public static final int
MODULE_TYPE_ALL
public static final int
EJB_TYPE_SESSION
public static final int
EJB_TYPE_ENTITY
public static final int
EJB_TYPE_MSGDRIVEN
public static final int
EJB_TYPE_ALL
static final String
APPLICATION_TAG
static final String
MODULE_TAG
static final String
EJB_MODULE_TAG
static final String
WEB_MODULE_TAG
static final String
WEB_URI_TAG
static final String
CONTEXT_ROOT_TAG
static final String
JAVA_MODULE_TAG
static final String
ENTERPRISE_BEANS_TAG
static final String
SESSION_TAG
static final String
ENTITY_TAG
static final String
MESSAGE_DRIVEN_TAG
static final String
EJB_NAME_TAG
static final String
SERVLET_TAG
static final String
SERVLET_NAME_TAG
static final Logger
sLogger
Document
document
Constructors Summary
public ModulesXMLHelper(String fileName)

    
        
    
        document = createDocument(fileName);
    
Methods Summary
private voidaddToListEjbNames(java.util.ArrayList listToAdd, org.w3c.dom.Node listNode, java.lang.String tag)

        ArrayList arr = findChildNodesByName(listNode, tag);
        for (int i=0; i<arr.size(); i++)
        {
            Node nameNode = findChildNodeByName((Node)arr.get(i), EJB_NAME_TAG);
            listToAdd.add(getTextForNode(nameNode));
        }
    
private org.w3c.dom.DocumentcreateDocument(java.lang.String fileName)

        DocumentBuilderFactory factory =
        DocumentBuilderFactory.newInstance();
        Document document;
        try
        {
            DocumentBuilder builder = factory.newDocumentBuilder();
            EntityResolver resolver = new AdminEntityResolver();
            builder.setEntityResolver(resolver);
            document = builder.parse(new File(fileName));
        }
        catch (SAXException sxe)
        {
            // Error generated during parsing)
            Exception  x = sxe;
            if (sxe.getException() != null)
                x = sxe.getException();
            sLogger.throwing(getClass().getName(), "createDocument", x);
            throw new ControlException(x.getLocalizedMessage());
            
        }
        catch (ParserConfigurationException pce)
        {
            // Parser with specified options can't be built
            sLogger.throwing(getClass().getName(), "createDocument", pce);
            throw new ControlException(pce.getLocalizedMessage());
        }
        catch (IOException ioe)
        {
            // I/O error
            sLogger.throwing(getClass().getName(), "createDocument", ioe);
            throw new ControlException(ioe.getLocalizedMessage());
        }
        return document;
    
private org.w3c.dom.NodefindChildNodeByName(org.w3c.dom.Node node, java.lang.String name)

        for (node = node.getFirstChild(); node != null; node = node.getNextSibling())
        {
            if(node.getNodeName().equalsIgnoreCase(name))
                return node;
        }
        return null;
    
private java.util.ArrayListfindChildNodesByName(org.w3c.dom.Node node, java.lang.String name)

        ArrayList resNodes = new ArrayList();
        for (node = node.getFirstChild(); node != null; node = node.getNextSibling())
        {
            if(node.getNodeName().equalsIgnoreCase(name))
                resNodes.add(node);
        }
        return resNodes;
    
public java.lang.String[]getEnterpriseBeans(int ejbType)

        if (document != null)
        {
            Node beansListNode = findChildNodeByName(document.getDocumentElement(), ENTERPRISE_BEANS_TAG);
            if(beansListNode!=null)
            {
                ArrayList resList = new ArrayList();
                if((ejbType&EJB_TYPE_SESSION)!=0)
                    addToListEjbNames(resList, beansListNode, SESSION_TAG);
                if((ejbType&EJB_TYPE_SESSION)!=0)
                    addToListEjbNames(resList, beansListNode, ENTITY_TAG);
                if((ejbType&EJB_TYPE_SESSION)!=0)
                    addToListEjbNames(resList, beansListNode, MESSAGE_DRIVEN_TAG);
                String [] res = new String[resList.size()];
                for (int i=0; i<res.length; i++)
                {
                    res[i] = (String)(resList.get(i));
                }
                return res;
                //                return ((String[]) resList.toArray());
            }
        }
        return new String[0];
    
public static java.lang.String[]getEnterpriseBeansForEjbModule(java.lang.String location, java.lang.String ejbModuleName, int ejbTypes)

        if(ejbModuleName!=null)
        { //not standalone - add super directory
            if(ejbModuleName.endsWith(".jar"))
                ejbModuleName = ejbModuleName.substring(0, ejbModuleName.length()-4);
            location = location + "/" + ejbModuleName + "_jar";
        }
        ModulesXMLHelper myObj = new ModulesXMLHelper(location + "/META-INF/ejb-jar.xml");
        return myObj.getEnterpriseBeans(ejbTypes);
    
private java.lang.StringgetModuleNameFromNode(org.w3c.dom.Node node, int moduleType)

        ArrayList arr;
        if((moduleType&MODULE_TYPE_EJB)!=0 &&
        (arr=findChildNodesByName(node, EJB_MODULE_TAG)).size()>0)
            return  getTextForNode((Node)arr.get(0));
        if((moduleType&MODULE_TYPE_JAVA)!=0 &&
        (arr=findChildNodesByName(node, JAVA_MODULE_TAG)).size()>0)
            return  getTextForNode((Node)arr.get(0));
        if((moduleType&MODULE_TYPE_WEB)!=0 &&
        (arr=findChildNodesByName(node, WEB_MODULE_TAG)).size()>0)
        {
            node = (Node)arr.get(0);
            if((arr=findChildNodesByName(node, WEB_URI_TAG))!=null && 
                    arr.size()>0)
            {
                String desc =  getTextForNode((Node)arr.get(0));
                /*
                // desc = web-uri till now
                String contextRoot = "";
                // now get the context-root - this is helpful 
                arr = findChildNodesByName(node, CONTEXT_ROOT_TAG);
                if (arr != null && arr.size() > 0)
                {
                    contextRoot = getTextForNode((Node) arr.get(0));
                }
                if (contextRoot != null)
                {
                    desc = contextRoot + ":" + desc;
                }
                */
                return desc;
            }
        }
        return null;
    
public java.lang.String[]getModules(int moduleType)

        if (document != null)
        {
            ArrayList arr = findChildNodesByName(document.getDocumentElement(), MODULE_TAG);
            String [] strs = new String[arr.size()];
            int noNullCount = 0;
            for (int i=0; i<arr.size(); i++)
            {
                String str = getModuleNameFromNode((Node)arr.get(i), moduleType);
                if(str!=null)
                    strs[noNullCount++] = str;
            }
            String [] res = new String[noNullCount];
            for (int i=0; i<noNullCount; i++)
            {
                res[i] = strs[i];
            }
            return res;
        }
        return new String[0];
        
    
public static java.lang.String[]getModulesFromApplicationLocation(java.lang.String appLocation, int moduleType)

        ModulesXMLHelper myObj = new ModulesXMLHelper(appLocation + "/META-INF/application.xml");
        return myObj.getModules(moduleType);
    
public java.lang.String[]getServlets()

        if (document != null)
        {
            ArrayList arr = findChildNodesByName(document.getDocumentElement(), SERVLET_TAG);
            String [] res = new String[arr.size()];
            for (int i=0; i<arr.size(); i++)
            {
                Node nameNode = findChildNodeByName((Node)arr.get(i), SERVLET_NAME_TAG);
                res[i] = getTextForNode(nameNode);
            }
            return res;
        }
        return new String[0];
    
public static java.lang.String[]getServletsForWebModule(java.lang.String location, java.lang.String webModuleName)

        if(webModuleName!=null)
        { //not standalone - add super directory to appLocation
            if(webModuleName.endsWith(".war"))
                webModuleName = webModuleName.substring(0, webModuleName.length()-4);
            location = location + "/" + webModuleName + "_war";
        }
        ModulesXMLHelper myObj = new ModulesXMLHelper(location + "/WEB-INF/web.xml");
        return myObj.getServlets();
    
private java.lang.StringgetTextForNode(org.w3c.dom.Node node)

        for (node = node.getFirstChild(); node != null; node = node.getNextSibling())
        {
            if(node.getNodeType()==Node.TEXT_NODE)
                return node.getNodeValue();
        }
        return null;
    
public static booleanisModuleExists(java.lang.String appLocation, java.lang.String moduleName, int moduleType)

        String[] strs = getModulesFromApplicationLocation(appLocation, moduleType);
        if(strs!=null)
            for(int i=0; i<strs.length; i++)
                if(moduleName.equals(strs[i]))
                    return true;
        return false;