1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.container.invoker;
18
19 import java.util.Map;
20
21 import javax.servlet.ServletConfig;
22
23 import org.apache.jetspeed.PortalContext;
24 import org.apache.jetspeed.factory.PortletFactory;
25 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
26 import org.apache.pluto.factory.PortletInvokerFactory;
27 import org.apache.pluto.invoker.PortletInvoker;
28 import org.apache.pluto.om.portlet.PortletDefinition;
29
30 /***
31 * <p>
32 * Portlet Invoker Factory creates portlet invokers based on the servlet context.
33 * This class is part of the contract between Pluto and the Jetspeed Portal as defined
34 * in the interfaces under <code>org.apache.pluto.factory</code>
35 * The Pluto container uses portlet invokers to abstract access to portlets.
36 * An invoker interfaces defines which actions are performed between the portal and container,
37 * namely action, render and optionally load. Portlet invoker factories are implemented by
38 * the portal implementation. The Pluto container uses pluggable portlet invoker factories
39 * in order to get portlet invokers, and then invoke methods on portlets (render, action, load).
40 * </p>
41 * <p>
42 * The Portlet Invoker Factory is a Pluto factory. Pluto defines a basic lifecycle for Pluto
43 * factory services in the <code>org.apach.pluto.factory.Factory</code> interface with
44 * standard <code>init</code> and <code>destroy</code> methods.
45 * </p>
46 * <p>
47 * The Jetspeed portlet invoker factory supports two kinds of invokers: local and servlet.
48 * Local portlet invokers call portlets located in the same web applications.
49 * With local invokers, a simple java method invocation is called on the portlet.
50 * Servlet portlet invokers call portlets located in another web application.
51 * With servlet invokers, the servlet request dispatcher is used to call methods on the portlet.
52 * </p>
53 *
54 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
55 * @version $Id: PortletInvokerFactoryImpl.java 517124 2007-03-12 08:10:25Z ate $
56 */
57 public class PortletInvokerFactoryImpl
58 implements PortletInvokerFactory
59 {
60
61 public final static String INVOKER_SERVLET_MAPPING_NAME = "factory.invoker.servlet.mapping.name";
62 public final static String DEFAULT_MAPPING_NAME = "/container";
63
64 /*** The servlet configuration for the Jetspeed portal */
65 private final ServletConfig servletConfig;
66
67 private final PortalContext portalContext;
68
69 private final PortletFactory portletFactory;
70
71 private final ServletPortletInvokerFactory servletPortletInvokerFactory;
72
73 private final LocalPortletInvokerFactory localPortletInvokerFactory;
74
75 public PortletInvokerFactoryImpl(ServletConfig servletConfig, PortalContext portalContext,
76 PortletFactory portletFactory, ServletPortletInvokerFactory servletPortletInvokerFactory, LocalPortletInvokerFactory localPortletInvokerFactory)
77 {
78 this.servletConfig = servletConfig;
79 this.portalContext = portalContext;
80 this.portletFactory = portletFactory;
81 this.servletPortletInvokerFactory = servletPortletInvokerFactory;
82 this.localPortletInvokerFactory = localPortletInvokerFactory;
83 }
84
85
86
87
88 public void init(ServletConfig config, Map properties)
89 throws Exception
90 {
91
92 }
93
94
95
96
97 public void destroy()
98 throws Exception
99 {
100 }
101
102
103
104
105 public PortletInvoker getPortletInvoker(PortletDefinition portletDefinition)
106 {
107 MutablePortletApplication app = (MutablePortletApplication)portletDefinition.getPortletApplicationDefinition();
108 if(app == null)
109 {
110 throw new IllegalStateException("Portlet definition \""+portletDefinition.getName()+"\" is not assigned to a portlet application.");
111 }
112
113 if (app.getApplicationType() == MutablePortletApplication.LOCAL)
114 {
115 LocalPortletInvoker localPortletInvoker = localPortletInvokerFactory.createInstance();
116 localPortletInvoker.activate(portletFactory, portletDefinition, servletConfig);
117 return localPortletInvoker;
118 }
119 else
120 {
121 ServletPortletInvoker servletPortletInvoker = servletPortletInvokerFactory.createInstance();
122 String servletMappingName = portalContext.getConfigurationProperty(INVOKER_SERVLET_MAPPING_NAME, DEFAULT_MAPPING_NAME);
123 servletPortletInvoker.activate(portletFactory, portletDefinition, servletConfig, servletMappingName);
124 return servletPortletInvoker;
125 }
126
127 }
128
129
130
131
132 public void releasePortletInvoker(PortletInvoker invoker)
133 {
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150 }
151
152 }