KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > Ejb3Module


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, 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.ejb3;
23
24 import java.util.Map JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26 import org.jboss.deployment.DeploymentInfo;
27 import org.jboss.system.ServiceMBeanSupport;
28 import org.jboss.logging.Logger;
29
30 /**
31  * An EjbModule represents a collection of beans that are deployed as a unit.
32  *
33  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
34  * @version $Revision: 57481 $
35  */

36 public class Ejb3Module extends ServiceMBeanSupport implements Ejb3ModuleMBean
37 {
38    public final static String JavaDoc BASE_EJB3_JMX_NAME = "jboss.j2ee:service=EJB3";
39    private static final Logger log = Logger.getLogger(Ejb3Module.class);
40
41    private Ejb3JmxDeployment deployment;
42    private DeploymentInfo di;
43
44     public Ejb3Module(DeploymentInfo di)
45     {
46        DeploymentScope deploymentScope = null;
47        if (di.parent != null)
48        {
49           if (di.parent.shortName.endsWith(".ear") || di.parent.shortName.endsWith(".ear/"))
50           {
51              synchronized(di.parent.context)
52              {
53                 deploymentScope = (DeploymentScope)di.parent.context.get("EJB3_EAR_METADATA");
54                 if (deploymentScope == null)
55                 {
56                    deploymentScope = new JmxDeploymentScopeImpl(di.parent.shortName);
57                    di.parent.context.put("EJB3_EAR_METADATA", deploymentScope);
58                 }
59              }
60           }
61        }
62        deployment = new Ejb3JmxDeployment(di, deploymentScope);
63        if (deploymentScope != null)
64        {
65           deploymentScope.register(deployment);
66        }
67        this.di = di;
68     }
69
70    protected void createService() throws Exception JavaDoc
71    {
72       super.createService();
73       ClassLoader JavaDoc old = Thread.currentThread().getContextClassLoader();
74       try
75       {
76          Thread.currentThread().setContextClassLoader(di.ucl);
77          deployment.create();
78       }
79       finally
80       {
81          Thread.currentThread().setContextClassLoader(old);
82       }
83    }
84
85    protected void startService() throws Exception JavaDoc
86    {
87       ClassLoader JavaDoc old = Thread.currentThread().getContextClassLoader();
88       try
89       {
90          Thread.currentThread().setContextClassLoader(di.ucl);
91          deployment.start();
92       }
93       finally
94       {
95          Thread.currentThread().setContextClassLoader(old);
96       }
97       super.startService();
98
99    }
100
101    protected void stopService() throws Exception JavaDoc
102    {
103       ClassLoader JavaDoc old = Thread.currentThread().getContextClassLoader();
104       try
105       {
106          Thread.currentThread().setContextClassLoader(di.ucl);
107          deployment.stop();
108       }
109       finally
110       {
111          Thread.currentThread().setContextClassLoader(old);
112       }
113       super.stopService();
114    }
115
116    protected void destroyService() throws Exception JavaDoc
117    {
118       ClassLoader JavaDoc old = Thread.currentThread().getContextClassLoader();
119       try
120       {
121          Thread.currentThread().setContextClassLoader(di.ucl);
122          deployment.destroy();
123       }
124       finally
125       {
126          Thread.currentThread().setContextClassLoader(old);
127       }
128       super.destroyService();
129    }
130
131    public Container getContainer(ObjectName JavaDoc name)
132    {
133       return deployment.getContainer(name);
134    }
135
136    public Map JavaDoc getContainers()
137    {
138       return deployment.getEjbContainers();
139    }
140 }
141
Popular Tags