KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > theme > strategy > impl > StrategyContextImpl


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.portal.core.theme.strategy.impl;
9
10 import org.jboss.portal.server.theme.PortalLayout;
11 import org.jboss.portal.server.theme.strategy.PortletContext;
12 import org.jboss.portal.server.theme.strategy.StrategyContext;
13 import org.jboss.portal.server.theme.strategy.StrategyResponse;
14
15 import javax.servlet.http.HttpServletRequest JavaDoc;
16 import java.util.Collection JavaDoc;
17 import java.util.Collections JavaDoc;
18
19 /**
20  * An implementation of the strategy context.
21  * <p>The strategy context is used by the layout strategy interceptor to pass the available state information
22  * from the portal to the strategy. The context contains information about the current page, the portlets on it,
23  * the state of those portlets, etc.</p>
24  *
25  * @author <a HREF="mailto:mholzner@novell.com">Martin Holzner</a>.
26  * @version <tt>$Revision: 1.8 $</tt>
27  * @see StrategyContext
28  */

29 public class StrategyContextImpl implements StrategyContext
30 {
31    private final Collection JavaDoc portlets;
32    private final PortalLayout layout;
33    private final String JavaDoc portalName;
34    private final String JavaDoc pageName;
35    private final String JavaDoc[] regionNames;
36    private final PortletContext targetPortlet;
37    private final HttpServletRequest JavaDoc httpRequest;
38
39    /**
40     * Create a new instance of this contex.
41     *
42     * @param httpRequest the current servlet request
43     * @param layout the layout that will be used for the current portal request
44     * @param portlets a <code>java.util.List</code> of <code>org.jboss.portal.server.theme.strategy.PortletContext</code>
45     * instances of the portlets on the requested page
46     * @param targetPortlet the <code>org.jboss.portal.server.theme.strategy.PortletContext</code> of the portlet that is
47     * targeted in this request (if any), otherwise null. A portlet is targeted if it receives a render or action request
48     * @param portalName the name of the portal that was requested
49     * @param pageName the name of the page that was requested
50     * @param regionNames an array of all the region names that are available on the requested page
51     * @throws NullPointerException if httpRequest, portalName or pageName are null
52     */

53    public StrategyContextImpl(HttpServletRequest JavaDoc httpRequest, PortalLayout layout,
54                               Collection JavaDoc portlets, PortletContext targetPortlet, String JavaDoc portalName,
55                               String JavaDoc pageName, String JavaDoc[] regionNames)
56    {
57       if (httpRequest == null)
58       {
59          throw new NullPointerException JavaDoc("HttpServletRequest cannot be null");
60       }
61       if (portalName == null || "".equals(portalName))
62       {
63          throw new NullPointerException JavaDoc("PortalName cannot be null or empty");
64       }
65       if (pageName == null || "".equals(pageName))
66       {
67          throw new NullPointerException JavaDoc("PageName cannot be null or empty");
68       }
69       this.httpRequest = httpRequest;
70       this.portalName = portalName;
71       this.pageName = pageName;
72
73       this.portlets = portlets == null ? Collections.EMPTY_LIST : portlets;
74       this.regionNames = regionNames == null ? new String JavaDoc[]{} : regionNames;
75       this.layout = layout;
76       this.targetPortlet = targetPortlet;
77    }
78
79    /**
80     * @see org.jboss.portal.server.theme.strategy.StrategyContext#getPortletList()
81     * @see org.jboss.portal.server.theme.strategy.PortletContext
82     */

83    public Collection JavaDoc getPortletList()
84    {
85       return Collections.unmodifiableCollection(portlets);
86    }
87
88    /**
89     * @see org.jboss.portal.server.theme.strategy.StrategyContext#getTargetPortlet()
90     */

91    public PortletContext getTargetPortlet()
92    {
93       return targetPortlet;
94    }
95
96    /**
97     * @see org.jboss.portal.server.theme.strategy.StrategyContext#getLayout()
98     */

99    public PortalLayout getLayout()
100    {
101       return layout;
102    }
103
104    /**
105     * @see org.jboss.portal.server.theme.strategy.StrategyContext#getPortalName()
106     */

107    public String JavaDoc getPortalName()
108    {
109       return portalName;
110    }
111
112    /**
113     * @see org.jboss.portal.server.theme.strategy.StrategyContext#getPageName()
114     */

115    public String JavaDoc getPageName()
116    {
117       return pageName;
118    }
119
120    /**
121     * @see org.jboss.portal.server.theme.strategy.StrategyContext#getRegions()
122     */

123    public String JavaDoc[] getRegions()
124    {
125       return regionNames;
126    }
127
128    /**
129     * @see org.jboss.portal.server.theme.strategy.StrategyContext#createResponse()
130     */

131    public StrategyResponse createResponse()
132    {
133       return new StrategyResponseImpl();
134    }
135
136    /**
137     * @see org.jboss.portal.server.theme.strategy.StrategyContext#getHttpServletRequest()
138     */

139    public HttpServletRequest JavaDoc getHttpServletRequest()
140    {
141       return httpRequest;
142    }
143 }
144
Popular Tags