KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > kernel > deployment > jboss > JBossBeanDeployment


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.kernel.deployment.jboss;
23
24 import org.jboss.dependency.spi.ControllerMode;
25 import org.jboss.dependency.spi.ControllerState;
26 import org.jboss.deployment.DeploymentException;
27 import org.jboss.deployment.DeploymentInfo;
28 import org.jboss.kernel.Kernel;
29 import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
30 import org.jboss.kernel.plugins.deployment.AbstractKernelDeployer;
31 import org.jboss.kernel.spi.deployment.KernelDeployment;
32 import org.jboss.system.ServiceMBeanSupport;
33 import org.jboss.util.UnreachableStatementException;
34
35 /**
36  * A jboss bean deployment
37  *
38  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
39  * @version $Revision: 37459 $
40  */

41 public class JBossBeanDeployment extends ServiceMBeanSupport implements JBossBeanDeploymentMBean
42 {
43    /** The deployment info */
44    protected DeploymentInfo di;
45    
46    /** The deployment */
47    protected KernelDeployment deployment;
48
49    /** The kernel deployer */
50    protected AbstractKernelDeployer deployer;
51    
52    /**
53     * Create a new deployment
54     *
55     * @param di the deployment info
56     */

57    public JBossBeanDeployment(DeploymentInfo di)
58    {
59       this.di = di;
60       this.deployment = (KernelDeployment) di.metaData;
61    }
62    
63    protected void createService() throws Exception JavaDoc
64    {
65       Kernel kernel = getKernel();
66       deployer = new AbstractKernelDeployer(kernel, ControllerState.CREATE, ControllerMode.MANUAL);
67       try
68       {
69          deployer.deploy(deployment);
70       }
71       catch (Throwable JavaDoc t)
72       {
73          DeploymentException.rethrowAsDeploymentException("Cannot deploy " + deployment, t);
74       }
75    }
76    
77    protected void startService() throws Exception JavaDoc
78    {
79       try
80       {
81          deployer.change(deployment, ControllerState.INSTALLED);
82          deployer.validate(deployment);
83       }
84       catch (Throwable JavaDoc t)
85       {
86          DeploymentException.rethrowAsDeploymentException("Cannot start " + deployment, t);
87       }
88    }
89    
90    protected void stopService() throws Exception JavaDoc
91    {
92       try
93       {
94          deployer.change(deployment, ControllerState.CREATE);
95       }
96       catch (Throwable JavaDoc t)
97       {
98          DeploymentException.rethrowAsDeploymentException("Cannot stop " + deployment, t);
99       }
100    }
101    
102    protected void destroyService() throws Exception JavaDoc
103    {
104       try
105       {
106          if (deployer != null)
107             deployer.undeploy(deployment);
108       }
109       catch (Throwable JavaDoc t)
110       {
111          DeploymentException.rethrowAsDeploymentException("Cannot stop " + deployment, t);
112       }
113       deployer = null;
114    }
115    
116    /**
117     * Get the kernel for this deployment
118     *
119     * @return the kernel
120     */

121    protected Kernel getKernel() throws DeploymentException
122    {
123       try
124       {
125          BasicBootstrap bootstrap = new BasicBootstrap();
126          bootstrap.run();
127          return bootstrap.getKernel();
128       }
129       catch (Throwable JavaDoc t)
130       {
131          DeploymentException.rethrowAsDeploymentException("Unable to boot kernel", t);
132          throw new UnreachableStatementException();
133       }
134    }
135 }
136
Popular Tags