KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.jboss.portal.server.kernel.Service;
17 import org.jboss.portal.server.kernel.ServiceImplementation;
18 import org.jboss.portal.server.metadata.InstanceMetaData;
19 import org.jboss.portal.server.metadata.ServerObjectMetaData;
20 import org.jboss.portal.server.user.ServerObjectContext;
21
22 /**
23  * The occurrence of a component and a preference set.
24  *
25  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
26  * @version $Revision: 1.5 $
27  */

28 public class Instance
29    extends ServerObject
30 {
31
32    protected Component component;
33    protected Map JavaDoc windows;
34    protected InstanceMetaData metaData;
35
36    public Instance(InstanceMetaData metaData)
37    {
38       super(metaData.getName());
39       this.windows = Collections.synchronizedMap(new HashMap JavaDoc());
40       this.metaData = metaData;
41    }
42
43    public ServerObjectContext createContext()
44    {
45       return new InstanceContext(getID());
46    }
47
48    public ServerObjectMetaData getMetaData()
49    {
50       return metaData;
51    }
52
53    public PortalServer getServer()
54    {
55       return component.getServer();
56    }
57
58    /**
59     * Return the componnent for this instance.
60     */

61    public Component getComponent()
62    {
63       return component;
64    }
65
66    /**
67     * Return a specific window related to this instance.
68     */

69    public Window getWindow(String JavaDoc name)
70    {
71       return (Window)windows.get(name);
72    }
73
74    /**
75     * Return the windows owned by this instance.
76     */

77    public Collection JavaDoc getWindows()
78    {
79       return windows.values();
80    }
81
82    public void addDependsOnMe(ServiceImplementation implementation)
83    {
84       Service service = implementation.getService();
85       if (service instanceof Window)
86       {
87          Window window = (Window)service;
88          windows.put(window.getName(), window);
89          log.debug("Added window " + window.getName());
90       }
91       else
92       {
93          super.addDependsOnMe(implementation);
94       }
95    }
96
97    public void removeDependsOnMe(ServiceImplementation implementation)
98    {
99       Service service = implementation.getService();
100       if (service instanceof Window)
101       {
102          Window window = (Window)service;
103          windows.remove(window.getName());
104          log.debug("Removed window " + window.getName());
105       }
106       else
107       {
108          super.removeDependsOnMe(implementation);
109       }
110    }
111
112    public void addIDependOn(ServiceImplementation implementation)
113    {
114       Service service = implementation.getService();
115       if (service instanceof Component)
116       {
117          component = (Component)service;
118       }
119       else
120       {
121          super.addIDependOn(implementation);
122       }
123    }
124
125    public void removeIDependOn(ServiceImplementation implementation)
126    {
127       Service service = implementation.getService();
128       if (service instanceof Component)
129       {
130          component = null;
131       }
132       else
133       {
134          super.removeIDependOn(implementation);
135       }
136    }
137 }
138
Popular Tags