KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
12 import java.util.Map JavaDoc;
13 import java.util.Set JavaDoc;
14
15 import org.apache.log4j.Logger;
16 import org.jboss.portal.common.plugin.Plugin;
17 import org.jboss.portal.common.plugin.PluginContainer;
18 import org.jboss.portal.server.invocation.Invocation;
19 import org.jboss.portal.server.kernel.BaseService;
20 import org.jboss.portal.server.kernel.Registration;
21 import org.jboss.portal.server.kernel.Service;
22 import org.jboss.portal.server.kernel.ServiceImplementation;
23 import org.jboss.portal.server.metadata.ServerObjectMetaData;
24 import org.jboss.portal.server.plugins.PluginID;
25 import org.jboss.portal.server.user.ServerObjectContext;
26
27 /**
28  * A common base for portal objects that live in a portal container.
29  *
30  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
31  * @version $Revision: 1.5 $
32  */

33 public abstract class ServerObject
34    extends BaseService
35    implements Service,
36    Registration,
37    PluginContainer
38 {
39
40    /** Node name. */
41    protected final String JavaDoc name;
42
43    /** Logger. */
44    protected final Logger log;
45
46    /** Dependant plugins. */
47    protected Map JavaDoc plugins;
48
49    /**
50     * @exception IllegalArgumentException if the component name is null
51     */

52    public ServerObject(String JavaDoc name)
53    {
54       if (name == null)
55       {
56          throw new IllegalArgumentException JavaDoc("Component name cannot be null");
57       }
58       this.name = name;
59       this.log = Logger.getLogger(getClass());
60       this.plugins = new HashMap JavaDoc();
61    }
62
63    /**
64     * Return the meta data for that object.
65     */

66    public abstract ServerObjectMetaData getMetaData();
67
68    /**
69     * Return an ID that uniquely identify this portal object.
70     */

71    public ServerObjectID getID()
72    {
73       return (ServerObjectID)ctx.getID();
74    }
75
76    /**
77     * Return the container this object belongs to.
78     */

79    public abstract PortalServer getServer();
80
81    /**
82     * Return the name.
83     */

84    public String JavaDoc getName()
85    {
86       return name;
87    }
88
89    /**
90     * Create and returns a context object.
91     *
92     * @return a context object
93     * @throws UnsupportedOperationException if the object does not support contextualization
94     */

95    public ServerObjectContext createContext() throws UnsupportedOperationException JavaDoc
96    {
97       throw new UnsupportedOperationException JavaDoc("Contextualization not supported");
98    }
99
100    public void addIDependOn(ServiceImplementation implementation)
101    {
102    }
103
104    public void removeIDependOn(ServiceImplementation implementation)
105    {
106    }
107
108    public void addDependsOnMe(ServiceImplementation implementation)
109    {
110       Service service = implementation.getService();
111       if (service instanceof Plugin)
112       {
113          Plugin plugin = (Plugin)service;
114          PluginID pluginID = (PluginID)implementation.getID();
115          addPlugin(pluginID.getName(), plugin);
116       }
117    }
118
119    public void removeDependsOnMe(ServiceImplementation implementation)
120    {
121       Service service = implementation.getService();
122       if (service instanceof Plugin)
123       {
124          PluginID pluginID = (PluginID)implementation.getID();
125          removePlugin(pluginID.getName());
126       }
127    }
128
129    public void addPlugin(String JavaDoc key, Plugin plugin)
130    {
131       plugins.put(key, plugin);
132       plugin.setPluginContainer(this);
133    }
134
135    public void removePlugin(String JavaDoc key)
136    {
137       Plugin plugin = (Plugin)plugins.remove(key);
138       plugin.setPluginContainer(null);
139    }
140
141    public Plugin getPlugin(String JavaDoc key)
142    {
143       return (Plugin)plugins.get(key);
144    }
145
146    public Set JavaDoc getPluginKeySet()
147    {
148       return plugins.keySet();
149    }
150
151    public void create() throws Exception JavaDoc
152    {
153    }
154
155    public void start() throws Exception JavaDoc
156    {
157    }
158
159    public void stop()
160    {
161    }
162
163    public void destroy()
164    {
165    }
166
167    /**
168     * Invoke on this object.
169     */

170    public Object JavaDoc invoke(Invocation invocation)
171    {
172       throw new UnsupportedOperationException JavaDoc();
173    }
174
175    /**
176     * Create a new URL for that will target this object.
177     */

178    public ServerURL createURL()
179    {
180       throw new UnsupportedOperationException JavaDoc();
181    }
182 }
183
Popular Tags