KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashSet JavaDoc;
13 import java.util.Set JavaDoc;
14
15 import org.jboss.portal.server.kernel.Service;
16 import org.jboss.portal.server.kernel.ServiceImplementation;
17 import org.jboss.portal.server.metadata.ServerObjectMetaData;
18 import org.jboss.portal.server.metadata.WindowMetaData;
19 import org.jboss.portal.server.plugins.mode.ContentTypes;
20 import org.jboss.portal.server.plugins.mode.Mode;
21 import org.jboss.portal.server.plugins.mode.ModeProvider;
22 import org.jboss.portal.server.plugins.windowstate.WindowState;
23 import org.jboss.portal.server.plugins.windowstate.WindowStateProvider;
24 import org.jboss.portal.server.user.ServerObjectContext;
25
26 /**
27  * The placement of a component instance on the page.
28  *
29  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
30  * @version $Revision: 1.5 $
31  */

32 public class Window extends ServerObject
33 {
34
35    protected Portal portal;
36    protected Instance instance;
37    protected WindowMetaData metaData;
38
39    public Window(WindowMetaData metaData)
40    {
41       super(metaData.getName());
42       this.metaData = metaData;
43    }
44
45    public ServerObjectContext createContext()
46    {
47       return new WindowContext(getID());
48    }
49
50    public ServerObjectMetaData getMetaData()
51    {
52       return metaData;
53    }
54
55    public PortalServer getServer()
56    {
57       return instance.getServer();
58    }
59
60    /**
61     * Return the portal this instance belongs to.
62     */

63    public Portal getPortal()
64    {
65       return portal;
66    }
67
68    /**
69     * Return the instance associed to this window.
70     */

71    public Instance getInstance()
72    {
73       return instance;
74    }
75
76    public void addIDependOn(ServiceImplementation implementation)
77    {
78       Service service = implementation.getService();
79       if (service instanceof Instance)
80       {
81          instance = (Instance)service;
82       }
83       else if (service instanceof Portal)
84       {
85          portal = (Portal)service;
86       }
87       else
88       {
89          super.addIDependOn(implementation);
90       }
91    }
92
93    public void removeIDependOn(ServiceImplementation implementation)
94    {
95       Service service = implementation.getService();
96       if (service instanceof Instance)
97       {
98          instance = null;
99       }
100       else if (service instanceof Portal)
101       {
102          portal = null;
103       }
104       else
105       {
106          super.removeIDependOn(implementation);
107       }
108    }
109
110    /**
111     * Return the set portlet modes allowed by this portlet window.
112     */

113    public Collection JavaDoc getSupportedModes(String JavaDoc contentType)
114    {
115       Component component = getInstance().getComponent();
116       ContentTypes contentTypes = component.getContentTypes();
117       Set JavaDoc componentModes = contentTypes.getSupportedModes(contentType);
118       Set JavaDoc tmp = new HashSet JavaDoc(componentModes);
119
120       //
121
ModeProvider modes = portal.getModeProvider();
122       tmp.retainAll(modes.getModes());
123       return tmp;
124    }
125
126    /**
127     * Return true if the given content type is supported for the given mode.
128     *
129     * @throws IllegalArgumentException if the content type or the mode is null
130     */

131    public boolean isSupportedMode(String JavaDoc contentType, Mode mode)
132    {
133       // Check against the current content type
134
Component component = instance.getComponent();
135       ContentTypes contentTypes = component.getContentTypes();
136
137       // Rely on this method to throw the IAE if one of the arguments is null
138
if (!contentTypes.isSupported(mode, contentType))
139       {
140          return false;
141       }
142
143       // Check against the portal
144
ModeProvider portalProvider = portal.getModeProvider();
145       return portalProvider.containsMode(mode);
146    }
147
148    /**
149     * @throws IllegalArgumentException if the window state is null
150     */

151    public boolean isSupportedWindowState(WindowState windowState)
152    {
153       // Check against the portal
154
WindowStateProvider windowStates = portal.getWindowStateProvider();
155
156       // Rely on this method to throw the IAE if the argument is null
157
return windowStates.containsWindowState(windowState);
158    }
159
160    /**
161     * Return the set window states allowed by this portlet window.
162     */

163    public Set JavaDoc getSupportedWindowStates()
164    {
165       return portal.getWindowStateProvider().getWindowStates();
166    }
167
168    // Should be defined by window.
169
public ServerURL createURL()
170    {
171       WindowURL windowURL = new WindowURL(getID());
172       return windowURL;
173    }
174 }
175
Popular Tags