1 22 package org.jboss.system.deployers; 23 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 import org.jboss.deployers.plugins.deployers.helpers.JAXPDeployer; 29 import org.jboss.deployers.spi.DeploymentException; 30 import org.jboss.deployers.spi.deployer.DeploymentUnit; 31 import org.jboss.deployers.spi.structure.DeploymentContext; 32 import org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfig; 33 import org.jboss.system.metadata.ServiceDeployment; 34 import org.jboss.system.metadata.ServiceDeploymentClassPath; 35 import org.jboss.system.metadata.ServiceDeploymentParser; 36 import org.jboss.system.server.ServerConfig; 37 import org.jboss.system.server.ServerConfigLocator; 38 import org.jboss.virtual.VFS; 39 import org.jboss.virtual.VirtualFile; 40 import org.w3c.dom.Document ; 41 42 53 public class SARDeployer extends JAXPDeployer<ServiceDeployment> 54 { 55 60 public SARDeployer() 61 { 62 super(ServiceDeployment.class); 63 } 64 65 70 @Override 71 protected ServiceDeployment parse(DeploymentUnit unit, VirtualFile file, Document document) throws Exception 72 { 73 ServiceDeploymentParser parser = new ServiceDeploymentParser(document); 74 ServiceDeployment parsed = parser.parse(); 75 String name = file.toURI().toString(); 76 parsed.setName(name); 77 78 List <ServiceDeploymentClassPath> classPaths = parsed.getClassPaths(); 79 if (classPaths != null) 80 processXMLClasspath(unit.getDeploymentContext(), classPaths); 81 82 LoaderRepositoryConfig config = parsed.getLoaderRepositoryConfig(); 83 if (config != null) 84 unit.addAttachment(LoaderRepositoryConfig.class.getName(), config); 85 return parsed; 86 } 87 88 public void deploy(DeploymentUnit unit) throws DeploymentException 89 { 90 createMetaData(unit, null, "-service.xml"); 91 } 92 93 100 private void processXMLClasspath(DeploymentContext context, List <ServiceDeploymentClassPath> classpaths) throws Exception 101 { 102 ArrayList <VirtualFile> classpath = new ArrayList <VirtualFile>(); 103 104 for (ServiceDeploymentClassPath path : classpaths) 105 { 106 String codebase = path.getCodeBase(); 107 String archives = path.getArchives(); 108 109 log.debug("Processing classpath: " + context.getName() + " codebase=" + codebase + " archives=" + archives); 110 VirtualFile codebaseFile = context.getRoot(); 111 if (".".equals(codebase) == false) 112 { 113 ServerConfig config = ServerConfigLocator.locate(); 114 URL codeBaseURL = new URL (config.getServerHomeURL(), codebase); 115 codebaseFile = VFS.getVirtualFile(codeBaseURL, ""); 116 } 117 118 if (codebaseFile == null) 119 throw new DeploymentException("Cannot use classpath without a root: " + context.getName()); 120 121 if (archives == null) 122 { 123 classpath.add(codebaseFile); 124 log.debug("Using codebase as classpath: " + context.getName()); 125 } 126 else 127 { 128 SARArchiveFilter filter = new SARArchiveFilter(archives); 129 List <VirtualFile> archiveFiles = codebaseFile.getChildren(filter); 130 classpath.addAll(archiveFiles); 131 } 132 133 } 134 135 List <VirtualFile> origClassPath = context.getClassPath(); 136 if (origClassPath != null) 137 classpath.addAll(origClassPath); 138 context.setClassPath(classpath); 139 } 140 } 141 | Popular Tags |