01: /*
02: * JFox - The most lightweight Java EE Application Server!
03: * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
04: *
05: * JFox is licenced and re-distributable under GNU LGPL.
06: */
07: package org.jfox.framework.component;
08:
09: import java.net.URL;
10: import java.net.URLClassLoader;
11:
12: import org.jfox.ejb3.EJBContainer;
13: import org.jfox.entity.EntityManagerFactoryBuilder;
14: import org.jfox.framework.Framework;
15: import org.jfox.webservice.WSContainer;
16:
17: /**
18: * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
19: */
20: public class SystemModule extends Module {
21:
22: public static final String name = "__SYSTEM_MODULE__";
23:
24: public SystemModule(Framework framework)
25: throws ModuleResolvedFailedException {
26: super (framework, null);
27: }
28:
29: protected ModuleClassLoader initModuleClassLoader() {
30: // 覆盖 getResource,以便能够æ£ç¡®æ£€ç´¢åˆ° resource
31: return new ModuleClassLoader(this ) {
32: public URL getResource(String name) {
33: // parent 是 ClassLoaderRepository
34: return getParent().getResource(name);
35: }
36:
37: protected URL[] getASMClasspathURLs() {
38: return super .getASMClasspathURLs();
39: }
40: };
41: }
42:
43: protected void resolve() throws ModuleResolvedFailedException {
44: setName(name);
45: setDescription("System Module");
46: setPriority(Integer.MIN_VALUE);
47: }
48:
49: public String getName() {
50: return name;
51: }
52:
53: public String getDescription() {
54: return super .getDescription();
55: }
56:
57: /**
58: * SystemModuleçš„ classpath å·²ç»?指定在å?¯åŠ¨ classpathä¸
59: */
60: public URL[] getClasspathURLs() {
61: return ((URLClassLoader) SystemModule.class.getClassLoader())
62: .getURLs();
63: }
64:
65: public URL getDescriptorURL() {
66: return null;
67: }
68:
69: // 在 fire ModuleLoadingEvent之å‰?åŠ è½½ä»¥ä¸‹ç»„ä»¶ï¼Œä»¥ä¾¿èƒ½ç›‘å?¬ModuleLoadingEvent
70: protected void preActiveComponent() {
71: // instantiate EJB container
72: findComponentByInterface(EJBContainer.class);
73: // instantiate JPA container
74: findComponentByInterface(EntityManagerFactoryBuilder.class);
75: // instantiate Web Service container
76: findComponentByInterface(WSContainer.class);
77:
78: }
79:
80: public static void main(String[] args) {
81:
82: }
83: }
|