KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > kernel > plugins > bootstrap > basic > BasicBootstrap


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.basic;
23
24 import org.jboss.kernel.plugins.bootstrap.AbstractBootstrap;
25 import org.jboss.kernel.plugins.config.property.PropertyKernelConfig;
26 import org.jboss.kernel.spi.config.KernelConfig;
27
28 import java.security.AccessController JavaDoc;
29 import java.security.PrivilegedAction JavaDoc;
30 import java.util.Properties JavaDoc;
31
32 /**
33  * Bootstrap the kernel.
34  *
35  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
36  * @author <a HREF="mailto:les.hazlewood@jboss.org">Les A. Hazlewood</a>
37  * @version $Revision: 45764 $
38  */

39 public class BasicBootstrap extends AbstractBootstrap
40 {
41    /**
42     * Bootstrap the kernel from the command line
43     *
44     * @param args the command line arguments
45     * @throws Exception for any error
46     */

47    public static void main(String JavaDoc[] args) throws Exception JavaDoc
48    {
49       BasicBootstrap bootstrap = new BasicBootstrap();
50       bootstrap.run();
51    }
52
53    /**
54     * Constructs a new Bootstrap which constructs a Kernel based on
55     * the system properties.
56     */

57    public BasicBootstrap()
58    {
59       Properties JavaDoc props = getConfigProperties();
60       if (props == null)
61          props = getSystemProperties();
62       final PropertyKernelConfig config = new PropertyKernelConfig(props);
63       PrivilegedAction JavaDoc<?> action = new PrivilegedAction JavaDoc()
64       {
65          public Object JavaDoc run()
66          {
67             setConfig(config);
68             return null;
69          }
70       };
71       AccessController.doPrivileged(action);
72    }
73
74    /**
75     * Constructs a new Bootstrap which constructs a Kernel based
76     *
77     * @param config the configure
78     * @throws Exception for any error
79     */

80    public BasicBootstrap(final KernelConfig config) throws Exception JavaDoc
81    {
82       PrivilegedAction JavaDoc<?> action = new PrivilegedAction JavaDoc()
83       {
84          public Object JavaDoc run()
85          {
86             setConfig(config);
87             return null;
88          }
89       };
90       AccessController.doPrivileged(action);
91    }
92    
93    /**
94     * Load bootstrap specific properties
95     *
96     * @return the bootstrap specific properties
97     */

98    protected Properties JavaDoc getConfigProperties()
99    {
100       return null;
101    }
102    
103    private Properties JavaDoc getSystemProperties()
104    {
105       if (System.getSecurityManager() == null)
106          return System.getProperties();
107       else
108       {
109          return AccessController.doPrivileged(GetSystemProperties.instance);
110       }
111    }
112    
113    private static class GetSystemProperties implements PrivilegedAction JavaDoc<Properties JavaDoc>
114    {
115       private static GetSystemProperties instance = new GetSystemProperties();
116       
117       public Properties JavaDoc run()
118       {
119          return System.getProperties();
120       }
121    }
122 }
123
Popular Tags