KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > server > Application


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.server;
10
11 import java.util.Collection JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import javax.servlet.ServletContext JavaDoc;
16
17 import org.jboss.portal.server.kernel.Service;
18 import org.jboss.portal.server.kernel.ServiceImplementation;
19 import org.jboss.portal.server.metadata.ApplicationMetaData;
20 import org.jboss.portal.server.metadata.ServerObjectMetaData;
21
22 /**
23  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
24  * @version $Revision: 1.5 $
25  */

26 public abstract class Application extends ServerObject
27 {
28
29    protected ServletContext JavaDoc servletContext;
30    protected String JavaDoc contextPath;
31    protected ClassLoader JavaDoc classLoader;
32
33    protected Map JavaDoc components;
34
35    protected ApplicationMetaData metaData;
36
37    private PortalServer portalServer;
38
39    public Application(String JavaDoc name, ApplicationMetaData applicationMD)
40    {
41       super(name);
42       this.components = new HashMap JavaDoc();
43       this.metaData = applicationMD;
44       this.servletContext = applicationMD.getServletContext();
45       this.contextPath = applicationMD.getContextPath();
46       this.classLoader = applicationMD.getClassLoader();
47    }
48
49    public ServerObjectMetaData getMetaData()
50    {
51       return metaData;
52    }
53
54    public PortalServer getServer()
55    {
56       return portalServer;
57    }
58
59    public String JavaDoc getContextPath()
60    {
61       return contextPath;
62    }
63
64    public ClassLoader JavaDoc getClassLoader()
65    {
66       return classLoader;
67    }
68
69    public ServletContext JavaDoc getServletContext()
70    {
71       return servletContext;
72    }
73
74    public Component getComponent(String JavaDoc name)
75    {
76       return (Component)components.get(name);
77    }
78
79    public Collection JavaDoc getComponents()
80    {
81       return components.values();
82    }
83
84    public void addDependsOnMe(ServiceImplementation implementation)
85    {
86       Service service = implementation.getService();
87       if (service instanceof Component)
88       {
89          Component component = (Component)service;
90          components.put(component.getName(), component);
91          log.debug("Added component " + component.getName());
92       }
93       else
94       {
95          super.addDependsOnMe(implementation);
96       }
97    }
98
99    public void removeDependsOnMe(ServiceImplementation implementation)
100    {
101       Service service = implementation.getService();
102       if (service instanceof Component)
103       {
104          Component component = (Component)service;
105          components.remove(component.getName());
106          log.debug("Removed component " + component.getName());
107       }
108       else
109       {
110          super.removeDependsOnMe(implementation);
111       }
112    }
113
114    public void addIDependOn(ServiceImplementation implementation)
115    {
116       Service service = implementation.getService();
117       if (service instanceof PortalServer)
118       {
119          portalServer = (PortalServer)service;
120       }
121       else
122       {
123          super.addIDependOn(implementation);
124       }
125    }
126
127    public void removeIDependOn(ServiceImplementation implementation)
128    {
129       Service service = implementation.getService();
130       if (service instanceof PortalServer)
131       {
132          portalServer = null;
133       }
134       else
135       {
136          super.removeIDependOn(implementation);
137       }
138    }
139 }
140
Popular Tags