KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > deployers > EJBRegistrationDeployer


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, Red Hat Middleware LLC., 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.ejb3.deployers;
23
24 import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
25 import org.jboss.deployers.spi.deployer.DeploymentUnit;
26 import org.jboss.deployers.spi.DeploymentException;
27 import org.jboss.deployers.spi.structure.DeploymentContext;
28 import org.jboss.ejb3.DeploymentScope;
29 import org.jboss.ejb3.Ejb3Deployment;
30 import org.jboss.ejb3.EJB3Deployer;
31 import org.jboss.kernel.Kernel;
32 import org.jboss.virtual.VirtualFile;
33 import org.jboss.logging.Logger;
34
35 import javax.management.MBeanServer JavaDoc;
36 import java.util.HashSet JavaDoc;
37 import java.util.Properties JavaDoc;
38 import java.util.List JavaDoc;
39
40 /**
41  * Creates initial EJB deployments and initializes only basic metadata.
42  * A registration process is required so that
43  *
44  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
45  * @version $Revision: 57082 $
46  */

47 public class EJBRegistrationDeployer extends AbstractSimpleDeployer
48 {
49    private static final Logger log = Logger.getLogger(EJBRegistrationDeployer.class);
50
51    private HashSet JavaDoc ignoredJarsSet;
52    private MBeanServer JavaDoc mbeanServer;
53    private Kernel kernel;
54    private Properties JavaDoc defaultPersistenceProperties;
55    private List JavaDoc<String JavaDoc> allowedSuffixes;
56
57    public List JavaDoc<String JavaDoc> getAllowedSuffixes()
58    {
59       return allowedSuffixes;
60    }
61
62    public void setAllowedSuffixes(List JavaDoc<String JavaDoc> allowedSuffixes)
63    {
64       this.allowedSuffixes = allowedSuffixes;
65    }
66
67    public HashSet JavaDoc getIgnoredJarsSet()
68    {
69       return ignoredJarsSet;
70    }
71
72    public void setIgnoredJarsSet(HashSet JavaDoc ignoredJarsSet)
73    {
74       this.ignoredJarsSet = ignoredJarsSet;
75    }
76
77    public MBeanServer JavaDoc getMbeanServer()
78    {
79       return mbeanServer;
80    }
81
82    public void setMbeanServer(MBeanServer JavaDoc mbeanServer)
83    {
84       this.mbeanServer = mbeanServer;
85    }
86
87    public Kernel getKernel()
88    {
89       return kernel;
90    }
91
92    public void setKernel(Kernel kernel)
93    {
94       this.kernel = kernel;
95    }
96
97    public Properties JavaDoc getDefaultPersistenceProperties()
98    {
99       return defaultPersistenceProperties;
100    }
101
102    public void setDefaultPersistenceProperties(Properties JavaDoc defaultPersistenceProperties)
103    {
104       this.defaultPersistenceProperties = defaultPersistenceProperties;
105    }
106
107    public void deploy(DeploymentUnit unit) throws DeploymentException
108    {
109       try
110       {
111          if (unit.getDeploymentContext().isComponent()) return;
112          VirtualFile jar = unit.getDeploymentContext().getRoot();
113          if (jar.isLeaf() || ignoredJarsSet.contains(jar.getName()) )
114          {
115             log.trace("EJBRegistrationDeployer ignoring: " + jar.getName());
116             return;
117          }
118          if (allowedSuffixes != null)
119          {
120             for (String JavaDoc suffix : allowedSuffixes)
121             {
122                if (jar.getName().endsWith(suffix))
123                {
124                   log.trace("EJBRegistrationDeployer ignoring: " + jar.getName());
125                   return;
126                }
127             }
128          }
129          log.debug("********* EJBRegistrationDepoyer Begin Unit: " + unit.getName() + " jar: " + jar.getName());
130          VirtualFile ejbjar = unit.getMetaDataFile("ejb-jar.xml");
131          if (ejbjar != null)
132          {
133             if (!EJB3Deployer.has30EjbJarXml(ejbjar.openStream())) return;
134          }
135          DeploymentScope scope = null;
136          DeploymentContext parent = unit.getDeploymentContext().getParent();
137          if (parent != null && parent.getRoot().getName().endsWith(".ear")) // todo should look for metadata instead of ".ear"
138
{
139             scope = parent.getTransientAttachments().getAttachment(DeploymentScope.class);
140             if (scope == null)
141             {
142                scope = new JBoss5DeploymentScope(unit.getDeploymentContext().getParent());
143                parent.getTransientAttachments().addAttachment(DeploymentScope.class, scope);
144             }
145          }
146          JBoss5DeploymentUnit du = new JBoss5DeploymentUnit(unit);
147          du.setDefaultPersistenceProperties(defaultPersistenceProperties);
148          Ejb3JBoss5Deployment deployment = new Ejb3JBoss5Deployment(du, kernel, mbeanServer, unit, scope);
149          if (scope != null) scope.register(deployment);
150          // create() creates initial EJB containers and initializes metadata.
151
deployment.create();
152          if (deployment.getEjbContainers().size() == 0 && deployment.getPersistenceUnitDeployments().size() == 0)
153          {
154             log.trace("EJBRegistrationDeployer no containers in scanned jar, consider adding it to the ignore list: " + jar.getName() + " url: " + jar.toURL() + " unit: " + unit.getName());
155             return;
156          }
157          unit.addAttachment(Ejb3Deployment.class, deployment);
158       }
159       catch (Exception JavaDoc e)
160       {
161          throw new DeploymentException(e);
162       }
163    }
164
165    public void undeploy(DeploymentUnit unit)
166    {
167       Ejb3Deployment deployment = unit.getAttachment(Ejb3Deployment.class);
168       if (deployment == null) return;
169       try
170       {
171          deployment.stop();
172       }
173       catch (Exception JavaDoc e)
174       {
175          log.error("failed to stop deployment", e);
176       }
177       try
178       {
179          deployment.destroy();
180       }
181       catch (Exception JavaDoc e)
182       {
183          log.error("failed to destroy deployment", e);
184       }
185    }
186
187 }
188
Popular Tags