FileDocCategorySizeDatePackage
DeploymentDescriptorFileFactory.javaAPI DocGlassfish v2 API6691Mon Jul 02 09:41:02 BST 2007com.sun.enterprise.deployment.io

DeploymentDescriptorFileFactory

public class DeploymentDescriptorFileFactory extends Object
Factory for DeploymentDescriptorFile implementations
author
Jerome Dochez

Fields Summary
Constructors Summary
private DeploymentDescriptorFileFactory()
no instance necessary for this factory

    
Methods Summary
public static DeploymentDescriptorFilegetDDFileFor(RootDeploymentDescriptor descriptor)
Creates and return an appropriate DeploymentDescriptorFile capable of handling the passed descriptor

param
descriptor used to identify the associated DeploymentDescriptorFile
return
the created DeploymentDescriptorFile

        if (descriptor instanceof Application) {
            return new ApplicationDeploymentDescriptorFile();
        }
        if (descriptor instanceof EjbBundleDescriptor) {
            return new EjbDeploymentDescriptorFile();
        }
        if (descriptor instanceof WebBundleDescriptor) {
            return new WebDeploymentDescriptorFile();
        }
        if (descriptor instanceof ConnectorDescriptor) {
            return new ConnectorDeploymentDescriptorFile();
        } 
        if (descriptor instanceof ApplicationClientDescriptor) {
            return new AppClientDeploymentDescriptorFile();
        }
        return null;
    
public static DeploymentDescriptorFilegetDDFileFor(javax.enterprise.deploy.shared.ModuleType type)
Creates and return an appropriate DeploymentDescriptorFile capable of handling the passed descriptor

param
descriptor used to identify the associated DeploymentDescriptorFile
return
the created DeploymentDescriptorFile

        if (type==null) {
            return null;
        }
        if (type.equals(ModuleType.EAR)) {
            return new ApplicationDeploymentDescriptorFile();
        }
        if (type.equals(ModuleType.EJB)) {
            return new EjbDeploymentDescriptorFile();
        }
        if (type.equals(ModuleType.WAR)) {
            return new WebDeploymentDescriptorFile();
        }
        if (type.equals(ModuleType.RAR)) {
            return new ConnectorDeploymentDescriptorFile();
        } 
        if (type.equals(ModuleType.CAR)) {
            return new AppClientDeploymentDescriptorFile();
        }
        return null;
    
public static DeploymentDescriptorFilegetDDFileFor(java.io.File xmlFile)
Creates and return the appropriate DeploymentDescriptorFile depending on the XML file passed.

param
input xml file
return
the DeploymentDescriptorFile responsible for handling the xml file

            
        // this is higly unefficient but we read the xml file as a DOM
        // tree, figure out the top xml element name and return the 
        // appropriate DeploymentDescriptorFile
        
        // always use system default to parse DD
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        System.clearProperty("javax.xml.parsers.DocumentBuilderFactory");

        factory.setValidating(false);
        DocumentBuilder docBuilder = factory.newDocumentBuilder();
        docBuilder.setEntityResolver(SaxParserHandlerFactory.newInstance());
        Document document = docBuilder.parse(xmlFile);
        Element element = document.getDocumentElement();
        if (element.getTagName().equals(ApplicationTagNames.APPLICATION)) {
            return new ApplicationDeploymentDescriptorFile();
        }
        if (element.getTagName().equals(EjbTagNames.EJB_BUNDLE_TAG)) {
            return new EjbDeploymentDescriptorFile();
        }
        if (element.getTagName().equals(WebTagNames.WEB_BUNDLE)) {
            return new WebDeploymentDescriptorFile();
        }
        if (element.getTagName().equals(ConnectorTagNames.CONNECTOR)) {
            return new ConnectorDeploymentDescriptorFile();
        } 
        if (element.getTagName().equals(ApplicationClientTagNames.APPLICATION_CLIENT_TAG)) {
            return new AppClientDeploymentDescriptorFile();
        }
        if (element.getTagName().equals(PersistenceTagNames.PERSISTENCE)) {
            return new PersistenceDeploymentDescriptorFile();
        }
        return null;