001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.container.invoker;
018:
019: import java.util.Map;
020:
021: import javax.servlet.ServletConfig;
022:
023: import org.apache.jetspeed.PortalContext;
024: import org.apache.jetspeed.factory.PortletFactory;
025: import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
026: import org.apache.pluto.factory.PortletInvokerFactory;
027: import org.apache.pluto.invoker.PortletInvoker;
028: import org.apache.pluto.om.portlet.PortletDefinition;
029:
030: /**
031: * <p>
032: * Portlet Invoker Factory creates portlet invokers based on the servlet context.
033: * This class is part of the contract between Pluto and the Jetspeed Portal as defined
034: * in the interfaces under <code>org.apache.pluto.factory</code>
035: * The Pluto container uses portlet invokers to abstract access to portlets.
036: * An invoker interfaces defines which actions are performed between the portal and container,
037: * namely action, render and optionally load. Portlet invoker factories are implemented by
038: * the portal implementation. The Pluto container uses pluggable portlet invoker factories
039: * in order to get portlet invokers, and then invoke methods on portlets (render, action, load).
040: * </p>
041: * <p>
042: * The Portlet Invoker Factory is a Pluto factory. Pluto defines a basic lifecycle for Pluto
043: * factory services in the <code>org.apach.pluto.factory.Factory</code> interface with
044: * standard <code>init</code> and <code>destroy</code> methods.
045: * </p>
046: * <p>
047: * The Jetspeed portlet invoker factory supports two kinds of invokers: local and servlet.
048: * Local portlet invokers call portlets located in the same web applications.
049: * With local invokers, a simple java method invocation is called on the portlet.
050: * Servlet portlet invokers call portlets located in another web application.
051: * With servlet invokers, the servlet request dispatcher is used to call methods on the portlet.
052: * </p>
053: *
054: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
055: * @version $Id: PortletInvokerFactoryImpl.java 517124 2007-03-12 08:10:25Z ate $
056: */
057: public class PortletInvokerFactoryImpl implements PortletInvokerFactory {
058:
059: public final static String INVOKER_SERVLET_MAPPING_NAME = "factory.invoker.servlet.mapping.name";
060: public final static String DEFAULT_MAPPING_NAME = "/container";
061:
062: /** The servlet configuration for the Jetspeed portal */
063: private final ServletConfig servletConfig;
064:
065: private final PortalContext portalContext;
066:
067: private final PortletFactory portletFactory;
068:
069: private final ServletPortletInvokerFactory servletPortletInvokerFactory;
070:
071: private final LocalPortletInvokerFactory localPortletInvokerFactory;
072:
073: public PortletInvokerFactoryImpl(ServletConfig servletConfig,
074: PortalContext portalContext, PortletFactory portletFactory,
075: ServletPortletInvokerFactory servletPortletInvokerFactory,
076: LocalPortletInvokerFactory localPortletInvokerFactory) {
077: this .servletConfig = servletConfig;
078: this .portalContext = portalContext;
079: this .portletFactory = portletFactory;
080: this .servletPortletInvokerFactory = servletPortletInvokerFactory;
081: this .localPortletInvokerFactory = localPortletInvokerFactory;
082: }
083:
084: /* (non-Javadoc)
085: * @see org.apache.pluto.factory.Factory#init(javax.servlet.ServletConfig, java.util.Map)
086: */
087: public void init(ServletConfig config, Map properties)
088: throws Exception {
089: // does absolutely nothing
090: }
091:
092: /* (non-Javadoc)
093: * @see org.apache.pluto.factory.Factory#destroy()
094: */
095: public void destroy() throws Exception {
096: }
097:
098: /* (non-Javadoc)
099: * @see org.apache.pluto.factory.PortletInvokerFactory#getPortletInvoker(org.apache.pluto.om.portlet.PortletDefinition)
100: */
101: public PortletInvoker getPortletInvoker(
102: PortletDefinition portletDefinition) {
103: MutablePortletApplication app = (MutablePortletApplication) portletDefinition
104: .getPortletApplicationDefinition();
105: if (app == null) {
106: throw new IllegalStateException("Portlet definition \""
107: + portletDefinition.getName()
108: + "\" is not assigned to a portlet application.");
109: }
110:
111: if (app.getApplicationType() == MutablePortletApplication.LOCAL) {
112: LocalPortletInvoker localPortletInvoker = localPortletInvokerFactory
113: .createInstance();
114: localPortletInvoker.activate(portletFactory,
115: portletDefinition, servletConfig);
116: return localPortletInvoker;
117: } else {
118: ServletPortletInvoker servletPortletInvoker = servletPortletInvokerFactory
119: .createInstance();
120: String servletMappingName = portalContext
121: .getConfigurationProperty(
122: INVOKER_SERVLET_MAPPING_NAME,
123: DEFAULT_MAPPING_NAME);
124: servletPortletInvoker.activate(portletFactory,
125: portletDefinition, servletConfig,
126: servletMappingName);
127: return servletPortletInvoker;
128: }
129:
130: }
131:
132: /* (non-Javadoc)
133: * @see org.apache.pluto.factory.PortletInvokerFactory#releasePortletInvoker(org.apache.pluto.invoker.PortletInvoker)
134: */
135: public void releasePortletInvoker(PortletInvoker invoker) {
136: // this is now taken care off by Spring's CommonsPoolingTargetSource
137: // try
138: // {
139: // if (invoker instanceof ServletPortletInvoker)
140: // {
141: // servletInvokerFactory.releaseObject(invoker);
142: // }
143: // else
144: // {
145: // localInvokerFactory.releaseObject(invoker);
146: // }
147: // }
148: // catch (Exception e)
149: // {
150: // log.error(e);
151: // }
152: }
153:
154: }
|