Hi Ate,

I came up with the attached patch last week while on a plane, to factor out the dependency on PCM. Hopefully you'll find it useful, if not the code, the idea.

Have fun at apachecon, which I could be there.

Best,
E

[EMAIL PROTECTED] wrote:
Author: ate
Date: Tue Apr  8 07:14:34 2008
New Revision: 645936

URL: http://svn.apache.org/viewvc?rev=645936&view=rev
Log:
Branch for refactoring the Pluto 2.0 SPI interfaces and services to make it 
proper embeddable in larger Portals like Jetspeed-2.
Target is to bring flexibility of Pluto 1.0.x back while maintaining the easier 
to use SPI of Pluto 1.1.x/2.0

Added:
    portals/pluto/branches/2.0-spi-refactoring/
      - copied from r645935, portals/pluto/trunk/
Index: 
pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java
===================================================================
--- 
pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java   
    (revision 641319)
+++ 
pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java   
    (working copy)
@@ -61,6 +61,7 @@
 import org.apache.pluto.spi.FilterManager;
 import org.apache.pluto.spi.PortletURLProvider;
 import org.apache.pluto.spi.optional.PortletInvokerService;
+import org.apache.pluto.spi.optional.PortletRegistryService;
 import org.apache.pluto.internal.impl.EventRequestImpl;
 import org.apache.pluto.internal.impl.EventResponseImpl;
 import org.apache.pluto.internal.impl.InternalPortletWindowImpl;
@@ -654,7 +655,7 @@
         * @throws PortletContainerException
         */
        private FilterManager filterInitialisation(InternalPortletWindow 
internalPortletWindow,String lifeCycle) throws PortletContainerException{
-       PortletAppDD portletAppDD = 
getOptionalContainerServices().getPortletRegistryService().getPortletApplicationDescriptor(internalPortletWindow.getContextPath());
+       PortletAppDD portletAppDD = 
getOptionalContainerServices().getPortletRegistryService().getPortletApplicationDescriptor(internalPortletWindow.getContextPath());
        
         String portletName = internalPortletWindow.getPortletName();
         
         return 
requiredContainerServices.getPortalCallbackService().getFilterManager(portletAppDD,portletName,lifeCycle);
Index: 
pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java
===================================================================
--- 
pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java  
    (revision 641319)
+++ 
pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java  
    (working copy)
@@ -29,9 +29,9 @@
 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.spi.optional.WritablePortletRegistry;
 import org.apache.pluto.util.ClasspathScanner;
- 
+
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletContext;
 import javax.servlet.ServletConfig;
@@ -52,7 +52,8 @@
  * @version 1.0
  * @since Sep 20, 2004
  */
-public class PortletContextManager implements PortletRegistryService {
+public class PortletContextManager implements WritablePortletRegistry
+{
 
        /**
      * Log Instance
@@ -61,14 +62,15 @@
 
     /**
      * The singleton manager instance.
+     * @deprecated
      */
-    private static final PortletContextManager MANAGER = new 
PortletContextManager();
+    private static PortletContextManager MANAGER = null;
     
     /**
      * The PortletContext cache map: key is servlet context, and value is the
      * associated portlet context.
      */
-    private Map portletContexts = new HashMap();
+    private static Map portletContexts = new HashMap();
 
     /**
      * List of application id resolvers. *
@@ -82,34 +84,39 @@
      * The PortletContext cache map: key is servlet context, and value is the
      * associated portlet context.
      */
-    private final Map portletConfigs = new HashMap();
+    private static final Map portletConfigs = new HashMap();
 
 
     /**
      * The registered listeners that should be notified upon
      * registry events.
      */
-    private final List registryListeners = new ArrayList();
+    private static final List registryListeners = new ArrayList();
 
     /**
      * The classloader for the portal, key is portletWindow and value is the 
classloader.
      */
-    private final Map classLoaders = new HashMap();
+    private static final Map classLoaders = new HashMap();
     
     // Constructor 
-------------------------------------------------------------
     
     /**
-     * Private constructor that prevents external instantiation.
+     * Protected constructor
      */
-    private PortletContextManager() {
-       // Do nothing.
+    PortletContextManager() {
+       MANAGER = this;
     }
 
     /**
      * Returns the singleton manager instance.
      * @return the singleton manager instance.
+     * @deprecated 
      */
-    public static PortletContextManager getManager() {
+    public synchronized static PortletContextManager getManager() {
+        if ( MANAGER == null )
+        {
+            new PortletContextManager();            
+        }
         return MANAGER;
     }
     
Index: pluto-container/src/main/java/org/apache/pluto/core/PortletServlet.java
===================================================================
--- pluto-container/src/main/java/org/apache/pluto/core/PortletServlet.java     
(revision 641319)
+++ pluto-container/src/main/java/org/apache/pluto/core/PortletServlet.java     
(working copy)
@@ -41,7 +41,6 @@
 import org.apache.pluto.internal.impl.ActionResponseImpl;
 import org.apache.pluto.internal.impl.EventRequestImpl;
 import org.apache.pluto.internal.impl.EventResponseImpl;
-import org.apache.pluto.internal.impl.PortletConfigImpl;
 import org.apache.pluto.internal.impl.RenderRequestImpl;
 import org.apache.pluto.internal.impl.RenderResponseImpl;
 import org.apache.pluto.internal.impl.ResourceRequestImpl;
@@ -51,6 +50,7 @@
 import org.apache.pluto.spi.optional.PortalAdministrationService;
 import org.apache.pluto.spi.optional.PortletInvocationEvent;
 import org.apache.pluto.spi.optional.PortletInvocationListener;
+import org.apache.pluto.spi.optional.WritablePortletRegistry;
 
 /**
  * Portlet Invocation Servlet. This servlet recieves cross context requests 
from
@@ -88,7 +88,10 @@
     private EventPortlet eventPortlet = null;
     
     /** The resource serving portlet instance wrapped by this servlet. */
-    private ResourceServingPortlet resourceServingPortlet = null;        
+    private ResourceServingPortlet resourceServingPortlet = null;
+
+    /** The portlet registry this Servlet registers itself with */
+    private WritablePortletRegistry portletRegistry = null;
     
     // HttpServlet Impl 
--------------------------------------------------------
     
@@ -107,13 +110,29 @@
        
        // Retrieve portlet name as defined as an initialization parameter.
         portletName = getInitParameter("portlet-name");
-        
+
         // Retrieve the associated internal portlet context.
-        PortletContextManager mgr = PortletContextManager.getManager();
+        try
+        {
+            java.util.List managers = 
org.apache.pluto.util.ClasspathScanner.findConfiguredImplementations( 
WritablePortletRegistry.class );
+            if ( managers == null || managers.isEmpty() )
+            {
+                throw new ServletException( "Could not resolve a 
WritablePortletRegistry implementation!  " +
+                        "Ensure that pluto.properties (typically packaged in 
the Pluto Container jar) " +
+                        "defines a property named '" + 
WritablePortletRegistry.class.getName() + "'" );
+            }
+
+            this.portletRegistry = (WritablePortletRegistry) 
((Class)managers.iterator().next()).newInstance();
+        }
+        catch ( Exception e )
+        {
+            throw new ServletException( "Could not resolve a 
WritablePortletRegistry implementation: " + e.getMessage() );
+        }
+
         try {
-            String applicationId = mgr.register(getServletConfig());
-            portletContext = (InternalPortletContext) 
mgr.getPortletContext(applicationId);
-            portletConfig = (InternalPortletConfig) 
mgr.getPortletConfig(applicationId, portletName);
+            String applicationId = 
portletRegistry.register(getServletConfig());
+            portletContext = (InternalPortletContext) 
portletRegistry.getPortletContext(applicationId);
+            portletConfig = (InternalPortletConfig) 
portletRegistry.getPortletConfig(applicationId, portletName);
 
         } catch (PortletContainerException ex) {
             throw new ServletException(ex);
@@ -145,7 +164,12 @@
     }
 
     public void destroy() {
-        PortletContextManager.getManager().remove(portletContext);
+        try {
+            portletRegistry.remove(portletContext);
+        } catch ( PortletContainerException e ) {
+            // don't care          
+        }
+
         if (portlet != null) {
             portlet.destroy();
         }
Index: 
pluto-container/src/main/java/org/apache/pluto/spi/optional/WritablePortletRegistry.java
===================================================================
--- 
pluto-container/src/main/java/org/apache/pluto/spi/optional/WritablePortletRegistry.java
    (revision 0)
+++ 
pluto-container/src/main/java/org/apache/pluto/spi/optional/WritablePortletRegistry.java
    (revision 0)
@@ -0,0 +1,30 @@
+package org.apache.pluto.spi.optional;
+
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.internal.InternalPortletContext;
+
+import javax.servlet.ServletConfig;
+
+/**                                      
+ * Extension of the PortletRegistryService, allowing portlets to be registered.
+ */
+public interface WritablePortletRegistry extends PortletRegistryService
+{
+    /**
+     * Registers the portlet application associated with the provided
+     * <code>config</code>
+     *
+     * @param config portlet ServletConfig
+     * @return the portlet application identifier
+     */
+    public String register( ServletConfig config ) throws 
PortletContainerException;
+
+    /**
+     * Removes the portlet application associated with the provided
+     * <code>portletCtx</code>.
+     *
+     * @param portletCtx
+     * @throws PortletContainerException
+     */
+    public void remove( InternalPortletContext portletCtx ) throws 
PortletContainerException;
+}

Property changes on: 
pluto-container/src/main/java/org/apache/pluto/spi/optional/WritablePortletRegistry.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Index: pluto-container/src/main/resources/META-INF/pluto.properties
===================================================================
--- pluto-container/src/main/resources/META-INF/pluto.properties        
(revision 641319)
+++ pluto-container/src/main/resources/META-INF/pluto.properties        
(working copy)
@@ -35,3 +35,6 @@
 
org.apache.pluto.core.ApplicationIdResolver=org.apache.pluto.core.DefaultApplicationIdResolver,\
   org.apache.pluto.core.InitParameterApplicationIdResolver,\
   org.apache.pluto.core.AttributeApplicationIdResolver
+
+org.apache.pluto.spi.optional.PortletRegistry=org.apache.pluto.core.PortletContextManager
+org.apache.pluto.spi.optional.WritablePortletRegistry=org.apache.pluto.core.PortletContextManager

Reply via email to