KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > kernel > Kernel


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;
23
24 import org.jboss.kernel.spi.config.KernelConfig;
25 import org.jboss.kernel.spi.config.KernelConfigurator;
26 import org.jboss.kernel.spi.dependency.KernelController;
27 import org.jboss.kernel.spi.event.KernelEventManager;
28 import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
29 import org.jboss.kernel.spi.registry.KernelBus;
30 import org.jboss.kernel.spi.registry.KernelRegistry;
31
32 /**
33  * The kernel.<p>
34  *
35  * The kernel is the entry point into the kernel services.
36  *
37  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
38  * @author <a HREF="mailto:les.hazlewood@jboss.org">Les A. Hazlewood</a>
39  * @version $Revision: 46188 $
40  */

41 public class Kernel
42 {
43    /** The permission required to access the kernel */
44    public static final KernelPermission ACCESS = new KernelPermission("access");
45    
46    /** The permission required to configure the kernel */
47    public static final KernelPermission CONFIGURE = new KernelPermission("configure");
48    
49    /** Whether kernel permission checking is active */
50    private static final boolean enablePermissionChecking;
51    
52    /** The kernel bus */
53    protected KernelBus bus;
54    
55    /** The kernel config */
56    protected KernelConfig config;
57    
58    /** The kernel configurator */
59    protected KernelConfigurator configurator;
60    
61    /** The kernel controller */
62    protected KernelController controller;
63    
64    /** The kernel event manager */
65    protected KernelEventManager eventManager;
66    
67    /** The kernel meta data repository */
68    protected KernelMetaDataRepository metaDataRepository;
69    
70    /** The kernel registry */
71    protected KernelRegistry registry;
72
73    static
74    {
75       boolean checkingEnabled = false;
76       try
77       {
78          
79          checkingEnabled = Boolean.getBoolean(KernelPermission.class.getName());
80       }
81       catch (Throwable JavaDoc ignored)
82       {
83       }
84       enablePermissionChecking = checkingEnabled;
85    }
86    
87    /**
88     * Check whether we can access the kernel
89     *
90     * @throws SecurityException if the you don't have KernelPermission('access')
91     */

92    public static void checkAccess()
93    {
94       if (enablePermissionChecking)
95       {
96          SecurityManager JavaDoc sm = System.getSecurityManager();
97          if (sm != null)
98             sm.checkPermission(ACCESS);
99       }
100    }
101    
102    /**
103     * Check whether we can configure the kernel
104     *
105     * @throws SecurityException if the you don't have KernelPermission('configure')
106     */

107    public static void checkConfigure()
108    {
109       if (enablePermissionChecking)
110       {
111          SecurityManager JavaDoc sm = System.getSecurityManager();
112          if (sm != null)
113             sm.checkPermission(CONFIGURE);
114       }
115    }
116
117    /**
118     * Get the kernel bus
119     *
120     * @return the kernel bus
121     * @throws SecurityException if the you don't have KernelPermission('access')
122     */

123    public KernelBus getBus()
124    {
125       checkAccess();
126       return bus;
127    }
128    
129    /**
130     * Set the kernel bus.<p>
131     *
132     * @param bus the kernel bus
133     * @throws SecurityException if the you don't have KernelPermission('configure')
134     */

135    public void setBus(KernelBus bus)
136    {
137       checkConfigure();
138       this.bus = bus;
139    }
140
141    /**
142     * Get the kernel config
143     *
144     * @return the kernel config
145     * @throws SecurityException if the you don't have KernelPermission('access')
146     */

147    public KernelConfig getConfig()
148    {
149       checkAccess();
150       return config;
151    }
152    
153    /**
154     * Set the kernel config.<p>
155     *
156     * @param config the kernel config
157     * @throws SecurityException if the you don't have KernelPermission('configure')
158     */

159    public void setConfig(KernelConfig config)
160    {
161       checkConfigure();
162       this.config = config;
163    }
164
165    /**
166     * Get the kernel configurator
167     *
168     * @return the kernel configurator
169     * @throws SecurityException if the you don't have KernelPermission('access')
170     */

171    public KernelConfigurator getConfigurator()
172    {
173       checkAccess();
174       return configurator;
175    }
176    
177    /**
178     * Set the kernel configurator.<p>
179     *
180     * @param configurator the kernel configurator
181     * @throws SecurityException if the you don't have KernelPermission('configure')
182     */

183    public void setConfigurator(KernelConfigurator configurator)
184    {
185       checkConfigure();
186       this.configurator = configurator;
187    }
188
189    /**
190     * Get the kernel controller
191     *
192     * @return the kernel controller
193     * @throws SecurityException if the you don't have KernelPermission('access')
194     */

195    public KernelController getController()
196    {
197       checkAccess();
198       return controller;
199    }
200    
201    /**
202     * Set the kernel controller.<p>
203     *
204     * @param controller the kernel controller
205     * @throws SecurityException if the you don't have KernelPermission('configure')
206     */

207    public void setController(KernelController controller)
208    {
209       checkConfigure();
210       this.controller = controller;
211    }
212
213    /**
214     * Get the event manager
215     *
216     * @return the event manager
217     * @throws SecurityException if the you don't have KernelPermission('access')
218     */

219    public KernelEventManager getEventManager()
220    {
221       checkAccess();
222       return eventManager;
223    }
224    
225    /**
226     * Set the event manager.
227     *
228     * @param eventManager the event manager
229     * @throws SecurityException if the you don't have KernelPermission('configure')
230     */

231    public void setEventManager(KernelEventManager eventManager)
232    {
233       checkConfigure();
234       this.eventManager = eventManager;
235    }
236
237    /**
238     * Get the kernel registry
239     *
240     * @return the kernel registry
241     * @throws SecurityException if the you don't have KernelPermission('access')
242     */

243    public KernelRegistry getRegistry()
244    {
245       checkAccess();
246       return registry;
247    }
248    
249    /**
250     * Set the kernel registry.<p>
251     *
252     * @param registry the kernel registry
253     * @throws SecurityException if the you don't have KernelPermission('configure')
254     */

255    public void setRegistry(KernelRegistry registry)
256    {
257       checkConfigure();
258       this.registry = registry;
259    }
260
261    /**
262     * Get the Meta Data Repository.
263     *
264     * @return the meta data repository.
265     * @throws SecurityException if the you don't have KernelPermission('access')
266     */

267    public KernelMetaDataRepository getMetaDataRepository()
268    {
269       checkAccess();
270       return metaDataRepository;
271    }
272
273    /**
274     * Set the meta data repository.
275     *
276     * @param metaDataRepository the meta data repository.
277     * @throws SecurityException if the you don't have KernelPermission('configure')
278     */

279    public void setMetaDataRepository(KernelMetaDataRepository metaDataRepository)
280    {
281       checkConfigure();
282       this.metaDataRepository = metaDataRepository;
283    }
284 }
285
Popular Tags