portals-pluto-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r607450 [4/36] - in /portals/pluto/trunk: ./ assembly/src/main/assembly/ assembly/src/main/resources/ maven-pluto-plugin/ maven-pluto-plugin/src/main/java/org/apache/pluto/maven/ pluto-ant-tasks/ pluto-ant-tasks/src/assemble/ pluto-ant-task...
Date Sat, 29 Dec 2007 17:32:18 GMT
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java?rev=607450&r1=607449&r2=607450&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java Sat Dec 29 09:31:56 2007
@@ -1,172 +1,172 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pluto.core;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.portlet.PortletRequest;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.pluto.PortletContainerException;
-import org.apache.pluto.PortletWindow;
-import org.apache.pluto.internal.InternalPortletPreference;
-import org.apache.pluto.spi.optional.PortletPreferencesService;
-
-/**
- * Default implementation of the portlet preferences service. The portlet
- * preferences service is a singleton held by the pluto portlet container.
- *
- * @see javax.portlet.PortletPreferences
- * @see org.apache.pluto.internal.impl.PortletPreferencesImpl
- * @see javax.portlet.PortletPreferences
- *
- */
-public class DefaultPortletPreferencesService
-implements PortletPreferencesService {
-
-	/** Logger. */
-	private static final Log LOG = LogFactory.getLog(
-			DefaultPortletPreferencesService.class);
-
-
-	// Private Member Variables ------------------------------------------------
-
-	/**
-	 * The in-memory portlet preferences storage: key is the preference name as
-	 * a string, value is an array of PortletPreference objects.
-	 */
-	private Map storage = new HashMap();
-
-
-	// Constructor -------------------------------------------------------------
-
-	/**
-	 * Default no-arg constructor.
-	 */
-	public DefaultPortletPreferencesService() {
-		// Do nothing.
-	}
-
-
-	// PortletPreferencesService Impl ------------------------------------------
-
-	/**
-	 * Returns the stored portlet preferences array. The preferences managed by
-	 * this service should be protected from being directly accessed, so this
-	 * method returns a cloned copy of the stored preferences.
-	 *
-	 * @param portletWindow  the portlet window.
-	 * @param request  the portlet request from which the remote user is retrieved.
-	 * @return a copy of the stored portlet preferences array.
-	 * @throws PortletContainerException
-	 */
-	public InternalPortletPreference[] getStoredPreferences(
-			PortletWindow portletWindow,
-			PortletRequest request)
-	throws PortletContainerException {
-        String key = getFormattedKey(portletWindow, request);
-        InternalPortletPreference[] preferences = (InternalPortletPreference[])
-        		storage.get(key);
-        if (preferences == null) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("No portlet preferences found for: " + key);
-            }
-            return new InternalPortletPreference[0];
-        } else {
-        	if (LOG.isDebugEnabled()) {
-        		LOG.debug("Got " + preferences.length + " stored preferences.");
-        	}
-        	return clonePreferences(preferences);
-        }
-    }
-
-	/**
-	 * Stores the portlet preferences to the in-memory storage. This method
-	 * should be invoked after the portlet preferences are validated by the
-	 * preference validator (if defined).
-	 * <p>
-	 * The preferences managed by this service should be protected from being
-	 * directly accessed, so this method clones the passed-in preferences array
-	 * and saves it.
-	 * </p>
-	 *
-	 * @see javax.portlet.PortletPreferences#store()
-	 *
-	 * @param portletWindow  the portlet window
-	 * @param request  the portlet request from which the remote user is retrieved.
-	 * @param preferences  the portlet preferences to store.
-	 * @throws PortletContainerException
-	 */
-    public void store(PortletWindow portletWindow,
-                      PortletRequest request,
-                      InternalPortletPreference[] preferences)
-    throws PortletContainerException {
-        String key = getFormattedKey(portletWindow, request);
-        storage.put(key, clonePreferences(preferences));
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Portlet preferences stored for: " + key);
-        }
-    }
-
-
-    // Private Methods ---------------------------------------------------------
-
-    /**
-     * Formats the preference key for the portlet preference using specified
-     * portlet window and remote user.
-     * @param portletWindow  the portlet window.
-     * @param request  the remote request.
-     */
-    private String getFormattedKey(PortletWindow portletWindow,
-                                   PortletRequest request) {
-    	StringBuffer buffer = new StringBuffer();
-    	buffer.append("user=").append(request.getRemoteUser()).append(";");
-    	buffer.append("portletName=").append(portletWindow.getPortletName());
-    	return buffer.toString();
-    }
-
-    /**
-     * Clones a PortletPreference array. This method performs a deep clone on
-     * the passed-in portlet preferences array. Every PortletPreference object
-     * in the array are cloned (via the <code>PortletPreference.clone()</code>
-     * method) and injected into the new array.
-     *
-     * @param preferences  the portlet preferences array to clone.
-     * @return a deep-cloned copy of the portlet preferences array.
-     */
-    private InternalPortletPreference[] clonePreferences(
-    		InternalPortletPreference[] preferences) {
-    	if (preferences == null) {
-    		return null;
-    	}
-    	InternalPortletPreference[] copy =
-    			new InternalPortletPreference[preferences.length];
-    	for (int i = 0; i < preferences.length; i++) {
-    		if (preferences[i] != null) {
-    			copy[i] = (InternalPortletPreference) preferences[i].clone();
-    		} else {
-    			copy[i] = null;
-    		}
-    	}
-    	return copy;
-    }
-
-}
-
-
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.core;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.PortletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.PortletWindow;
+import org.apache.pluto.internal.InternalPortletPreference;
+import org.apache.pluto.spi.optional.PortletPreferencesService;
+
+/**
+ * Default implementation of the portlet preferences service. The portlet
+ * preferences service is a singleton held by the pluto portlet container.
+ *
+ * @see javax.portlet.PortletPreferences
+ * @see org.apache.pluto.internal.impl.PortletPreferencesImpl
+ * @see javax.portlet.PortletPreferences
+ *
+ */
+public class DefaultPortletPreferencesService
+implements PortletPreferencesService {
+
+	/** Logger. */
+	private static final Log LOG = LogFactory.getLog(
+			DefaultPortletPreferencesService.class);
+
+
+	// Private Member Variables ------------------------------------------------
+
+	/**
+	 * The in-memory portlet preferences storage: key is the preference name as
+	 * a string, value is an array of PortletPreference objects.
+	 */
+	private Map storage = new HashMap();
+
+
+	// Constructor -------------------------------------------------------------
+
+	/**
+	 * Default no-arg constructor.
+	 */
+	public DefaultPortletPreferencesService() {
+		// Do nothing.
+	}
+
+
+	// PortletPreferencesService Impl ------------------------------------------
+
+	/**
+	 * Returns the stored portlet preferences array. The preferences managed by
+	 * this service should be protected from being directly accessed, so this
+	 * method returns a cloned copy of the stored preferences.
+	 *
+	 * @param portletWindow  the portlet window.
+	 * @param request  the portlet request from which the remote user is retrieved.
+	 * @return a copy of the stored portlet preferences array.
+	 * @throws PortletContainerException
+	 */
+	public InternalPortletPreference[] getStoredPreferences(
+			PortletWindow portletWindow,
+			PortletRequest request)
+	throws PortletContainerException {
+        String key = getFormattedKey(portletWindow, request);
+        InternalPortletPreference[] preferences = (InternalPortletPreference[])
+        		storage.get(key);
+        if (preferences == null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("No portlet preferences found for: " + key);
+            }
+            return new InternalPortletPreference[0];
+        } else {
+        	if (LOG.isDebugEnabled()) {
+        		LOG.debug("Got " + preferences.length + " stored preferences.");
+        	}
+        	return clonePreferences(preferences);
+        }
+    }
+
+	/**
+	 * Stores the portlet preferences to the in-memory storage. This method
+	 * should be invoked after the portlet preferences are validated by the
+	 * preference validator (if defined).
+	 * <p>
+	 * The preferences managed by this service should be protected from being
+	 * directly accessed, so this method clones the passed-in preferences array
+	 * and saves it.
+	 * </p>
+	 *
+	 * @see javax.portlet.PortletPreferences#store()
+	 *
+	 * @param portletWindow  the portlet window
+	 * @param request  the portlet request from which the remote user is retrieved.
+	 * @param preferences  the portlet preferences to store.
+	 * @throws PortletContainerException
+	 */
+    public void store(PortletWindow portletWindow,
+                      PortletRequest request,
+                      InternalPortletPreference[] preferences)
+    throws PortletContainerException {
+        String key = getFormattedKey(portletWindow, request);
+        storage.put(key, clonePreferences(preferences));
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Portlet preferences stored for: " + key);
+        }
+    }
+
+
+    // Private Methods ---------------------------------------------------------
+
+    /**
+     * Formats the preference key for the portlet preference using specified
+     * portlet window and remote user.
+     * @param portletWindow  the portlet window.
+     * @param request  the remote request.
+     */
+    private String getFormattedKey(PortletWindow portletWindow,
+                                   PortletRequest request) {
+    	StringBuffer buffer = new StringBuffer();
+    	buffer.append("user=").append(request.getRemoteUser()).append(";");
+    	buffer.append("portletName=").append(portletWindow.getPortletName());
+    	return buffer.toString();
+    }
+
+    /**
+     * Clones a PortletPreference array. This method performs a deep clone on
+     * the passed-in portlet preferences array. Every PortletPreference object
+     * in the array are cloned (via the <code>PortletPreference.clone()</code>
+     * method) and injected into the new array.
+     *
+     * @param preferences  the portlet preferences array to clone.
+     * @return a deep-cloned copy of the portlet preferences array.
+     */
+    private InternalPortletPreference[] clonePreferences(
+    		InternalPortletPreference[] preferences) {
+    	if (preferences == null) {
+    		return null;
+    	}
+    	InternalPortletPreference[] copy =
+    			new InternalPortletPreference[preferences.length];
+    	for (int i = 0; i < preferences.length; i++) {
+    		if (preferences[i] != null) {
+    			copy[i] = (InternalPortletPreference) preferences[i].clone();
+    		} else {
+    			copy[i] = null;
+    		}
+    	}
+    	return copy;
+    }
+
+}
+
+

Propchange: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java?rev=607450&r1=607449&r2=607450&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java Sat Dec 29 09:31:56 2007
@@ -1,479 +1,479 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pluto.core;
-
-import java.io.IOException;
-import java.util.Map;
-
-import javax.portlet.PortletException;
-import javax.portlet.PortletPreferences;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.pluto.OptionalContainerServices;
-import org.apache.pluto.PortletContainer;
-import org.apache.pluto.PortletContainerException;
-import org.apache.pluto.PortletWindow;
-import org.apache.pluto.RequiredContainerServices;
-import org.apache.pluto.descriptors.portlet.PortletAppDD;
-import org.apache.pluto.internal.InternalActionRequest;
-import org.apache.pluto.internal.InternalActionResponse;
-import org.apache.pluto.internal.InternalPortletRequest;
-import org.apache.pluto.internal.InternalPortletResponse;
-import org.apache.pluto.internal.InternalPortletWindow;
-import org.apache.pluto.internal.InternalRenderRequest;
-import org.apache.pluto.internal.InternalRenderResponse;
-import org.apache.pluto.internal.PortletDescriptorRegistry;
-import org.apache.pluto.internal.impl.InternalPortletWindowImpl;
-import org.apache.pluto.internal.impl.PortletRequestImpl;
-import org.apache.pluto.internal.impl.PortletResponseImpl;
-import org.apache.pluto.spi.PortletURLProvider;
-import org.apache.pluto.spi.optional.PortletInvokerService;
-import org.apache.pluto.util.StringManager;
-
-/**
- * Default Pluto Container implementation.
- *
- * @version 1.0
- * @since Sep 18, 2004
- */
-public class PortletContainerImpl implements PortletContainer {
-
-    /** Internal logger. */
-    private static final Log LOG = LogFactory.getLog(PortletContainerImpl.class);
-
-    private static final StringManager EXCEPTIONS = StringManager.getManager(
-    		PortletContainerImpl.class.getPackage().getName());
-
-
-    /** The portlet container name. */
-    private final String name;
-
-    /** The required container services associated with this container. */
-    private final RequiredContainerServices requiredContainerServices;
-
-    /** The optional container services associated with this container. */
-    private final OptionalContainerServices optionalContainerServices;
-
-    /** The servlet context associated with this container. */
-    private ServletContext servletContext;
-
-    /** Flag indicating whether or not we've been initialized. */
-    private boolean initialized = false;
-
-
-    // Constructor -------------------------------------------------------------
-
-    /** Default Constructor.  Create a container implementation
-     *  whith the given name and given services.
-     *
-     * @param name  the name of the container.
-     * @param requiredServices  the required container services implementation.
-     * @param optionalServices  the optional container services implementation.
-     */
-    public PortletContainerImpl(String name,
-                                RequiredContainerServices requiredServices,
-                                OptionalContainerServices optionalServices) {
-        this.name = name;
-        this.requiredContainerServices = requiredServices;
-        this.optionalContainerServices = optionalServices;
-    }
-
-
-    // PortletContainer Impl ---------------------------------------------------
-
-    /**
-     * Initialize the container for use within the given configuration scope.
-     * @param servletContext  the servlet context of the portal webapp.
-     */
-    public void init(ServletContext servletContext)
-    throws PortletContainerException {
-    	if (servletContext == null) {
-    		throw new PortletContainerException(
-    				"Unable to initialize portlet container [" + name + "]: "
-    				+ "servlet context is null.");
-    	}
-        this.servletContext = servletContext;
-        this.initialized = true;
-        infoWithName("Container initialized successfully.");
-    }
-
-    /**
-     * Determine whether this container has been initialized or not.
-     * @return true if the container has been initialized.
-     */
-    public boolean isInitialized() {
-        return initialized;
-    }
-
-    /**
-     * Destroy this container.
-     */
-    public void destroy() {
-        this.servletContext = null;
-        this.initialized = false;
-        infoWithName("Container destroyed.");
-    }
-
-
-    /**
-     * Renders the portlet associated with the specified portlet window.
-     * @param portletWindow  the portlet window.
-     * @param request  the servlet request.
-     * @param response  the servlet response.
-     * @throws IllegalStateException  if the container is not initialized.
-     * @throws PortletException
-     * @throws IOException
-     * @throws PortletContainerException
-     *
-     * @see javax.portlet.Portlet#render(javax.portlet.RenderRequest,javax.portlet.RenderResponse)
-     */
-    public void doRender(PortletWindow portletWindow,
-                         HttpServletRequest request,
-                         HttpServletResponse response)
-    throws PortletException, IOException, PortletContainerException {
-
-        ensureInitialized();
-
-        InternalPortletWindow internalPortletWindow =
-        		new InternalPortletWindowImpl(
-                    PortletContextManager.getPortletContext(servletContext,
-                        portletWindow.getContextPath()),
-                    portletWindow);
-        debugWithName("Render request received for portlet: "
-        		+ portletWindow.getPortletName());
-
-        InternalRenderRequest renderRequest = getOptionalContainerServices().getPortletEnvironmentService()
-            .createRenderRequest(this, request, response, internalPortletWindow);
-
-        InternalRenderResponse renderResponse = getOptionalContainerServices().getPortletEnvironmentService()
-            .createRenderResponse(this, request, response, internalPortletWindow);
-
-        PortletInvokerService invoker = optionalContainerServices.getPortletInvokerService();
-
-        try {
-            ContainerInvocation.setInvocation(this, internalPortletWindow);
-            invoker.render(renderRequest, renderResponse, internalPortletWindow);
-        } finally {
-            ContainerInvocation.clearInvocation();
-        }
-
-        debugWithName("Portlet rendered for: "
-        		+ portletWindow.getPortletName());
-    }
-
-
-    /**
-     * Process action for the portlet associated with the given portlet window.
-     * @param portletWindow  the portlet window.
-     * @param request  the servlet request.
-     * @param response  the servlet response.
-     * @throws PortletException
-     * @throws IOException
-     * @throws PortletContainerException
-     *
-     * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest,javax.portlet.ActionResponse)
-     */
-    public void doAction(PortletWindow portletWindow,
-                         HttpServletRequest request,
-                         HttpServletResponse response)
-    throws PortletException, IOException, PortletContainerException {
-
-    	ensureInitialized();
-
-        InternalPortletWindow internalPortletWindow =
-            	new InternalPortletWindowImpl(
-                    PortletContextManager.getPortletContext(servletContext,
-                        portletWindow.getContextPath()), portletWindow);
-
-        debugWithName("Action request received for portlet: "
-    			+ portletWindow.getPortletName());
-
-        InternalActionRequest actionRequest = getOptionalContainerServices().getPortletEnvironmentService()
-            .createActionRequest(this, request, response, internalPortletWindow);
-
-        InternalActionResponse actionResponse = getOptionalContainerServices().getPortletEnvironmentService()
-            .createActionResponse(this, request, response, internalPortletWindow);
-
-        PortletInvokerService invoker = optionalContainerServices.getPortletInvokerService();
-
-        try {
-            ContainerInvocation.setInvocation(this, internalPortletWindow);
-            invoker.action(actionRequest, actionResponse, internalPortletWindow);
-        }
-        finally {
-            ContainerInvocation.clearInvocation();
-        }
-
-        debugWithName("Portlet action processed for: "
-        		+ portletWindow.getPortletName());
-
-        // After processing action, send a redirect URL for rendering.
-        String location = actionResponse.getRedirectLocation();
-
-        if (location == null) {
-
-        	// Create portlet URL provider to encode redirect URL.
-        	debugWithName("No redirect location specified.");
-            PortletURLProvider redirectURL = requiredContainerServices
-            		.getPortalCallbackService()
-            		.getPortletURLProvider(request, internalPortletWindow);
-
-            // Encode portlet mode if it is changed.
-            if (actionResponse.getChangedPortletMode() != null) {
-                redirectURL.setPortletMode(
-                		actionResponse.getChangedPortletMode());
-            }
-
-            // Encode window state if it is changed.
-            if (actionResponse.getChangedWindowState() != null) {
-                redirectURL.setWindowState(
-                		actionResponse.getChangedWindowState());
-            }
-
-            // Encode render parameters retrieved from action response.
-            Map renderParameters = actionResponse.getRenderParameters();
-            redirectURL.clearParameters();
-            redirectURL.setParameters(renderParameters);
-
-            // Encode redirect URL as a render URL.
-            redirectURL.setAction(false);
-
-            // Set secure of the redirect URL if necessary.
-            if (actionRequest.isSecure()) {
-                redirectURL.setSecure();
-            }
-
-            // Encode the redirect URL to a string.
-            location = actionResponse.encodeRedirectURL(redirectURL.toString());
-        }
-
-        // Here we intentionally use the original response
-        // instead of the wrapped internal response.
-        response.sendRedirect(location);
-        debugWithName("Redirect URL sent.");
-    }
-
-    /**
-     * Loads the portlet associated with the specified portlet window.
-     * @param portletWindow  the portlet window.
-     * @param request  the servlet request.
-     * @param response  the servlet response.
-     * @throws PortletException
-     * @throws IOException
-     * @throws PortletContainerException
-     */
-    public void doLoad(PortletWindow portletWindow,
-                       HttpServletRequest request,
-                       HttpServletResponse response)
-    throws PortletException, IOException, PortletContainerException {
-
-    	ensureInitialized();
-
-        InternalPortletWindow internalPortletWindow =
-        		new InternalPortletWindowImpl(
-                    PortletContextManager.getPortletContext(servletContext,
-                        portletWindow.getContextPath()),
-                    portletWindow);
-
-        debugWithName("Load request received for portlet: "
-        		+ portletWindow.getPortletName());
-
-        InternalRenderRequest renderRequest =
-            getOptionalContainerServices().getPortletEnvironmentService()
-                .createRenderRequest(this, request, response, internalPortletWindow);
-
-        InternalRenderResponse renderResponse =
-            getOptionalContainerServices().getPortletEnvironmentService()
-                .createRenderResponse(this, request, response, internalPortletWindow);
-
-        PortletInvokerService invoker = optionalContainerServices.getPortletInvokerService();
-
-        try {
-            ContainerInvocation.setInvocation(this, internalPortletWindow);
-            invoker.load(renderRequest, renderResponse, internalPortletWindow);
-        } finally {
-            ContainerInvocation.clearInvocation();
-        }
-
-        debugWithName("Portlet loaded for: " + portletWindow.getPortletName());
-    }
-
-
-    public void doAdmin(PortletWindow portletWindow,
-                        HttpServletRequest servletRequest,
-                        HttpServletResponse servletResponse)
-    throws PortletException, IOException, PortletContainerException {
-        ensureInitialized();
-
-        InternalPortletWindow internalPortletWindow =
-            new InternalPortletWindowImpl(
-                PortletContextManager.getPortletContext(servletContext,
-                    portletWindow.getContextPath()), portletWindow);
-
-        debugWithName("Admin request received for portlet: "
-            +portletWindow.getPortletName());
-
-        InternalPortletRequest internalRequest =
-            new AdminRequest(this, internalPortletWindow, servletRequest) { };
-
-        InternalPortletResponse internalResponse =
-            new AdminResponse(this, internalPortletWindow, servletRequest, servletResponse);
-
-        PortletInvokerService invoker =
-            optionalContainerServices.getPortletInvokerService();
-
-        try {
-            ContainerInvocation.setInvocation(this, internalPortletWindow);
-            invoker.admin(internalRequest, internalResponse, internalPortletWindow);
-        } finally {
-            ContainerInvocation.clearInvocation();
-        }
-
-        debugWithName("Admin request complete.");
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public RequiredContainerServices getRequiredContainerServices() {
-        return requiredContainerServices;
-    }
-
-    /**
-     * Retrieve the optional container services used by the container.
-     * If no implementation was provided during construction, the default
-     * instance will be returned.
-     *
-     * @return services used by the container.
-     */
-    public OptionalContainerServices getOptionalContainerServices() {
-        return optionalContainerServices;
-    }
-
-    public PortletAppDD getPortletApplicationDescriptor(String context)
-        throws PortletContainerException {
-
-        // make sure the container has initialized
-        ensureInitialized();
-
-        // sanity check
-        if (context == null || context.trim().equals("")) {
-            final String msg = "Context was null or the empty string.";
-            errorWithName(msg);
-            throw new PortletContainerException(msg);
-        }
-
-        // obtain the context of the portlet
-        ServletContext portletCtx = PortletContextManager.getPortletContext(servletContext, context);
-        if (portletCtx == null) {
-            final String msg = "Unable to obtain the servlet context for " +
-                "portlet context [" + context + "].  Ensure the portlet has " +
-                "been deployed and that cross context support is enabled.";
-            errorWithName(msg);
-            throw new PortletContainerException(msg);
-        }
-
-        // obtain the portlet application descriptor for the portlet
-        // context.
-        PortletAppDD portletAppDD = PortletDescriptorRegistry
-                                        .getRegistry()
-                                        .getPortletAppDD(portletCtx);
-
-        // we can't return null
-        if (portletAppDD == null) {
-            final String msg = "Obtained a null portlet application description for " +
-                "portlet context [" + context + "]";
-            errorWithName(msg);
-            throw new PortletContainerException(msg);
-        }
-
-        return portletAppDD;
-    }
-
-    // Private Methods ---------------------------------------------------------
-
-    /**
-     * Ensures that the portlet container is initialized.
-     * @throws IllegalStateException  if the container is not initialized.
-     */
-    private void ensureInitialized() throws IllegalStateException {
-    	if (!isInitialized()) {
-    		throw new IllegalStateException(
-    				"Portlet container [" + name + "] is not initialized.");
-    	}
-    }
-
-    /**
-     * Prints a message at DEBUG level with the container name prefix.
-     * @param message  log message.
-     */
-    private void debugWithName(String message) {
-    	if (LOG.isDebugEnabled()) {
-    		LOG.debug("Portlet Container [" + name + "]: " + message);
-    	}
-    }
-
-    /**
-     * Prints a message at INFO level with the container name prefix.
-     * @param message  log message.
-     */
-    private void infoWithName(String message) {
-    	if (LOG.isInfoEnabled()) {
-    		LOG.info("Portlet Container [" + name + "]: " + message);
-    	}
-    }
-
-    /**
-     * Prints a message at ERROR level with the container name prefix.
-     * @param message  log message.
-     */
-    private void errorWithName(String message) {
-        if (LOG.isErrorEnabled()) {
-            LOG.info("Portlet Container [" + name + "]: " + message);
-        }
-    }
-
-
-    class AdminRequest extends PortletRequestImpl {
-
-        public AdminRequest(PortletContainer container,
-                            InternalPortletWindow internalPortletWindow,
-                            HttpServletRequest servletRequest) {
-            super(container, internalPortletWindow, servletRequest);
-        }
-
-        public PortletPreferences getPreferences() {
-            throw new IllegalStateException("Can not access preferences during admin request.");
-        }
-    }
-
-    class AdminResponse extends PortletResponseImpl {
-
-        public AdminResponse(PortletContainer container,
-                             InternalPortletWindow internalPortletWindow,
-                             HttpServletRequest servletRequest,
-                             HttpServletResponse servletResponse) {
-            super(container, internalPortletWindow, servletRequest, servletResponse);
-        }
-    }
-}
-
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.core;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletPreferences;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.OptionalContainerServices;
+import org.apache.pluto.PortletContainer;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.PortletWindow;
+import org.apache.pluto.RequiredContainerServices;
+import org.apache.pluto.descriptors.portlet.PortletAppDD;
+import org.apache.pluto.internal.InternalActionRequest;
+import org.apache.pluto.internal.InternalActionResponse;
+import org.apache.pluto.internal.InternalPortletRequest;
+import org.apache.pluto.internal.InternalPortletResponse;
+import org.apache.pluto.internal.InternalPortletWindow;
+import org.apache.pluto.internal.InternalRenderRequest;
+import org.apache.pluto.internal.InternalRenderResponse;
+import org.apache.pluto.internal.PortletDescriptorRegistry;
+import org.apache.pluto.internal.impl.InternalPortletWindowImpl;
+import org.apache.pluto.internal.impl.PortletRequestImpl;
+import org.apache.pluto.internal.impl.PortletResponseImpl;
+import org.apache.pluto.spi.PortletURLProvider;
+import org.apache.pluto.spi.optional.PortletInvokerService;
+import org.apache.pluto.util.StringManager;
+
+/**
+ * Default Pluto Container implementation.
+ *
+ * @version 1.0
+ * @since Sep 18, 2004
+ */
+public class PortletContainerImpl implements PortletContainer {
+
+    /** Internal logger. */
+    private static final Log LOG = LogFactory.getLog(PortletContainerImpl.class);
+
+    private static final StringManager EXCEPTIONS = StringManager.getManager(
+    		PortletContainerImpl.class.getPackage().getName());
+
+
+    /** The portlet container name. */
+    private final String name;
+
+    /** The required container services associated with this container. */
+    private final RequiredContainerServices requiredContainerServices;
+
+    /** The optional container services associated with this container. */
+    private final OptionalContainerServices optionalContainerServices;
+
+    /** The servlet context associated with this container. */
+    private ServletContext servletContext;
+
+    /** Flag indicating whether or not we've been initialized. */
+    private boolean initialized = false;
+
+
+    // Constructor -------------------------------------------------------------
+
+    /** Default Constructor.  Create a container implementation
+     *  whith the given name and given services.
+     *
+     * @param name  the name of the container.
+     * @param requiredServices  the required container services implementation.
+     * @param optionalServices  the optional container services implementation.
+     */
+    public PortletContainerImpl(String name,
+                                RequiredContainerServices requiredServices,
+                                OptionalContainerServices optionalServices) {
+        this.name = name;
+        this.requiredContainerServices = requiredServices;
+        this.optionalContainerServices = optionalServices;
+    }
+
+
+    // PortletContainer Impl ---------------------------------------------------
+
+    /**
+     * Initialize the container for use within the given configuration scope.
+     * @param servletContext  the servlet context of the portal webapp.
+     */
+    public void init(ServletContext servletContext)
+    throws PortletContainerException {
+    	if (servletContext == null) {
+    		throw new PortletContainerException(
+    				"Unable to initialize portlet container [" + name + "]: "
+    				+ "servlet context is null.");
+    	}
+        this.servletContext = servletContext;
+        this.initialized = true;
+        infoWithName("Container initialized successfully.");
+    }
+
+    /**
+     * Determine whether this container has been initialized or not.
+     * @return true if the container has been initialized.
+     */
+    public boolean isInitialized() {
+        return initialized;
+    }
+
+    /**
+     * Destroy this container.
+     */
+    public void destroy() {
+        this.servletContext = null;
+        this.initialized = false;
+        infoWithName("Container destroyed.");
+    }
+
+
+    /**
+     * Renders the portlet associated with the specified portlet window.
+     * @param portletWindow  the portlet window.
+     * @param request  the servlet request.
+     * @param response  the servlet response.
+     * @throws IllegalStateException  if the container is not initialized.
+     * @throws PortletException
+     * @throws IOException
+     * @throws PortletContainerException
+     *
+     * @see javax.portlet.Portlet#render(javax.portlet.RenderRequest,javax.portlet.RenderResponse)
+     */
+    public void doRender(PortletWindow portletWindow,
+                         HttpServletRequest request,
+                         HttpServletResponse response)
+    throws PortletException, IOException, PortletContainerException {
+
+        ensureInitialized();
+
+        InternalPortletWindow internalPortletWindow =
+        		new InternalPortletWindowImpl(
+                    PortletContextManager.getPortletContext(servletContext,
+                        portletWindow.getContextPath()),
+                    portletWindow);
+        debugWithName("Render request received for portlet: "
+        		+ portletWindow.getPortletName());
+
+        InternalRenderRequest renderRequest = getOptionalContainerServices().getPortletEnvironmentService()
+            .createRenderRequest(this, request, response, internalPortletWindow);
+
+        InternalRenderResponse renderResponse = getOptionalContainerServices().getPortletEnvironmentService()
+            .createRenderResponse(this, request, response, internalPortletWindow);
+
+        PortletInvokerService invoker = optionalContainerServices.getPortletInvokerService();
+
+        try {
+            ContainerInvocation.setInvocation(this, internalPortletWindow);
+            invoker.render(renderRequest, renderResponse, internalPortletWindow);
+        } finally {
+            ContainerInvocation.clearInvocation();
+        }
+
+        debugWithName("Portlet rendered for: "
+        		+ portletWindow.getPortletName());
+    }
+
+
+    /**
+     * Process action for the portlet associated with the given portlet window.
+     * @param portletWindow  the portlet window.
+     * @param request  the servlet request.
+     * @param response  the servlet response.
+     * @throws PortletException
+     * @throws IOException
+     * @throws PortletContainerException
+     *
+     * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest,javax.portlet.ActionResponse)
+     */
+    public void doAction(PortletWindow portletWindow,
+                         HttpServletRequest request,
+                         HttpServletResponse response)
+    throws PortletException, IOException, PortletContainerException {
+
+    	ensureInitialized();
+
+        InternalPortletWindow internalPortletWindow =
+            	new InternalPortletWindowImpl(
+                    PortletContextManager.getPortletContext(servletContext,
+                        portletWindow.getContextPath()), portletWindow);
+
+        debugWithName("Action request received for portlet: "
+    			+ portletWindow.getPortletName());
+
+        InternalActionRequest actionRequest = getOptionalContainerServices().getPortletEnvironmentService()
+            .createActionRequest(this, request, response, internalPortletWindow);
+
+        InternalActionResponse actionResponse = getOptionalContainerServices().getPortletEnvironmentService()
+            .createActionResponse(this, request, response, internalPortletWindow);
+
+        PortletInvokerService invoker = optionalContainerServices.getPortletInvokerService();
+
+        try {
+            ContainerInvocation.setInvocation(this, internalPortletWindow);
+            invoker.action(actionRequest, actionResponse, internalPortletWindow);
+        }
+        finally {
+            ContainerInvocation.clearInvocation();
+        }
+
+        debugWithName("Portlet action processed for: "
+        		+ portletWindow.getPortletName());
+
+        // After processing action, send a redirect URL for rendering.
+        String location = actionResponse.getRedirectLocation();
+
+        if (location == null) {
+
+        	// Create portlet URL provider to encode redirect URL.
+        	debugWithName("No redirect location specified.");
+            PortletURLProvider redirectURL = requiredContainerServices
+            		.getPortalCallbackService()
+            		.getPortletURLProvider(request, internalPortletWindow);
+
+            // Encode portlet mode if it is changed.
+            if (actionResponse.getChangedPortletMode() != null) {
+                redirectURL.setPortletMode(
+                		actionResponse.getChangedPortletMode());
+            }
+
+            // Encode window state if it is changed.
+            if (actionResponse.getChangedWindowState() != null) {
+                redirectURL.setWindowState(
+                		actionResponse.getChangedWindowState());
+            }
+
+            // Encode render parameters retrieved from action response.
+            Map renderParameters = actionResponse.getRenderParameters();
+            redirectURL.clearParameters();
+            redirectURL.setParameters(renderParameters);
+
+            // Encode redirect URL as a render URL.
+            redirectURL.setAction(false);
+
+            // Set secure of the redirect URL if necessary.
+            if (actionRequest.isSecure()) {
+                redirectURL.setSecure();
+            }
+
+            // Encode the redirect URL to a string.
+            location = actionResponse.encodeRedirectURL(redirectURL.toString());
+        }
+
+        // Here we intentionally use the original response
+        // instead of the wrapped internal response.
+        response.sendRedirect(location);
+        debugWithName("Redirect URL sent.");
+    }
+
+    /**
+     * Loads the portlet associated with the specified portlet window.
+     * @param portletWindow  the portlet window.
+     * @param request  the servlet request.
+     * @param response  the servlet response.
+     * @throws PortletException
+     * @throws IOException
+     * @throws PortletContainerException
+     */
+    public void doLoad(PortletWindow portletWindow,
+                       HttpServletRequest request,
+                       HttpServletResponse response)
+    throws PortletException, IOException, PortletContainerException {
+
+    	ensureInitialized();
+
+        InternalPortletWindow internalPortletWindow =
+        		new InternalPortletWindowImpl(
+                    PortletContextManager.getPortletContext(servletContext,
+                        portletWindow.getContextPath()),
+                    portletWindow);
+
+        debugWithName("Load request received for portlet: "
+        		+ portletWindow.getPortletName());
+
+        InternalRenderRequest renderRequest =
+            getOptionalContainerServices().getPortletEnvironmentService()
+                .createRenderRequest(this, request, response, internalPortletWindow);
+
+        InternalRenderResponse renderResponse =
+            getOptionalContainerServices().getPortletEnvironmentService()
+                .createRenderResponse(this, request, response, internalPortletWindow);
+
+        PortletInvokerService invoker = optionalContainerServices.getPortletInvokerService();
+
+        try {
+            ContainerInvocation.setInvocation(this, internalPortletWindow);
+            invoker.load(renderRequest, renderResponse, internalPortletWindow);
+        } finally {
+            ContainerInvocation.clearInvocation();
+        }
+
+        debugWithName("Portlet loaded for: " + portletWindow.getPortletName());
+    }
+
+
+    public void doAdmin(PortletWindow portletWindow,
+                        HttpServletRequest servletRequest,
+                        HttpServletResponse servletResponse)
+    throws PortletException, IOException, PortletContainerException {
+        ensureInitialized();
+
+        InternalPortletWindow internalPortletWindow =
+            new InternalPortletWindowImpl(
+                PortletContextManager.getPortletContext(servletContext,
+                    portletWindow.getContextPath()), portletWindow);
+
+        debugWithName("Admin request received for portlet: "
+            +portletWindow.getPortletName());
+
+        InternalPortletRequest internalRequest =
+            new AdminRequest(this, internalPortletWindow, servletRequest) { };
+
+        InternalPortletResponse internalResponse =
+            new AdminResponse(this, internalPortletWindow, servletRequest, servletResponse);
+
+        PortletInvokerService invoker =
+            optionalContainerServices.getPortletInvokerService();
+
+        try {
+            ContainerInvocation.setInvocation(this, internalPortletWindow);
+            invoker.admin(internalRequest, internalResponse, internalPortletWindow);
+        } finally {
+            ContainerInvocation.clearInvocation();
+        }
+
+        debugWithName("Admin request complete.");
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public RequiredContainerServices getRequiredContainerServices() {
+        return requiredContainerServices;
+    }
+
+    /**
+     * Retrieve the optional container services used by the container.
+     * If no implementation was provided during construction, the default
+     * instance will be returned.
+     *
+     * @return services used by the container.
+     */
+    public OptionalContainerServices getOptionalContainerServices() {
+        return optionalContainerServices;
+    }
+
+    public PortletAppDD getPortletApplicationDescriptor(String context)
+        throws PortletContainerException {
+
+        // make sure the container has initialized
+        ensureInitialized();
+
+        // sanity check
+        if (context == null || context.trim().equals("")) {
+            final String msg = "Context was null or the empty string.";
+            errorWithName(msg);
+            throw new PortletContainerException(msg);
+        }
+
+        // obtain the context of the portlet
+        ServletContext portletCtx = PortletContextManager.getPortletContext(servletContext, context);
+        if (portletCtx == null) {
+            final String msg = "Unable to obtain the servlet context for " +
+                "portlet context [" + context + "].  Ensure the portlet has " +
+                "been deployed and that cross context support is enabled.";
+            errorWithName(msg);
+            throw new PortletContainerException(msg);
+        }
+
+        // obtain the portlet application descriptor for the portlet
+        // context.
+        PortletAppDD portletAppDD = PortletDescriptorRegistry
+                                        .getRegistry()
+                                        .getPortletAppDD(portletCtx);
+
+        // we can't return null
+        if (portletAppDD == null) {
+            final String msg = "Obtained a null portlet application description for " +
+                "portlet context [" + context + "]";
+            errorWithName(msg);
+            throw new PortletContainerException(msg);
+        }
+
+        return portletAppDD;
+    }
+
+    // Private Methods ---------------------------------------------------------
+
+    /**
+     * Ensures that the portlet container is initialized.
+     * @throws IllegalStateException  if the container is not initialized.
+     */
+    private void ensureInitialized() throws IllegalStateException {
+    	if (!isInitialized()) {
+    		throw new IllegalStateException(
+    				"Portlet container [" + name + "] is not initialized.");
+    	}
+    }
+
+    /**
+     * Prints a message at DEBUG level with the container name prefix.
+     * @param message  log message.
+     */
+    private void debugWithName(String message) {
+    	if (LOG.isDebugEnabled()) {
+    		LOG.debug("Portlet Container [" + name + "]: " + message);
+    	}
+    }
+
+    /**
+     * Prints a message at INFO level with the container name prefix.
+     * @param message  log message.
+     */
+    private void infoWithName(String message) {
+    	if (LOG.isInfoEnabled()) {
+    		LOG.info("Portlet Container [" + name + "]: " + message);
+    	}
+    }
+
+    /**
+     * Prints a message at ERROR level with the container name prefix.
+     * @param message  log message.
+     */
+    private void errorWithName(String message) {
+        if (LOG.isErrorEnabled()) {
+            LOG.info("Portlet Container [" + name + "]: " + message);
+        }
+    }
+
+
+    class AdminRequest extends PortletRequestImpl {
+
+        public AdminRequest(PortletContainer container,
+                            InternalPortletWindow internalPortletWindow,
+                            HttpServletRequest servletRequest) {
+            super(container, internalPortletWindow, servletRequest);
+        }
+
+        public PortletPreferences getPreferences() {
+            throw new IllegalStateException("Can not access preferences during admin request.");
+        }
+    }
+
+    class AdminResponse extends PortletResponseImpl {
+
+        public AdminResponse(PortletContainer container,
+                             InternalPortletWindow internalPortletWindow,
+                             HttpServletRequest servletRequest,
+                             HttpServletResponse servletResponse) {
+            super(container, internalPortletWindow, servletRequest, servletResponse);
+        }
+    }
+}
+

Propchange: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java?rev=607450&r1=607449&r2=607450&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java Sat Dec 29 09:31:56 2007
@@ -1,356 +1,356 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.pluto.core;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.pluto.PortletContainerException;
-import org.apache.pluto.descriptors.portlet.PortletAppDD;
-import org.apache.pluto.descriptors.portlet.PortletDD;
-import org.apache.pluto.internal.Configuration;
-import org.apache.pluto.internal.InternalPortletConfig;
-import org.apache.pluto.internal.InternalPortletContext;
-import org.apache.pluto.internal.PortletDescriptorRegistry;
-import org.apache.pluto.internal.impl.PortletConfigImpl;
-import org.apache.pluto.internal.impl.PortletContextImpl;
-import org.apache.pluto.spi.optional.PortletRegistryEvent;
-import org.apache.pluto.spi.optional.PortletRegistryListener;
-import org.apache.pluto.spi.optional.PortletRegistryService;
-import org.apache.pluto.util.ClasspathScanner;
-
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletContext;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Manager used to cache the portlet configurations which have
- * been previously parsed.
- *
- * @version 1.0
- * @since Sep 20, 2004
- */
-public class PortletContextManager implements PortletRegistryService {
-
-    /**
-     * Log Instance
-     */
-    private static final Log LOG = LogFactory.getLog(PortletContextManager.class);
-
-    /**
-     * The singleton manager instance.
-     */
-    private static final PortletContextManager MANAGER = new PortletContextManager();
-
-    /**
-     * List of application id resolvers. *
-     */
-    private static final List APP_ID_RESOLVERS = new ArrayList();
-
-    // Private Member Variables ------------------------------------------------
-
-    /**
-     * The PortletContext cache map: key is servlet context, and value is the
-     * associated portlet context.
-     */
-    private final Map portletContexts = new HashMap();
-
-
-    private final Map portletConfigs = new HashMap();
-
-
-    /**
-     * The registered listeners that should be notified upon
-     * registry events.
-     */
-    private final List registryListeners = new ArrayList();
-
-    // Constructor -------------------------------------------------------------
-
-    /**
-     * Private constructor that prevents external instantiation.
-     */
-    private PortletContextManager() {
-        // Do nothing.
-    }
-
-    /**
-     * Returns the singleton manager instance.
-     *
-     * @return the singleton manager instance.
-     */
-    public static PortletContextManager getManager() {
-        return MANAGER;
-    }
-
-    // Public Methods ----------------------------------------------------------
-
-    /**
-     * Retrieves the PortletContext associated with the given ServletContext.
-     * If one does not exist, it is created.
-     *
-     * @param config the servlet config.
-     * @return the InternalPortletContext associated with the ServletContext.
-     * @throws PortletContainerException
-     */
-    public String register(ServletConfig config) throws PortletContainerException {
-        InternalPortletContext portletContext = register(config.getServletContext());
-
-        PortletAppDD portletAppDD =
-            portletContext.getPortletApplicationDefinition();
-        PortletDD portletDD = null;
-
-        LOG.info("Registering "+portletAppDD.getPortlets().size()+" portlets for context "+portletContext.getApplicationId());
-
-        for (Iterator it = portletAppDD.getPortlets().iterator(); it.hasNext();) {
-            portletDD = (PortletDD) it.next();
-            portletConfigs.put(
-                portletContext.getApplicationId() + "/" + portletDD.getPortletName(),
-                new PortletConfigImpl(config, portletContext, portletDD)
-            );
-        }
-
-        return portletContext.getApplicationId();
-    }
-
-    /**
-     * @param servletContext
-     * @return
-     * @throws PortletContainerException
-     * @deprecated Use {@link #register(ServletConfig)}
-     */
-    public InternalPortletContext register(ServletContext servletContext)
-        throws PortletContainerException {
-        String applicationId = getContextPath(servletContext);
-        if (!portletContexts.containsKey(applicationId)) {
-
-            PortletAppDD portletAppDD = PortletDescriptorRegistry.getRegistry()
-                .getPortletAppDD(servletContext);
-
-            PortletContextImpl portletContext = new PortletContextImpl(
-                applicationId, servletContext, portletAppDD);
-
-            if (portletContext.getApplicationId() == null) {
-                throw new IllegalStateException("Unable to resolve unique identifier for portletContext.");
-            }
-            portletContexts.put(applicationId, portletContext);
-
-            fireRegistered(portletContext);
-
-            if (LOG.isInfoEnabled()) {
-                LOG.info("Registered portlet application with application id '" + applicationId + "'");
-            }
-        } else {
-             if (LOG.isInfoEnabled()) {
-                LOG.info("Portlet application with application id '" + applicationId + "' already registered.");
-            }
-        }
-
-
-        return (InternalPortletContext) portletContexts.get(applicationId);
-    }
-
-    public void remove(InternalPortletContext context) {
-        portletContexts.remove(context.getApplicationId());
-        Iterator configs = portletConfigs.keySet().iterator();
-        while (configs.hasNext()) {
-            String key = (String) configs.next();
-            if (key.startsWith(context.getApplicationId() + "/")) {
-                configs.remove();
-            }
-        }
-        fireRemoved(context);
-    }
-
-    public Iterator getRegisteredPortletApplicationIds() {
-        return new HashSet(portletContexts.keySet()).iterator();
-
-    }
-
-    /**
-     * Retrieve an iterator of all PortletContext instances
-     * which exist within this application.
-     *
-     * @return
-     */
-    public Iterator getRegisteredPortletApplications() {
-        return new HashSet(portletContexts.values()).iterator();
-    }
-
-    public PortletContext getPortletContext(String applicationId)
-        throws PortletContainerException {
-        return (InternalPortletContext) portletContexts.get(applicationId);
-    }
-
-    public PortletConfig getPortletConfig(String applicationId, String portletName) {
-        String lookup = applicationId + "/" + portletName;
-        if(!portletConfigs.containsKey(lookup)) {
-            LOG.info("Unable to locate portlet config [applicationId="+applicationId+"]/["+portletName+"].");
-        }
-        return (InternalPortletConfig) portletConfigs.get(lookup);
-    }
-
-    public PortletDD getPortletDescriptor(String applicationId, String portletName) {
-        InternalPortletConfig ipc = (InternalPortletConfig) portletConfigs.get(applicationId + "/" + portletName);
-        if (ipc != null) {
-            return ipc.getPortletDefinition();
-        }
-        LOG.warn("Unable to retrieve portlet descriptor: '"+applicationId+"/"+portletName+"'");
-        return null;
-
-    }
-
-    public PortletAppDD getPortletApplicationDescriptor(String applicationId) throws PortletContainerException {
-        InternalPortletContext ipc = (InternalPortletContext) portletContexts.get(applicationId);
-        if (ipc != null) {
-            return ipc.getPortletApplicationDefinition();
-        }
-        String msg = "Unable to retrieve portlet application descriptor: '"+applicationId+"'"; 
-        LOG.warn(msg);
-        throw new PortletContainerException(msg);
-    }
-
-    public void addPortletRegistryListener(PortletRegistryListener listener) {
-        registryListeners.add(listener);
-    }
-
-    public void removePortletRegistryListener(PortletRegistryListener listener) {
-        registryListeners.remove(listener);
-    }
-
-    private void fireRegistered(InternalPortletContext context) {
-        PortletRegistryEvent event = new PortletRegistryEvent();
-        event.setApplicationId(context.getApplicationId());
-        event.setPortletApplicationDescriptor(context.getPortletApplicationDefinition());
-
-        Iterator i = registryListeners.iterator();
-        while (i.hasNext()) {
-            ((PortletRegistryListener) i.next()).portletApplicationRegistered(event);
-        }
-
-        LOG.info("Portlet Context '" + context.getApplicationId() + "' registered.");
-    }
-
-    private void fireRemoved(InternalPortletContext context) {
-        PortletRegistryEvent event = new PortletRegistryEvent();
-        event.setApplicationId(context.getApplicationId());
-        event.setPortletApplicationDescriptor(context.getPortletApplicationDefinition());
-
-        Iterator i = registryListeners.iterator();
-        while (i.hasNext()) {
-            ((PortletRegistryListener) i.next()).portletApplicationRemoved(event);
-        }
-
-        LOG.info("Portlet Context '" + context.getApplicationId() + "' removed.");
-    }
-
-//
-// Utility
-
-    public static ServletContext getPortletContext(ServletContext portalContext, String portletContextPath) {
-        if (Configuration.preventUnecessaryCrossContext()) {
-            String portalPath = getContextPath(portalContext);
-            if (portalPath.equals(portletContextPath)) {
-                return portalContext;
-            }
-        }
-        return portalContext.getContext(portletContextPath);
-    }
-
-    /**
-     * Servlet 2.5 ServletContext.getContextPath() method.
-     */
-    private static Method contextPathGetter;
-
-    static {
-        try {
-            contextPathGetter = ServletContext.class.getMethod("getContextPath", new Class[0]);
-        }
-        catch (NoSuchMethodException e) {
-            LOG.warn("Servlet 2.4 or below detected.  Unable to find getContextPath on ServletContext.");
-        }
-    }
-
-    protected static String getContextPath(ServletContext context) {
-        String contextPath = null;
-        if (contextPathGetter != null) {
-            try {
-                contextPath = (String) contextPathGetter.invoke(context, new Class[0]);
-            } catch (Exception e) {
-                LOG.warn("Unable to directly retrieve context path from ServletContext. Computing. . . ");
-            }
-        }
-
-        if (contextPath == null) {
-            contextPath = computeContextPath(context);
-        }
-
-        return contextPath;
-    }
-
-
-    protected static String computeContextPath(ServletContext context) {
-        if (APP_ID_RESOLVERS.size() < 1) {
-            List classes = null;
-            try {
-                classes = ClasspathScanner.findConfiguredImplementations(ApplicationIdResolver.class);
-            } catch (IOException e) {
-                throw new RuntimeException("Unable to find any ApplicationIdResolvers");
-            }
-            Iterator i = classes.iterator();
-            while (i.hasNext()) {
-                Class c = (Class) i.next();
-                try {
-                    APP_ID_RESOLVERS.add(c.newInstance());
-                } catch (Exception e) {
-                    LOG.warn("Unable to instantiate ApplicationIdResolver for class " + c.getName());
-                }
-            }
-            if (LOG.isInfoEnabled()) {
-                LOG.info("Found " + APP_ID_RESOLVERS.size() + " application id resolvers.");
-            }
-        }
-
-        String path = null;
-        int authority = Integer.MAX_VALUE;
-
-        Iterator i = APP_ID_RESOLVERS.iterator();
-        while (i.hasNext()) {
-            ApplicationIdResolver resolver = (ApplicationIdResolver) i.next();
-            if (resolver.getAuthority() < authority || path == null) {
-                authority = resolver.getAuthority();
-                String temp = resolver.resolveApplicationId(context);
-                if (temp != null) {
-                    path = temp;
-                }
-            }
-        }
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Resolved application id '" + path + "' with authority " + authority);
-        }
-        return path;
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.descriptors.portlet.PortletAppDD;
+import org.apache.pluto.descriptors.portlet.PortletDD;
+import org.apache.pluto.internal.Configuration;
+import org.apache.pluto.internal.InternalPortletConfig;
+import org.apache.pluto.internal.InternalPortletContext;
+import org.apache.pluto.internal.PortletDescriptorRegistry;
+import org.apache.pluto.internal.impl.PortletConfigImpl;
+import org.apache.pluto.internal.impl.PortletContextImpl;
+import org.apache.pluto.spi.optional.PortletRegistryEvent;
+import org.apache.pluto.spi.optional.PortletRegistryListener;
+import org.apache.pluto.spi.optional.PortletRegistryService;
+import org.apache.pluto.util.ClasspathScanner;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Manager used to cache the portlet configurations which have
+ * been previously parsed.
+ *
+ * @version 1.0
+ * @since Sep 20, 2004
+ */
+public class PortletContextManager implements PortletRegistryService {
+
+    /**
+     * Log Instance
+     */
+    private static final Log LOG = LogFactory.getLog(PortletContextManager.class);
+
+    /**
+     * The singleton manager instance.
+     */
+    private static final PortletContextManager MANAGER = new PortletContextManager();
+
+    /**
+     * List of application id resolvers. *
+     */
+    private static final List APP_ID_RESOLVERS = new ArrayList();
+
+    // Private Member Variables ------------------------------------------------
+
+    /**
+     * The PortletContext cache map: key is servlet context, and value is the
+     * associated portlet context.
+     */
+    private final Map portletContexts = new HashMap();
+
+
+    private final Map portletConfigs = new HashMap();
+
+
+    /**
+     * The registered listeners that should be notified upon
+     * registry events.
+     */
+    private final List registryListeners = new ArrayList();
+
+    // Constructor -------------------------------------------------------------
+
+    /**
+     * Private constructor that prevents external instantiation.
+     */
+    private PortletContextManager() {
+        // Do nothing.
+    }
+
+    /**
+     * Returns the singleton manager instance.
+     *
+     * @return the singleton manager instance.
+     */
+    public static PortletContextManager getManager() {
+        return MANAGER;
+    }
+
+    // Public Methods ----------------------------------------------------------
+
+    /**
+     * Retrieves the PortletContext associated with the given ServletContext.
+     * If one does not exist, it is created.
+     *
+     * @param config the servlet config.
+     * @return the InternalPortletContext associated with the ServletContext.
+     * @throws PortletContainerException
+     */
+    public String register(ServletConfig config) throws PortletContainerException {
+        InternalPortletContext portletContext = register(config.getServletContext());
+
+        PortletAppDD portletAppDD =
+            portletContext.getPortletApplicationDefinition();
+        PortletDD portletDD = null;
+
+        LOG.info("Registering "+portletAppDD.getPortlets().size()+" portlets for context "+portletContext.getApplicationId());
+
+        for (Iterator it = portletAppDD.getPortlets().iterator(); it.hasNext();) {
+            portletDD = (PortletDD) it.next();
+            portletConfigs.put(
+                portletContext.getApplicationId() + "/" + portletDD.getPortletName(),
+                new PortletConfigImpl(config, portletContext, portletDD)
+            );
+        }
+
+        return portletContext.getApplicationId();
+    }
+
+    /**
+     * @param servletContext
+     * @return
+     * @throws PortletContainerException
+     * @deprecated Use {@link #register(ServletConfig)}
+     */
+    public InternalPortletContext register(ServletContext servletContext)
+        throws PortletContainerException {
+        String applicationId = getContextPath(servletContext);
+        if (!portletContexts.containsKey(applicationId)) {
+
+            PortletAppDD portletAppDD = PortletDescriptorRegistry.getRegistry()
+                .getPortletAppDD(servletContext);
+
+            PortletContextImpl portletContext = new PortletContextImpl(
+                applicationId, servletContext, portletAppDD);
+
+            if (portletContext.getApplicationId() == null) {
+                throw new IllegalStateException("Unable to resolve unique identifier for portletContext.");
+            }
+            portletContexts.put(applicationId, portletContext);
+
+            fireRegistered(portletContext);
+
+            if (LOG.isInfoEnabled()) {
+                LOG.info("Registered portlet application with application id '" + applicationId + "'");
+            }
+        } else {
+             if (LOG.isInfoEnabled()) {
+                LOG.info("Portlet application with application id '" + applicationId + "' already registered.");
+            }
+        }
+
+
+        return (InternalPortletContext) portletContexts.get(applicationId);
+    }
+
+    public void remove(InternalPortletContext context) {
+        portletContexts.remove(context.getApplicationId());
+        Iterator configs = portletConfigs.keySet().iterator();
+        while (configs.hasNext()) {
+            String key = (String) configs.next();
+            if (key.startsWith(context.getApplicationId() + "/")) {
+                configs.remove();
+            }
+        }
+        fireRemoved(context);
+    }
+
+    public Iterator getRegisteredPortletApplicationIds() {
+        return new HashSet(portletContexts.keySet()).iterator();
+
+    }
+
+    /**
+     * Retrieve an iterator of all PortletContext instances
+     * which exist within this application.
+     *
+     * @return
+     */
+    public Iterator getRegisteredPortletApplications() {
+        return new HashSet(portletContexts.values()).iterator();
+    }
+
+    public PortletContext getPortletContext(String applicationId)
+        throws PortletContainerException {
+        return (InternalPortletContext) portletContexts.get(applicationId);
+    }
+
+    public PortletConfig getPortletConfig(String applicationId, String portletName) {
+        String lookup = applicationId + "/" + portletName;
+        if(!portletConfigs.containsKey(lookup)) {
+            LOG.info("Unable to locate portlet config [applicationId="+applicationId+"]/["+portletName+"].");
+        }
+        return (InternalPortletConfig) portletConfigs.get(lookup);
+    }
+
+    public PortletDD getPortletDescriptor(String applicationId, String portletName) {
+        InternalPortletConfig ipc = (InternalPortletConfig) portletConfigs.get(applicationId + "/" + portletName);
+        if (ipc != null) {
+            return ipc.getPortletDefinition();
+        }
+        LOG.warn("Unable to retrieve portlet descriptor: '"+applicationId+"/"+portletName+"'");
+        return null;
+
+    }
+
+    public PortletAppDD getPortletApplicationDescriptor(String applicationId) throws PortletContainerException {
+        InternalPortletContext ipc = (InternalPortletContext) portletContexts.get(applicationId);
+        if (ipc != null) {
+            return ipc.getPortletApplicationDefinition();
+        }
+        String msg = "Unable to retrieve portlet application descriptor: '"+applicationId+"'"; 
+        LOG.warn(msg);
+        throw new PortletContainerException(msg);
+    }
+
+    public void addPortletRegistryListener(PortletRegistryListener listener) {
+        registryListeners.add(listener);
+    }
+
+    public void removePortletRegistryListener(PortletRegistryListener listener) {
+        registryListeners.remove(listener);
+    }
+
+    private void fireRegistered(InternalPortletContext context) {
+        PortletRegistryEvent event = new PortletRegistryEvent();
+        event.setApplicationId(context.getApplicationId());
+        event.setPortletApplicationDescriptor(context.getPortletApplicationDefinition());
+
+        Iterator i = registryListeners.iterator();
+        while (i.hasNext()) {
+            ((PortletRegistryListener) i.next()).portletApplicationRegistered(event);
+        }
+
+        LOG.info("Portlet Context '" + context.getApplicationId() + "' registered.");
+    }
+
+    private void fireRemoved(InternalPortletContext context) {
+        PortletRegistryEvent event = new PortletRegistryEvent();
+        event.setApplicationId(context.getApplicationId());
+        event.setPortletApplicationDescriptor(context.getPortletApplicationDefinition());
+
+        Iterator i = registryListeners.iterator();
+        while (i.hasNext()) {
+            ((PortletRegistryListener) i.next()).portletApplicationRemoved(event);
+        }
+
+        LOG.info("Portlet Context '" + context.getApplicationId() + "' removed.");
+    }
+
+//
+// Utility
+
+    public static ServletContext getPortletContext(ServletContext portalContext, String portletContextPath) {
+        if (Configuration.preventUnecessaryCrossContext()) {
+            String portalPath = getContextPath(portalContext);
+            if (portalPath.equals(portletContextPath)) {
+                return portalContext;
+            }
+        }
+        return portalContext.getContext(portletContextPath);
+    }
+
+    /**
+     * Servlet 2.5 ServletContext.getContextPath() method.
+     */
+    private static Method contextPathGetter;
+
+    static {
+        try {
+            contextPathGetter = ServletContext.class.getMethod("getContextPath", new Class[0]);
+        }
+        catch (NoSuchMethodException e) {
+            LOG.warn("Servlet 2.4 or below detected.  Unable to find getContextPath on ServletContext.");
+        }
+    }
+
+    protected static String getContextPath(ServletContext context) {
+        String contextPath = null;
+        if (contextPathGetter != null) {
+            try {
+                contextPath = (String) contextPathGetter.invoke(context, new Class[0]);
+            } catch (Exception e) {
+                LOG.warn("Unable to directly retrieve context path from ServletContext. Computing. . . ");
+            }
+        }
+
+        if (contextPath == null) {
+            contextPath = computeContextPath(context);
+        }
+
+        return contextPath;
+    }
+
+
+    protected static String computeContextPath(ServletContext context) {
+        if (APP_ID_RESOLVERS.size() < 1) {
+            List classes = null;
+            try {
+                classes = ClasspathScanner.findConfiguredImplementations(ApplicationIdResolver.class);
+            } catch (IOException e) {
+                throw new RuntimeException("Unable to find any ApplicationIdResolvers");
+            }
+            Iterator i = classes.iterator();
+            while (i.hasNext()) {
+                Class c = (Class) i.next();
+                try {
+                    APP_ID_RESOLVERS.add(c.newInstance());
+                } catch (Exception e) {
+                    LOG.warn("Unable to instantiate ApplicationIdResolver for class " + c.getName());
+                }
+            }
+            if (LOG.isInfoEnabled()) {
+                LOG.info("Found " + APP_ID_RESOLVERS.size() + " application id resolvers.");
+            }
+        }
+
+        String path = null;
+        int authority = Integer.MAX_VALUE;
+
+        Iterator i = APP_ID_RESOLVERS.iterator();
+        while (i.hasNext()) {
+            ApplicationIdResolver resolver = (ApplicationIdResolver) i.next();
+            if (resolver.getAuthority() < authority || path == null) {
+                authority = resolver.getAuthority();
+                String temp = resolver.resolveApplicationId(context);
+                if (temp != null) {
+                    path = temp;
+                }
+            }
+        }
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Resolved application id '" + path + "' with authority " + authority);
+        }
+        return path;
+    }
+
+}

Propchange: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message