1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17packageorg.apache.jetspeed.container.invoker;
1819import java.util.Map;
2021import javax.servlet.ServletConfig;
2223import org.apache.jetspeed.PortalContext;
24import org.apache.jetspeed.factory.PortletFactory;
25import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
26import org.apache.pluto.factory.PortletInvokerFactory;
27import org.apache.pluto.invoker.PortletInvoker;
28import org.apache.pluto.om.portlet.PortletDefinition;
2930/***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 defined34 * 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 by38 * the portal implementation. The Pluto container uses pluggable portlet invoker factories39 * 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 Pluto43 * factory services in the <code>org.apach.pluto.factory.Factory</code> interface with44 * 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 */57publicclassPortletInvokerFactoryImpl58 implements PortletInvokerFactory
59 {
6061publicfinalstatic String INVOKER_SERVLET_MAPPING_NAME = "factory.invoker.servlet.mapping.name";
62publicfinalstatic String DEFAULT_MAPPING_NAME = "/container";
6364/*** The servlet configuration for the Jetspeed portal */65privatefinal ServletConfig servletConfig;
6667privatefinal PortalContext portalContext;
6869privatefinal PortletFactory portletFactory;
7071privatefinalServletPortletInvokerFactory servletPortletInvokerFactory;
7273privatefinalLocalPortletInvokerFactory localPortletInvokerFactory;
7475publicPortletInvokerFactoryImpl(ServletConfig servletConfig, PortalContext portalContext,
76 PortletFactory portletFactory, ServletPortletInvokerFactory servletPortletInvokerFactory, LocalPortletInvokerFactory localPortletInvokerFactory)
77 {
78this.servletConfig = servletConfig;
79this.portalContext = portalContext;
80this.portletFactory = portletFactory;
81this.servletPortletInvokerFactory = servletPortletInvokerFactory;
82this.localPortletInvokerFactory = localPortletInvokerFactory;
83 }
8485/* (non-Javadoc)86 * @see org.apache.pluto.factory.Factory#init(javax.servlet.ServletConfig, java.util.Map)87 */88publicvoid init(ServletConfig config, Map properties)
89 throws Exception
90 {
91// does absolutely nothing92 }
9394/* (non-Javadoc)95 * @see org.apache.pluto.factory.Factory#destroy()96 */97publicvoid destroy()
98 throws Exception
99 {
100 }
101102/* (non-Javadoc)103 * @see org.apache.pluto.factory.PortletInvokerFactory#getPortletInvoker(org.apache.pluto.om.portlet.PortletDefinition)104 */105public PortletInvoker getPortletInvoker(PortletDefinition portletDefinition)
106 {
107 MutablePortletApplication app = (MutablePortletApplication)portletDefinition.getPortletApplicationDefinition();
108if(app == null)
109 {
110thrownew IllegalStateException("Portlet definition \""+portletDefinition.getName()+"\" is not assigned to a portlet application.");
111 }
112113if (app.getApplicationType() == MutablePortletApplication.LOCAL)
114 {
115LocalPortletInvoker localPortletInvoker = localPortletInvokerFactory.createInstance();
116 localPortletInvoker.activate(portletFactory, portletDefinition, servletConfig);
117return localPortletInvoker;
118 }
119else120 {
121ServletPortletInvoker servletPortletInvoker = servletPortletInvokerFactory.createInstance();
122 String servletMappingName = portalContext.getConfigurationProperty(INVOKER_SERVLET_MAPPING_NAME, DEFAULT_MAPPING_NAME);
123 servletPortletInvoker.activate(portletFactory, portletDefinition, servletConfig, servletMappingName);
124return servletPortletInvoker;
125 }
126127 }
128129/* (non-Javadoc)130 * @see org.apache.pluto.factory.PortletInvokerFactory#releasePortletInvoker(org.apache.pluto.invoker.PortletInvoker)131 */132publicvoid releasePortletInvoker(PortletInvoker invoker)
133 {
134// this is now taken care off by Spring's CommonsPoolingTargetSource135// try136// {137// if (invoker instanceof ServletPortletInvoker)138// {139// servletInvokerFactory.releaseObject(invoker); 140// }141// else142// {143// localInvokerFactory.releaseObject(invoker); 144// }145// }146// catch (Exception e)147// {148// log.error(e);149// }150 }
151152 }