You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-dev@portals.apache.org by dd...@apache.org on 2004/04/02 04:34:28 UTC

cvs commit: jakarta-pluto/sandbox/kuiper/src/java/org/apache/pluto/core PortletConfigFactoryServiceImpl.java PortletRequestFactoryServiceImpl.java PortletResponseFactoryServiceImpl.java ServiceFactoryWrapper.java PlutoContainerImpl.java PortletInvokerServiceImpl.java PortletServlet.java

ddewolf     2004/04/01 18:34:28

  Modified:    sandbox/kuiper/src/java/org/apache/pluto/core
                        PlutoContainerImpl.java
                        PortletInvokerServiceImpl.java PortletServlet.java
  Added:       sandbox/kuiper/src/java/org/apache/pluto/core
                        PortletConfigFactoryServiceImpl.java
                        PortletRequestFactoryServiceImpl.java
                        PortletResponseFactoryServiceImpl.java
                        ServiceFactoryWrapper.java
  Log:
  Adding support for the OptionalServiceFactory (Request and Response Factories, etc. . .)
  
  Revision  Changes    Path
  1.4       +25 -19    jakarta-pluto/sandbox/kuiper/src/java/org/apache/pluto/core/PlutoContainerImpl.java
  
  Index: PlutoContainerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-pluto/sandbox/kuiper/src/java/org/apache/pluto/core/PlutoContainerImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PlutoContainerImpl.java	26 Mar 2004 03:38:45 -0000	1.3
  +++ PlutoContainerImpl.java	2 Apr 2004 02:34:28 -0000	1.4
  @@ -38,9 +38,6 @@
    */
   public class PlutoContainerImpl implements PlutoContainer {
   
  -    // Construction Parameters
  -    private ServiceFactory factory;
  -
       //Service Commonly Used
       private PortletInvokerService invoker;
       private LoggerService loggerService;
  @@ -51,39 +48,49 @@
       // Constructed Internally
       private PortletRegistry registry;
   
  -    public PlutoContainerImpl(ServiceFactory factory) {
  -        this.factory = factory;
  -
  -        this.invoker = this.factory.getPortletInvokerService();
  -        this.loggerService = this.factory.getLoggerService();
  +    /** Constructor used to create the PlutoContainer
  +     *  using only the required services.
  +     *
  +     * @param env
  +     * @param factory
  +     */
  +    public PlutoContainerImpl(PlutoEnvironment env, ServiceFactory factory) {
  +        this(env, new ServiceFactoryWrapper(env, factory));
       }
   
  -    public PlutoContainerImpl(OptionalServiceFactory factory) {
  -        throw new java.lang.UnsupportedOperationException("Not Yet Implemented");
  +    /** Constructor used to create the PlutoContainer
  +     *  using both Required and Optional services.
  +     * @param env
  +     * @param factory
  +     */
  +    public PlutoContainerImpl(PlutoEnvironment env,
  +                              OptionalServiceFactory factory) {
  +        this.env = env;
  +
  +        this.invoker = factory.getPortletInvokerService();
  +        this.loggerService = factory.getLoggerService();
  +
  +        // Initialize the invoker
  +        this.registry = new PortletRegistry(loggerService);
  +        invoker.init(registry);
       }
   
       public String getContainerName() {
           return env.getContainerName();
       }
   
  -    public void init(PlutoEnvironment config) {
  -        this.env = config;
  -        this.registry = new PortletRegistry(loggerService);
  -        invoker.init(config, registry);
  -    }
  -
       public void destroy() {
           this.env = null;
           this.registry = null;
       }
   
       public void start() {
  -
  +        // we don't need to do anything to start
       }
   
   
       public void stop() {
  -
  +        // we don't need to do anything to stop
       }
   
       public void doRender(PortletWindow window,
  @@ -122,5 +129,4 @@
       public PortletRegistry getPortletRegistry() {
           return registry;
       }
  -
   }
  
  
  
  1.4       +22 -29    jakarta-pluto/sandbox/kuiper/src/java/org/apache/pluto/core/PortletInvokerServiceImpl.java
  
  Index: PortletInvokerServiceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-pluto/sandbox/kuiper/src/java/org/apache/pluto/core/PortletInvokerServiceImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PortletInvokerServiceImpl.java	26 Mar 2004 03:38:45 -0000	1.3
  +++ PortletInvokerServiceImpl.java	2 Apr 2004 02:34:28 -0000	1.4
  @@ -21,6 +21,7 @@
   import org.apache.pluto.services.Logger;
   import org.apache.pluto.services.ServiceFactory;
   import org.apache.pluto.services.PortletURLService;
  +import org.apache.pluto.services.OptionalServiceFactory;
   import org.apache.pluto.PortletWindow;
   import org.apache.pluto.PlutoException;
   import org.apache.pluto.PlutoConstants;
  @@ -48,14 +49,14 @@
    * @version 1.0
    * @since Mar 9, 2004 at 10:03:58 AM
    */
  -public class PortletInvokerServiceImpl implements PortletInvokerService {
  -
  -    /** The Environment within which we belong. */
  -    private PlutoEnvironment env;
  +public class PortletInvokerServiceImpl
  +    implements PortletInvokerService {
   
       /** The surrounding Portal's ServletContext.*/
       private ServletContext context;
   
  +    private ServiceFactory factory;
  +
       /** Our logging utility. */
       private Logger logger;
   
  @@ -69,18 +70,17 @@
       private PortletURLService portletURLService;
   
       /** Default Constructor. */
  -    public PortletInvokerServiceImpl(PortletURLService urlService,
  -                                     LoggerService service) {
  -        this.portletURLService = urlService;
  -        this.loggerService = service;
  -        this.logger = service.getLogger(PortletInvokerServiceImpl.class);
  +    public PortletInvokerServiceImpl(PlutoEnvironment env,
  +                                     OptionalServiceFactory factory) {
  +        this.factory = factory;
  +        this.portletURLService = factory.getPortletURLService();
  +        this.loggerService = factory.getLoggerService();
  +        this.logger = loggerService.getLogger(PortletInvokerServiceImpl.class);
  +
  +        context = env.getServletContext();
       }
   
  -    /** Initialize the Invoker with the runtime compontents.
  -      */
  -    public void init(PlutoEnvironment env, PortletRegistry registry) {
  -        this.env = env;
  -        this.context = env.getServletContext();
  +    public void init(PortletRegistry registry) {
           this.registry = registry;
       }
   
  @@ -165,18 +165,8 @@
           );
   
           req.setAttribute(
  -            PlutoConstants.PLUTO_ENVIRONMENT,
  -            env
  -        );
  -
  -        req.setAttribute(
  -            PlutoConstants.LOGGER_SERVICE,
  -            loggerService
  -        );
  -
  -        req.setAttribute(
  -            PlutoConstants.PORTLET_URL_SERVICE,
  -            portletURLService
  +            PlutoConstants.SERVICE_FACTORY,
  +            factory
           );
   
           try {
  @@ -187,6 +177,11 @@
               disp.include(req,res);
               if(logger.isDebugEnabled()) {
                   logger.debug("Invokation complete");
  +                logger.debug("RenderParameters: "+
  +                             req.getAttribute(
  +                                 PlutoConstants.RENDER_PARAMETERS
  +                             )
  +                );
               }
           }
           catch(javax.servlet.UnavailableException ue) {
  @@ -217,9 +212,7 @@
               req.removeAttribute(PlutoConstants.REQUEST_METHOD);
               req.removeAttribute(PlutoConstants.PORTLET_WINDOW);
               req.removeAttribute(PlutoConstants.PORTLET_REGISTRY);
  -            req.removeAttribute(PlutoConstants.PLUTO_ENVIRONMENT);
  -            req.removeAttribute(PlutoConstants.LOGGER_SERVICE);
  -            req.removeAttribute(PlutoConstants.PORTLET_URL_SERVICE);
  +            req.removeAttribute(PlutoConstants.SERVICE_FACTORY);
           }
       }
   }
  
  
  
  1.4       +36 -23    jakarta-pluto/sandbox/kuiper/src/java/org/apache/pluto/core/PortletServlet.java
  
  Index: PortletServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-pluto/sandbox/kuiper/src/java/org/apache/pluto/core/PortletServlet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PortletServlet.java	26 Mar 2004 03:38:45 -0000	1.3
  +++ PortletServlet.java	2 Apr 2004 02:34:28 -0000	1.4
  @@ -18,16 +18,11 @@
   
   import org.apache.pluto.PlutoConstants;
   import org.apache.pluto.PlutoException;
  -import org.apache.pluto.PlutoEnvironment;
   import org.apache.pluto.PortletWindow;
   import org.apache.pluto.services.Logger;
   import org.apache.pluto.services.LoggerService;
  -import org.apache.pluto.services.PortletURLService;
  +import org.apache.pluto.services.OptionalServiceFactory;
   import org.apache.pluto.impl.PortletContextImpl;
  -import org.apache.pluto.impl.ActionRequestImpl;
  -import org.apache.pluto.impl.ActionResponseImpl;
  -import org.apache.pluto.impl.RenderRequestImpl;
  -import org.apache.pluto.impl.RenderResponseImpl;
   import org.apache.pluto.binding.PortletDD;
   import org.apache.pluto.binding.XMLBinding;
   import org.apache.pluto.binding.PortletAppDD;
  @@ -38,6 +33,7 @@
   import javax.servlet.ServletException;
   import javax.portlet.*;
   import java.io.IOException;
  +import java.util.Map;
   
   /** <P>Servlet used by the PlutoContainer to interact with and
    *  invoke a portlet application.  The PortletServlet is a thin
  @@ -200,11 +196,13 @@
                              HttpServletResponse response)
       throws ServletException, IOException, PortletException, PlutoException {
   
  +        OptionalServiceFactory factory = (OptionalServiceFactory)
  +            request.getAttribute(PlutoConstants.SERVICE_FACTORY);
  +
           PortletRegistry registry = (PortletRegistry)
               request.getAttribute(PlutoConstants.PORTLET_REGISTRY);
   
  -        LoggerService loggerService = (LoggerService)
  -            request.getAttribute(PlutoConstants.LOGGER_SERVICE);
  +        LoggerService loggerService = factory.getLoggerService();
   
           if(registry==null || loggerService==null) {
               throw new ServletException("Invalid Invocation.  This servlet"
  @@ -216,15 +214,9 @@
               initInternal(registry, loggerService);
           }
   
  -        PortletURLService portletURLService = (PortletURLService)
  -            request.getAttribute(PlutoConstants.PORTLET_URL_SERVICE);
  -
           PortletWindow window = (PortletWindow)
               request.getAttribute(PlutoConstants.PORTLET_WINDOW);
   
  -        PlutoEnvironment plutoEnvironment = (PlutoEnvironment)
  -            request.getAttribute(PlutoConstants.PLUTO_ENVIRONMENT);
  -
           String method = (String)
               request.getAttribute(PlutoConstants.REQUEST_METHOD);
   
  @@ -252,29 +244,50 @@
   
           if(PlutoConstants.ACTION_REQUEST.equals(method)) {
               ActionRequest requ =
  -                new ActionRequestImpl(plutoEnvironment, portletContext,
  -                                      window, request);
  +                factory.getRequestFactoryService()
  +                    .createActionRequest(request, response,
  +                                         portletContext, window
  +                    );
   
  +            Map renderParameters = new java.util.HashMap();
               ActionResponse resp =
  -                new ActionResponseImpl(window, response);
  +                factory.getResponseFactoryService()
  +                    .createActionResponse(request, response,
  +                                          portletContext, window,
  +                                          renderParameters
  +                    );
   
               // Do we need to set attributes here too? or just render?
  -
               if(logger.isInfoEnabled()) {
                   logger.info("Invoking portlet action: "
                               +config.getPortletName());
               }
               portlet.processAction(requ,resp);
  +
  +            request.setAttribute(
  +                PlutoConstants.RENDER_PARAMETERS,
  +                renderParameters
  +            );
           }
  +
           else if(PlutoConstants.RENDER_REQUEST.equals(method)) {
  +            Map renderParameters = (Map)
  +                request.getAttribute(PlutoConstants.RENDER_PARAMETERS);
  +            // null is ok - it means action wasn't done
  +
               RenderRequest requ =
  -                new RenderRequestImpl(plutoEnvironment, portletContext,
  -                                      window, request);
  +                factory.getRequestFactoryService()
  +                    .createRenderRequest(request, response,
  +                                         portletContext, window,
  +                                         renderParameters
  +                    );
   
               RenderResponse resp =
  -                new RenderResponseImpl(window, request,
  -                                       response,
  -                                       portletURLService);
  +                factory.getResponseFactoryService()
  +                    .createRenderResponse(request, response,
  +                                          portletContext, window
  +
  +                    );
   
               request.setAttribute(
                   PlutoConstants.PORTLET_REQUEST,
  
  
  
  1.1                  jakarta-pluto/sandbox/kuiper/src/java/org/apache/pluto/core/PortletConfigFactoryServiceImpl.java
  
  Index: PortletConfigFactoryServiceImpl.java
  ===================================================================
  /*
   * Copyright 2003,2004 The Apache Software Foundation.
   * 
   * Licensed 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.pluto.services.PortletConfigFactoryService;
  import org.apache.pluto.impl.PortletConfigImpl;
  
  import javax.portlet.PortletConfig;
  import javax.portlet.PortletContext;
  import javax.servlet.ServletConfig;
  import java.util.ResourceBundle;
  import java.util.Map;
  
  /**
   * <B>TODO</B>: Document
   * 
   * @author <A href="mailto:david.dewolf@vivare.com">David H. DeWolf</A>
   * @version 1.0
   * @since Mar 29, 2004 at 9:59:41 AM
   */
  public class PortletConfigFactoryServiceImpl 
      implements PortletConfigFactoryService {
      
      public PortletConfig createPortletConfig(String portletId,
                                               PortletContext context,
                                               ResourceBundle bundle,
                                               Map map) {
          return new PortletConfigImpl(portletId, context, bundle, map);
      }
  }
  
  
  
  1.1                  jakarta-pluto/sandbox/kuiper/src/java/org/apache/pluto/core/PortletRequestFactoryServiceImpl.java
  
  Index: PortletRequestFactoryServiceImpl.java
  ===================================================================
  /*
   * Copyright 2003,2004 The Apache Software Foundation.
   * 
   * Licensed 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.pluto.services.PortletRequestFactoryService;
  import org.apache.pluto.PortletWindow;
  import org.apache.pluto.PlutoEnvironment;
  import org.apache.pluto.impl.RenderRequestImpl;
  import org.apache.pluto.impl.ActionRequestImpl;
  import org.apache.pluto.impl.LoadRequestImpl;
  
  import javax.portlet.RenderRequest;
  import javax.portlet.ActionRequest;
  import javax.portlet.PortletRequest;
  import javax.portlet.PortletContext;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.util.Map;
  
  /**
   * <B>TODO</B>: Document
   * 
   * @author <A href="mailto:david.dewolf@vivare.com">David H. DeWolf</A>
   * @version 1.0
   * @since Mar 29, 2004 at 9:12:48 AM
   */
  public class PortletRequestFactoryServiceImpl
      implements PortletRequestFactoryService {
  
      private PlutoEnvironment env;
  
      public PortletRequestFactoryServiceImpl(PlutoEnvironment env) {
          this.env = env;
      }
  
      public RenderRequest createRenderRequest(HttpServletRequest req,
                                               HttpServletResponse res,
                                               PortletContext context,
                                               PortletWindow window,
                                               Map renderParameters) {
          return new RenderRequestImpl(env, context, window, req, renderParameters);
      }
  
      public ActionRequest createActionRequest(HttpServletRequest req,
                                               HttpServletResponse res,
                                               PortletContext context,
                                               PortletWindow window) {
          return new ActionRequestImpl(env, context, window, req);
      }
  
      public PortletRequest createLoadRequest(HttpServletRequest req,
                                              HttpServletResponse res,
                                              PortletContext context,
                                              PortletWindow window) {
          return new LoadRequestImpl(env, context, window, req);
      }
  
  }
  
  
  
  1.1                  jakarta-pluto/sandbox/kuiper/src/java/org/apache/pluto/core/PortletResponseFactoryServiceImpl.java
  
  Index: PortletResponseFactoryServiceImpl.java
  ===================================================================
  /*
   * Copyright 2003,2004 The Apache Software Foundation.
   * 
   * Licensed 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.pluto.services.PortletResponseFactoryService;
  import org.apache.pluto.services.PortletURLService;
  import org.apache.pluto.PortletWindow;
  import org.apache.pluto.impl.RenderResponseImpl;
  import org.apache.pluto.impl.ActionResponseImpl;
  import org.apache.pluto.impl.LoadResponseImpl;
  
  import javax.portlet.RenderResponse;
  import javax.portlet.ActionResponse;
  import javax.portlet.PortletResponse;
  import javax.portlet.PortletContext;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpServletRequest;
  import java.util.Map;
  
  /**
   * <B>TODO</B>: Document
   * 
   * @author <A href="mailto:david.dewolf@vivare.com">David H. DeWolf</A>
   * @version 1.0
   * @since Mar 29, 2004 at 9:51:13 AM
   */
  public class PortletResponseFactoryServiceImpl implements
          PortletResponseFactoryService{
  
      private PortletURLService service;
      public PortletResponseFactoryServiceImpl(PortletURLService url) {
          this.service = url;
      }
  
      public RenderResponse createRenderResponse(HttpServletRequest req,
                                                 HttpServletResponse res,
                                                 PortletContext context,
                                                 PortletWindow window) {
          return new RenderResponseImpl(window, req, res, service);
      }
  
      public ActionResponse createActionResponse(HttpServletRequest req,
                                                 HttpServletResponse res,
                                                 PortletContext context,
                                                 PortletWindow window,
                                                 Map renderParameterStorage) {
          return new ActionResponseImpl(window, res, renderParameterStorage);
      }
  
      public PortletResponse createLoadResponse(HttpServletRequest req,
                                                HttpServletResponse res,
                                                PortletContext context,
                                                PortletWindow window) {
          return new LoadResponseImpl(res);
      }
  }
  
  
  
  1.1                  jakarta-pluto/sandbox/kuiper/src/java/org/apache/pluto/core/ServiceFactoryWrapper.java
  
  Index: ServiceFactoryWrapper.java
  ===================================================================
  /*
   * Copyright 2003,2004 The Apache Software Foundation.
   * 
   * Licensed 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.pluto.services.OptionalServiceFactory;
  import org.apache.pluto.services.PortletInvokerService;
  import org.apache.pluto.services.PortletRequestFactoryService;
  import org.apache.pluto.services.PortletResponseFactoryService;
  import org.apache.pluto.services.PortletConfigFactoryService;
  import org.apache.pluto.services.ServiceFactory;
  import org.apache.pluto.services.LoggerService;
  import org.apache.pluto.services.PortletURLService;
  import org.apache.pluto.PlutoEnvironment;
  
  /**
   * <B>TODO</B>: Document
   * 
   * @author <A href="mailto:david.dewolf@vivare.com">David H. DeWolf</A>
   * @version 1.0
   * @since Mar 29, 2004 at 9:06:05 AM
   */
  public class ServiceFactoryWrapper implements OptionalServiceFactory {
  
      private LoggerService loggerService;
      private PortletURLService portletURLService;
  
      // Created Services
      private PortletInvokerService invokerService;
      private PortletRequestFactoryService requestFactory;
      private PortletResponseFactoryService responseFactory;
      private PortletConfigFactoryService portletConfigFactory;
  
      public ServiceFactoryWrapper(PlutoEnvironment env,
                                   ServiceFactory factory) {
          this.loggerService = factory.getLoggerService();
          this.portletURLService = factory.getPortletURLService();
  
          // Create Optional Services
          this.requestFactory =
              new PortletRequestFactoryServiceImpl(
                  env
              );
  
          this.responseFactory =
              new PortletResponseFactoryServiceImpl(
                  factory.getPortletURLService()
              );
  
          this.portletConfigFactory =
              new PortletConfigFactoryServiceImpl();
  
          // This must be created last
          this.invokerService =
                  new PortletInvokerServiceImpl(
                      env, this
                  );
      }
  
      public LoggerService getLoggerService() {
          return loggerService;
      }
  
      public PortletURLService getPortletURLService() {
          return portletURLService;
      }
  
      public PortletInvokerService getPortletInvokerService() {
          return this.invokerService;
      }
  
      public PortletRequestFactoryService getRequestFactoryService() {
          return this.requestFactory;
      }
  
      public PortletResponseFactoryService getResponseFactoryService() {
          return this.responseFactory;
      }
  
      public PortletConfigFactoryService getPortletConfigFactoryService() {
          return this.portletConfigFactory;
      }
  }