KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > system > deployers > SARDeployer


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.system.deployers;
23
24 import java.net.URL JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
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 JavaDoc;
41
42 /**
43  * SARDeployer.<p>
44  *
45  * This deployer is responsible for looking for -service.xml
46  * and creating the metadata object.<p>
47  *
48  * The {@link ServiceClassLoaderDeployer} and {@link ServiceDeployer} does the real work of deployment.
49  *
50  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
51  * @version $Revision: 1.1 $
52  */

53 public class SARDeployer extends JAXPDeployer<ServiceDeployment>
54 {
55    /**
56     * Create a new SARDeployer.
57     *
58     * @throws IllegalArgumentException for a null kernel
59     */

60    public SARDeployer()
61    {
62       super(ServiceDeployment.class);
63    }
64
65    /**
66     * @param unit - the deployment unit
67     * @param file - the vf for the jboss-service.xml descriptor
68     * @param document - the jaxp document for the jboss-service.xml descriptor
69     */

70    @Override JavaDoc
71    protected ServiceDeployment parse(DeploymentUnit unit, VirtualFile file, Document JavaDoc document) throws Exception JavaDoc
72    {
73       ServiceDeploymentParser parser = new ServiceDeploymentParser(document);
74       ServiceDeployment parsed = parser.parse();
75       String JavaDoc name = file.toURI().toString();
76       parsed.setName(name);
77
78       List JavaDoc<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    /**
94     * Process the xml classpath
95     *
96     * @param context the context
97     * @param classpaths the classpaths
98     * @throws Exception for any error
99     */

100    private void processXMLClasspath(DeploymentContext context, List JavaDoc<ServiceDeploymentClassPath> classpaths) throws Exception JavaDoc
101    {
102       ArrayList JavaDoc<VirtualFile> classpath = new ArrayList JavaDoc<VirtualFile>();
103
104       for (ServiceDeploymentClassPath path : classpaths)
105       {
106          String JavaDoc codebase = path.getCodeBase();
107          String JavaDoc 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 JavaDoc codeBaseURL = new URL JavaDoc(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 JavaDoc<VirtualFile> archiveFiles = codebaseFile.getChildren(filter);
130             classpath.addAll(archiveFiles);
131          }
132
133       }
134
135       List JavaDoc<VirtualFile> origClassPath = context.getClassPath();
136       if (origClassPath != null)
137          classpath.addAll(origClassPath);
138       context.setClassPath(classpath);
139    }
140 }
141
Popular Tags