1 23 24 25 package com.sun.enterprise.deployment.io; 26 27 import java.io.File ; 28 import javax.xml.parsers.*; 29 import org.w3c.dom.*; 30 31 import com.sun.enterprise.deployment.*; 32 import com.sun.enterprise.deployment.xml.*; 33 import com.sun.enterprise.deployment.node.SaxParserHandler; 34 import com.sun.enterprise.deployment.node.SaxParserHandlerFactory; 35 import javax.enterprise.deploy.shared.ModuleType ; 36 37 42 public class DeploymentDescriptorFileFactory { 43 44 45 private DeploymentDescriptorFileFactory() { 46 } 47 48 55 public static DeploymentDescriptorFile getDDFileFor(RootDeploymentDescriptor descriptor) { 56 if (descriptor instanceof Application) { 57 return new ApplicationDeploymentDescriptorFile(); 58 } 59 if (descriptor instanceof EjbBundleDescriptor) { 60 return new EjbDeploymentDescriptorFile(); 61 } 62 if (descriptor instanceof WebBundleDescriptor) { 63 return new WebDeploymentDescriptorFile(); 64 } 65 if (descriptor instanceof ConnectorDescriptor) { 66 return new ConnectorDeploymentDescriptorFile(); 67 } 68 if (descriptor instanceof ApplicationClientDescriptor) { 69 return new AppClientDeploymentDescriptorFile(); 70 } 71 return null; 72 } 73 74 81 public static DeploymentDescriptorFile getDDFileFor(ModuleType type) { 82 if (type==null) { 83 return null; 84 } 85 if (type.equals(ModuleType.EAR)) { 86 return new ApplicationDeploymentDescriptorFile(); 87 } 88 if (type.equals(ModuleType.EJB)) { 89 return new EjbDeploymentDescriptorFile(); 90 } 91 if (type.equals(ModuleType.WAR)) { 92 return new WebDeploymentDescriptorFile(); 93 } 94 if (type.equals(ModuleType.RAR)) { 95 return new ConnectorDeploymentDescriptorFile(); 96 } 97 if (type.equals(ModuleType.CAR)) { 98 return new AppClientDeploymentDescriptorFile(); 99 } 100 return null; 101 } 102 103 111 public static DeploymentDescriptorFile getDDFileFor(File xmlFile) 112 throws Exception { 113 114 118 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 119 factory.setValidating(false); 120 DocumentBuilder docBuilder = factory.newDocumentBuilder(); 121 docBuilder.setEntityResolver(SaxParserHandlerFactory.newInstance()); 122 Document document = docBuilder.parse(xmlFile); 123 Element element = document.getDocumentElement(); 124 if (element.getTagName().equals(ApplicationTagNames.APPLICATION)) { 125 return new ApplicationDeploymentDescriptorFile(); 126 } 127 if (element.getTagName().equals(EjbTagNames.EJB_BUNDLE_TAG)) { 128 return new EjbDeploymentDescriptorFile(); 129 } 130 if (element.getTagName().equals(WebTagNames.WEB_BUNDLE)) { 131 return new WebDeploymentDescriptorFile(); 132 } 133 if (element.getTagName().equals(ConnectorTagNames.CONNECTOR)) { 134 return new ConnectorDeploymentDescriptorFile(); 135 } 136 if (element.getTagName().equals(ApplicationClientTagNames.APPLICATION_CLIENT_TAG)) { 137 return new AppClientDeploymentDescriptorFile(); 138 } 139 if (element.getTagName().equals(PersistenceTagNames.PERSISTENCE)) { 140 return new PersistenceDeploymentDescriptorFile(); 141 } 142 return null; 143 } 144 } 145 | Popular Tags |