KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > kernel > plugins > bootstrap > standalone > StandaloneBootstrap


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.plugins.bootstrap.standalone;
23
24 import java.net.URL JavaDoc;
25 import java.util.Enumeration JavaDoc;
26
27 import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
28 import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
29
30 /**
31  * Standalone Bootstrap of the kernel.
32  *
33  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
34  * @author <a HREF="mailto:les.hazlewood@jboss.org">Les A. Hazlewood</a>
35  * @version $Revision: 40838 $
36  */

37 public class StandaloneBootstrap extends BasicBootstrap
38 {
39    /** The deployer */
40    protected BasicXMLDeployer deployer;
41    
42    /** The arguments */
43    protected String JavaDoc[] args;
44    
45    /**
46     * Bootstrap the kernel from the command line
47     *
48     * @param args the command line arguments
49     * @throws Exception for any error
50     */

51    public static void main(String JavaDoc[] args) throws Exception JavaDoc
52    {
53       StandaloneBootstrap bootstrap = new StandaloneBootstrap(args);
54       bootstrap.run();
55    }
56
57    /**
58     * Create a new bootstrap
59     *
60     * @param args the arguments
61     * @throws Exception for any error
62     */

63    public StandaloneBootstrap(String JavaDoc[] args) throws Exception JavaDoc
64    {
65       super();
66       this.args = args;
67    }
68    
69    public void bootstrap() throws Throwable JavaDoc
70    {
71       super.bootstrap();
72       
73       deployer = new BasicXMLDeployer(getKernel());
74       
75       Runtime.getRuntime().addShutdownHook(new Shutdown JavaDoc());
76       
77       ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
78       for (Enumeration JavaDoc e = cl.getResources(StandaloneKernelConstants.DEPLOYMENT_XML_NAME); e.hasMoreElements(); )
79       {
80          URL JavaDoc url = (URL JavaDoc) e.nextElement();
81          deploy(url);
82       }
83       for (Enumeration JavaDoc e = cl.getResources("META-INF/" + StandaloneKernelConstants.DEPLOYMENT_XML_NAME); e.hasMoreElements(); )
84       {
85          URL JavaDoc url = (URL JavaDoc) e.nextElement();
86          deploy(url);
87       }
88       
89       // Validate that everything is ok
90
deployer.validate();
91    }
92    
93    /**
94     * Deploy a url
95     *
96     * @param url the deployment url
97     * @throws Throwable for any error
98     */

99    protected void deploy(URL JavaDoc url) throws Throwable JavaDoc
100    {
101       deployer.deploy(url);
102    }
103    
104    /**
105     * Undeploy a url
106     *
107     * @param url the deployment url
108     */

109    protected void undeploy(URL JavaDoc url)
110    {
111       try
112       {
113          deployer.undeploy(url);
114       }
115       catch (Throwable JavaDoc t)
116       {
117          log.warn("Error during undeployment: " + url, t);
118       }
119    }
120    
121    protected class Shutdown extends Thread JavaDoc
122    {
123       public void run()
124       {
125          log.info("Shutting down");
126          deployer.shutdown();
127       }
128    }
129 }
130
Popular Tags