portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager PortletApplicationManager.java
Date Wed, 02 Mar 2005 02:48:12 GMT
ate         2005/03/01 18:48:12

  Modified:    portal/src/java/org/apache/jetspeed/request Tag:
                        deployment-refactoring JetspeedRequestContext.java
                        JetspeedRequestContextComponent.java
               portal/src/java/org/apache/jetspeed/container/invoker Tag:
                        deployment-refactoring JetspeedPortletInvoker.java
                        ServletPortletInvoker.java
                        PortletInvokerFactoryImpl.java
                        LocalPortletInvoker.java
               portal/src/java/org/apache/jetspeed/tools/pamanager Tag:
                        deployment-refactoring
                        PortletApplicationManager.java
  Log:
  New portlet container access and invokation implementation
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.37.2.1  +1 -6      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java
  
  Index: JetspeedRequestContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java,v
  retrieving revision 1.37
  retrieving revision 1.37.2.1
  diff -u -r1.37 -r1.37.2.1
  --- JetspeedRequestContext.java	27 Jan 2005 21:27:51 -0000	1.37
  +++ JetspeedRequestContext.java	2 Mar 2005 02:48:11 -0000	1.37.2.1
  @@ -36,7 +36,6 @@
   import org.apache.jetspeed.container.url.PortalURL;
   import org.apache.jetspeed.engine.servlet.ServletRequestFactory;
   import org.apache.jetspeed.engine.servlet.ServletResponseFactory;
  -import org.apache.jetspeed.factory.PortletFactory;
   import org.apache.jetspeed.om.common.MutableLanguage;
   import org.apache.jetspeed.om.impl.LanguageImpl;
   import org.apache.jetspeed.om.page.Fragment;
  @@ -47,7 +46,6 @@
   import org.apache.pluto.om.common.LanguageSet;
   import org.apache.pluto.om.common.ObjectID;
   import org.apache.pluto.om.portlet.PortletDefinition;
  -import org.apache.pluto.om.portlet.PortletDefinitionCtrl;
   import org.apache.pluto.om.window.PortletWindow;
   
   /**
  @@ -86,7 +84,6 @@
       private Fragment rootFragment;
       private Map fragments;
       private JetspeedPowerTool jpt;
  -    private PortletFactory portletFactory;
   
       /**
        * Create a new Request Context
  @@ -97,7 +94,7 @@
        * @param config
        */
       public JetspeedRequestContext( HttpServletRequest request, HttpServletResponse response, ServletConfig config,
  -            UserInfoManager userInfoMgr, PortletFactory portletFactory )
  +            UserInfoManager userInfoMgr )
       {
           this.request = request;
           this.response = response;
  @@ -106,7 +103,6 @@
           this.requestsForWindows = new HashMap();
           this.responsesForWindows = new HashMap();
           this.fragments = new LinkedHashMap();
  -        this.portletFactory = portletFactory;
   
           // set context in Request for later use
           if (null != this.request)
  @@ -494,7 +490,6 @@
           // {
           //     return language;
           // }
  -        ((PortletDefinitionCtrl) portlet).setPortletClassLoader(portletFactory.getPortletClassLoader(portlet));
           LanguageSet languageSet = portlet.getLanguageSet();
           Language language = languageSet.get(locale);
   
  
  
  
  1.10.2.1  +4 -8      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContextComponent.java
  
  Index: JetspeedRequestContextComponent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContextComponent.java,v
  retrieving revision 1.10
  retrieving revision 1.10.2.1
  diff -u -r1.10 -r1.10.2.1
  --- JetspeedRequestContextComponent.java	27 Jan 2005 21:27:52 -0000	1.10
  +++ JetspeedRequestContextComponent.java	2 Mar 2005 02:48:11 -0000	1.10.2.1
  @@ -25,7 +25,6 @@
   import org.apache.commons.logging.LogFactory;
   
   import org.apache.jetspeed.PortalReservedParameters;
  -import org.apache.jetspeed.factory.PortletFactory;
   import org.apache.jetspeed.userinfo.UserInfoManager;
   
   /**
  @@ -43,18 +42,16 @@
       private ThreadLocal tlRequestContext = new ThreadLocal();
   
       private final static Log log = LogFactory.getLog(JetspeedRequestContextComponent.class);
  -    private PortletFactory portletFactory;
   
       public JetspeedRequestContextComponent(String contextClassName)
       {
       }
   
       public JetspeedRequestContextComponent(String contextClassName, 
  -                                           UserInfoManager userInfoMgr, PortletFactory portletFactory)
  +                                           UserInfoManager userInfoMgr)
       {
           this.contextClassName = contextClassName;
           this.userInfoMgr = userInfoMgr;
  -        this.portletFactory = portletFactory;
       }
   
       public RequestContext create(HttpServletRequest req, HttpServletResponse resp, ServletConfig config)
  @@ -75,9 +72,8 @@
                           HttpServletRequest.class,
                           HttpServletResponse.class,
                           ServletConfig.class,
  -                        UserInfoManager.class,
  -                        PortletFactory.class});
  -            context = (RequestContext) constructor.newInstance(new Object[] { req, resp, config, userInfoMgr, portletFactory });
  +                        UserInfoManager.class});
  +            context = (RequestContext) constructor.newInstance(new Object[] { req, resp, config, userInfoMgr});
   
           }
           catch (Exception e)
  
  
  
  No                   revision
  No                   revision
  1.4.4.1   +6 -3      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/JetspeedPortletInvoker.java
  
  Index: JetspeedPortletInvoker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/JetspeedPortletInvoker.java,v
  retrieving revision 1.4
  retrieving revision 1.4.4.1
  diff -u -r1.4 -r1.4.4.1
  --- JetspeedPortletInvoker.java	8 Mar 2004 00:23:31 -0000	1.4
  +++ JetspeedPortletInvoker.java	2 Mar 2005 02:48:11 -0000	1.4.4.1
  @@ -17,6 +17,7 @@
   
   import javax.servlet.ServletConfig;
   
  +import org.apache.jetspeed.factory.PortletFactory;
   import org.apache.pluto.invoker.PortletInvoker;
   import org.apache.pluto.om.portlet.PortletDefinition;
   
  @@ -34,23 +35,25 @@
        * Activating an invoker makes it ready to invoke portlets.
        * If an invoker's state is not activated, it can not invoke.
        * 
  +     * @param portletFactory The factory to get access to the portlet being invoked.
        * @param portletDefinition The portlet's definition that is being invoked.
        * @param servletConfig The servlet configuration of the portal. 
        * @param containerServlet
        */
  -    void activate(PortletDefinition portletDefinition, ServletConfig servletConfig);
  +    void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig);
   
       /**
        * Activating an invoker makes it ready to invoke portlets.
        * If an invoker's state is not activated, it can not invoke.
        * This second signature allows for activating with an extra property.
        * 
  +     * @param portletFactory The factory to get access to the portlet being invoked.
        * @param portletDefinition The portlet's definition that is being invoked.
        * @param servletConfig The servlet configuration of the portal. 
        * @param property Implementation specific property
        * @param containerServlet
        */
  -    void activate(PortletDefinition portletDefinition, ServletConfig servletConfig, String property);
  +    void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig, String property);
       
       /**
        * Passivates an invoker, freeing it back to the invoker pool.
  
  
  
  1.18.2.1  +24 -28    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java
  
  Index: ServletPortletInvoker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/ServletPortletInvoker.java,v
  retrieving revision 1.18
  retrieving revision 1.18.2.1
  diff -u -r1.18 -r1.18.2.1
  --- ServletPortletInvoker.java	4 Feb 2005 17:25:20 -0000	1.18
  +++ ServletPortletInvoker.java	2 Mar 2005 02:48:11 -0000	1.18.2.1
  @@ -19,8 +19,6 @@
   
   import javax.portlet.ActionRequest;
   import javax.portlet.ActionResponse;
  -import javax.portlet.PortletConfig;
  -import javax.portlet.PortletContext;
   import javax.portlet.PortletException;
   import javax.portlet.PortletRequest;
   import javax.portlet.PortletResponse;
  @@ -36,11 +34,11 @@
   import org.apache.commons.logging.LogFactory;
   import org.apache.jetspeed.PortalReservedParameters;
   import org.apache.jetspeed.container.ContainerConstants;
  -import org.apache.jetspeed.container.PortletContextFactory;
  -import org.apache.jetspeed.factory.JetspeedPortletFactoryProxy;
  +import org.apache.jetspeed.factory.PortletFactory;
  +import org.apache.jetspeed.factory.PortletInstance;
   import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
  +import org.apache.jetspeed.om.common.portlet.PortletApplication;
   import org.apache.jetspeed.request.RequestContext;
  -import org.apache.pluto.core.impl.PortletConfigImpl;
   import org.apache.pluto.om.portlet.PortletDefinition;
   import org.apache.pluto.om.servlet.WebApplicationDefinition;
   
  @@ -68,6 +66,7 @@
   {
       private final static Log log = LogFactory.getLog(ServletPortletInvoker.class);
   
  +    protected PortletFactory portletFactory;
       protected ServletContext jetspeedContext;
       protected ServletConfig jetspeedConfig;
       protected PortletDefinition portletDefinition;
  @@ -93,10 +92,11 @@
       }
   
       /* (non-Javadoc)
  -     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(org.apache.pluto.om.portlet.PortletDefinition, javax.servlet.ServletConfig)
  +     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(PortletFactory,org.apache.pluto.om.portlet.PortletDefinition, javax.servlet.ServletConfig)
        */
  -    public void activate(PortletDefinition portletDefinition, ServletConfig servletConfig)
  +    public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig)
       {
  +        this.portletFactory = portletFactory;
           this.jetspeedConfig = servletConfig;
           jetspeedContext = servletConfig.getServletContext();
           this.portletDefinition = portletDefinition;
  @@ -104,16 +104,14 @@
       }
   
       /* (non-Javadoc)
  -     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(org.apache.pluto.om.portlet.PortletDefinition, javax.servlet.ServletConfig, java.lang.String)
  +     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(PortletFactory,org.apache.pluto.om.portlet.PortletDefinition, javax.servlet.ServletConfig, java.lang.String)
        */
  -    public void activate(PortletDefinition portletDefinition, ServletConfig servletConfig, String servletMappingName)
  +    public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig, String servletMappingName)
       {
           this.servletMappingName = servletMappingName;
  -        activate(portletDefinition, servletConfig);
  +        activate(portletFactory, portletDefinition, servletConfig);
       }
   
  -
  -
       /**
        *
        * @param request
  @@ -144,7 +142,7 @@
           }
           catch (IOException e)
           {
  -            log.error("PortletInvokerImpl.load() - Error while dispatching portlet.", e);
  +            log.error("ServletPortletInvokerImpl.load() - Error while dispatching portlet.", e);
               throw new PortletException(e);
           }
       }
  @@ -163,6 +161,8 @@
       protected void invoke(PortletRequest portletRequest, PortletResponse portletResponse, Integer methodID)
           throws PortletException, IOException
       {
  +        ClassLoader paClassLoader = portletFactory.getPortletApplicationClassLoader((PortletApplication)portletDefinition.getPortletApplicationDefinition());
  +
           MutablePortletApplication app = (MutablePortletApplication)portletDefinition.getPortletApplicationDefinition();
   
           WebApplicationDefinition webApplicationDefinition = app.getWebApplicationDefinition();
  @@ -184,7 +184,6 @@
               log.error(message);
               throw new PortletException(message);
           }
  -
           RequestDispatcher dispatcher = appContext.getRequestDispatcher(servletMappingName);
           if (null == dispatcher)
           {
  @@ -199,19 +198,15 @@
   
           try
           {
  -            PortletContext portletContext = PortletContextFactory.createPortletContext(appContext, app);            
  -            PortletConfig portletConfig = new PortletConfigImpl(this.jetspeedConfig, portletContext, portletDefinition);
  -            
  -            servletRequest.setAttribute(ContainerConstants.METHOD_ID, methodID);
  -
  +            PortletInstance portletInstance = portletFactory.getPortletInstance(appContext, portletDefinition);
  +            servletRequest.setAttribute(ContainerConstants.PORTLET, portletInstance);
  +            servletRequest.setAttribute(ContainerConstants.PORTLET_CONFIG, portletInstance.getConfig());
               servletRequest.setAttribute(ContainerConstants.PORTLET_REQUEST, portletRequest);
               servletRequest.setAttribute(ContainerConstants.PORTLET_RESPONSE, portletResponse);
  -            servletRequest.setAttribute(ContainerConstants.PORTLET_CONFIG, portletConfig);
  +            servletRequest.setAttribute(ContainerConstants.METHOD_ID, methodID);
               RequestContext requestContext = (RequestContext)servletRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
               servletRequest.setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath());
   
  -            JetspeedPortletFactoryProxy.setCurrentPortletDefinition(portletDefinition);                        
  -            
               dispatcher.include(servletRequest, servletResponse);
               
           }
  @@ -224,11 +219,12 @@
           }
           finally
           {
  -            //servletRequest.removeAttribute(ContainerConstants.METHOD_ID);
  -            //servletRequest.removeAttribute(ContainerConstants.PORTLET_REQUEST);
  -            //servletRequest.removeAttribute(ContainerConstants.PORTLET_RESPONSE);
  -            //servletRequest.removeAttribute(ContainerConstants.PORTLET_CONFIG);
  -            //servletRequest.removeAttribute(ContainerConstants.PORTLET_ENTITY);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_CONFIG);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_REQUEST);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_RESPONSE);
  +            servletRequest.removeAttribute(ContainerConstants.METHOD_ID);
  +            servletRequest.removeAttribute(ContainerConstants.PORTAL_CONTEXT);
           }
   
       }
  
  
  
  1.11.2.1  +6 -4      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/PortletInvokerFactoryImpl.java
  
  Index: PortletInvokerFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/PortletInvokerFactoryImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.11.2.1
  diff -u -r1.11 -r1.11.2.1
  --- PortletInvokerFactoryImpl.java	4 Jan 2005 16:11:20 -0000	1.11
  +++ PortletInvokerFactoryImpl.java	2 Mar 2005 02:48:11 -0000	1.11.2.1
  @@ -24,6 +24,7 @@
   
   import org.apache.jetspeed.Jetspeed;
   import org.apache.jetspeed.PortalContext;
  +import org.apache.jetspeed.factory.PortletFactory;
   import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
   import org.apache.pluto.factory.PortletInvokerFactory;
   import org.apache.pluto.om.portlet.PortletDefinition;
  @@ -72,7 +73,7 @@
   
       private PortalContext portalContext;
       
  -
  +    private PortletFactory portletFactory;
                  
       /* (non-Javadoc)
        * @see org.apache.pluto.factory.Factory#init(javax.servlet.ServletConfig, java.util.Map)
  @@ -83,6 +84,7 @@
           servletConfig = config;        
           portalContext = Jetspeed.getContext();
           props = properties;                        
  +        portletFactory = (PortletFactory)props.get("PortletFactory");
       }
   
       /* (non-Javadoc)
  @@ -109,14 +111,14 @@
           if (app.getApplicationType() == MutablePortletApplication.LOCAL)
           {
                   invoker =  (JetspeedPortletInvoker) props.get("LocalPortletInvoker"); 
  -                invoker.activate(portletDefinition, servletConfig);
  +                invoker.activate(portletFactory, portletDefinition, servletConfig);
                   return invoker;           
           }
           else
           {
               invoker =  (JetspeedPortletInvoker) props.get("ServletPortletInvoker"); 
               String servletMappingName = portalContext.getConfigurationProperty(INVOKER_SERVLET_MAPPING_NAME, DEFAULT_MAPPING_NAME);
  -            invoker.activate(portletDefinition, servletConfig, servletMappingName);            
  +            invoker.activate(portletFactory, portletDefinition, servletConfig, servletMappingName);            
               return invoker;
           }
   
  
  
  
  1.8.2.1   +38 -65    jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java
  
  Index: LocalPortletInvoker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/container/invoker/LocalPortletInvoker.java,v
  retrieving revision 1.8
  retrieving revision 1.8.2.1
  diff -u -r1.8 -r1.8.2.1
  --- LocalPortletInvoker.java	1 Aug 2004 15:43:45 -0000	1.8
  +++ LocalPortletInvoker.java	2 Mar 2005 02:48:11 -0000	1.8.2.1
  @@ -16,10 +16,6 @@
   package org.apache.jetspeed.container.invoker;
   
   import java.io.IOException;
  -import java.net.URL;
  -import java.net.URLClassLoader;
  -import java.util.HashMap;
  -import java.util.Map;
   
   import javax.portlet.ActionRequest;
   import javax.portlet.ActionResponse;
  @@ -36,10 +32,12 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.apache.jetspeed.PortalReservedParameters;
   import org.apache.jetspeed.container.ContainerConstants;
  -import org.apache.jetspeed.container.JetspeedPortletContext;
  -import org.apache.jetspeed.factory.JetspeedPortletFactoryProxy;
  -import org.apache.pluto.om.portlet.PortletApplicationDefinition;
  +import org.apache.jetspeed.factory.PortletFactory;
  +import org.apache.jetspeed.factory.PortletInstance;
  +import org.apache.jetspeed.om.common.portlet.PortletApplication;
  +import org.apache.jetspeed.request.RequestContext;
   import org.apache.pluto.om.portlet.PortletDefinition;
   
   /**
  @@ -61,23 +59,18 @@
   {
       private final static Log log = LogFactory.getLog(LocalPortletInvoker.class);
   
  +    protected PortletFactory portletFactory;
       protected ServletContext jetspeedContext;
       protected ServletConfig jetspeedConfig;
       protected PortletDefinition portletDefinition;
       protected boolean activated = false;
  -    /**
  -     * One class loader per local portlet application
  -     */
  -    protected static Map classLoaders = new HashMap();
  -
  -    public static final String LOCAL_CLASSES = "/WEB-INF/classes/";    
  -    public static final String LOCAL_JARS = "/WEB-INF/lib/";    
       
       /* (non-Javadoc)
  -     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(org.apache.pluto.om.portlet.PortletDefinition, javax.servlet.ServletConfig)
  +     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(PortletFactory,org.apache.pluto.om.portlet.PortletDefinition, javax.servlet.ServletConfig)
        */
  -    public void activate(PortletDefinition portletDefinition, ServletConfig servletConfig)
  +    public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig)
       {
  +        this.portletFactory = portletFactory;
           this.jetspeedConfig = servletConfig;
           jetspeedContext = servletConfig.getServletContext();
           this.portletDefinition = portletDefinition;
  @@ -135,7 +128,7 @@
           }
           catch (IOException e)
           {
  -            log.error("PortletInvokerImpl.load() - Error while dispatching portlet.", e);
  +            log.error("LocalPortletInvokerImpl.load() - Error while dispatching portlet.", e);
               throw new PortletException(e);
           }
       }
  @@ -155,63 +148,36 @@
       protected void invoke(PortletRequest portletRequest, PortletResponse portletResponse, Integer method)
           throws PortletException, IOException
       {
  -        PortletApplicationDefinition app = portletDefinition.getPortletApplicationDefinition();
  -        ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();            
  +        ClassLoader paClassLoader = portletFactory.getPortletApplicationClassLoader((PortletApplication)portletDefinition.getPortletApplicationDefinition());
  +        PortletInstance portletInstance = portletFactory.getPortletInstance(jetspeedContext,portletDefinition);
   
  -        String portletApplicationName = app.getWebApplicationDefinition().getContextRoot();
  +        if (method == ContainerConstants.METHOD_NOOP)
  +        {
  +            return;
  +        }
   
           // gather all required data from request and response
           ServletRequest servletRequest = ((javax.servlet.http.HttpServletRequestWrapper) portletRequest).getRequest();
   
           ServletResponse servletResponse = ((javax.servlet.http.HttpServletResponseWrapper) portletResponse).getResponse();
   
  -        ServletContext appContext = jetspeedContext.getContext(portletApplicationName);
  -        if (null == appContext)
  -        {
  -            String message = "Failed to find Servlet context for Portlet Application: " + portletApplicationName;
  -            log.error(message);
  -            throw new PortletException();
  -        }
  -
  -        
  -        Portlet portlet = null;
  -        
  +        ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();            
           try
           {
  -            ClassLoader loader = (ClassLoader)classLoaders.get(portletApplicationName);            
  -            if (null == loader)
  -            {
  -                StringBuffer localPath = new StringBuffer("file:");
  -                localPath.append(jetspeedContext.getRealPath(JetspeedPortletContext.LOCAL_PA_ROOT));
  -                localPath.append(portletApplicationName);
  -                String localAppPath = localPath.toString(); 
  -                URL[] urls = {new URL(localAppPath + LOCAL_CLASSES),
  -                              new URL(localAppPath + LOCAL_JARS)};
  -                loader = new URLClassLoader(urls, oldLoader);
  -                classLoaders.put(portletApplicationName, loader);
  -            }
  -            Thread.currentThread().setContextClassLoader(loader);                 
  -            portlet = JetspeedPortletFactoryProxy.getPortlet(jetspeedConfig, portletDefinition);            
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -            return;
  -        }
  -
  -        if (method == ContainerConstants.METHOD_NOOP)
  -        {
  -            return;
  -        }
  +            servletRequest.setAttribute(ContainerConstants.PORTLET_CONFIG, portletInstance.getConfig());
  +            servletRequest.setAttribute(ContainerConstants.PORTLET_REQUEST, portletRequest);
  +            servletRequest.setAttribute(ContainerConstants.PORTLET_RESPONSE, portletResponse);
  +            RequestContext requestContext = (RequestContext)servletRequest.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
  +            servletRequest.setAttribute(ContainerConstants.PORTAL_CONTEXT, requestContext.getRequest().getContextPath());
   
  -        //res.getWriter().print("Rendering: Portlet Class = " + entity.getPortletClass() + "<BR/>");
  +            Thread.currentThread().setContextClassLoader(paClassLoader);
   
           if (method == ContainerConstants.METHOD_ACTION)
           {
               ActionRequest actionRequest = (ActionRequest)portletRequest;            
               ActionResponse actionResponse = (ActionResponse)portletResponse;
   
  -            portlet.processAction(actionRequest, actionResponse);
  +                portletInstance.processAction(actionRequest, actionResponse);
           }
           else if (method == ContainerConstants.METHOD_RENDER)
           {
  @@ -219,21 +185,28 @@
               RenderResponse renderResponse = (RenderResponse)portletResponse;
               
               renderResponse.setContentType("text/html");            
  -            renderResponse.getWriter().print(portletDefinition.getName());
  +// TODO: ???    renderResponse.getWriter().print(portletDefinition.getName());
   
  -            portlet.render(renderRequest, renderResponse);
  +                portletInstance.render(renderRequest, renderResponse);
  +        }
           }
  +        finally
  +        {
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_CONFIG);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_REQUEST);
  +            servletRequest.removeAttribute(ContainerConstants.PORTLET_RESPONSE);
  +            servletRequest.removeAttribute(ContainerConstants.PORTAL_CONTEXT);
   
           Thread.currentThread().setContextClassLoader(oldLoader);                 
  -
  +        }
       }
   
       /* (non-Javadoc)
  -     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(org.apache.pluto.om.portlet.PortletDefinition, javax.servlet.ServletConfig, java.lang.String)
  +     * @see org.apache.jetspeed.container.invoker.JetspeedPortletInvoker#activate(PortletFactory,org.apache.pluto.om.portlet.PortletDefinition, javax.servlet.ServletConfig, java.lang.String)
        */
  -    public void activate(PortletDefinition portletDefinition, ServletConfig servletConfig, String servletMappingName)
  +    public void activate(PortletFactory portletFactory, PortletDefinition portletDefinition, ServletConfig servletConfig, String servletMappingName)
       {
  -        activate(portletDefinition, servletConfig);
  +        activate(portletFactory, portletDefinition, servletConfig);
       }
       
   }
  
  
  
  No                   revision
  No                   revision
  1.18.2.1  +311 -605  jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java
  
  Index: PortletApplicationManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/PortletApplicationManager.java,v
  retrieving revision 1.18
  retrieving revision 1.18.2.1
  diff -u -r1.18 -r1.18.2.1
  --- PortletApplicationManager.java	29 Oct 2004 14:19:37 -0000	1.18
  +++ PortletApplicationManager.java	2 Mar 2005 02:48:12 -0000	1.18.2.1
  @@ -15,661 +15,367 @@
    */
   package org.apache.jetspeed.tools.pamanager;
   
  -import java.io.File;
  -import java.io.FileInputStream;
  -import java.io.IOException;
  -import java.util.HashMap;
  -import java.util.Iterator;
  -import java.util.Map;
  -import java.util.Properties;
  -import java.util.Map.Entry;
  -
  -import org.apache.commons.configuration.Configuration;
  -import org.apache.commons.configuration.PropertiesConfiguration;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.jetspeed.Jetspeed;
  +
  +import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
  +import org.apache.jetspeed.components.portletentity.PortletEntityNotDeletedException;
   import org.apache.jetspeed.components.portletregistry.PortletRegistry;
  -import org.apache.jetspeed.deployment.impl.FileNotDeployableException;
  -import org.apache.jetspeed.deployment.impl.StandardDeploymentObject;
  -import org.apache.jetspeed.engine.Engine;
  -import org.apache.jetspeed.engine.JetspeedEngineConstants;
  -import org.apache.jetspeed.engine.SpringEngine;
  -import org.apache.jetspeed.exception.JetspeedException;
  -import org.apache.jetspeed.util.DirectoryHelper;
  +import org.apache.jetspeed.components.portletregistry.RegistryException;
  +import org.apache.jetspeed.container.window.PortletWindowAccessor;
  +import org.apache.jetspeed.factory.PortletFactory;
  +import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
  +import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
  +import org.apache.jetspeed.search.SearchEngine;
  +import org.apache.jetspeed.util.FileSystemHelper;
   import org.apache.jetspeed.util.descriptor.PortletApplicationWar;
   
  +import org.apache.pluto.om.entity.PortletEntity;
  +import org.apache.pluto.om.portlet.PortletDefinition;
  +
  +import java.io.IOException;
  +
  +import java.util.Iterator;
  +
   /**
    * PortletApplicationManager
    *
  - * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  + * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
    * @version $Id$
    */
  -/**
  - * This is the interface that defines the Lifecycle-related methods to control
  - * Portlet Applications.
  - *
  - * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
  -  * @version $Id$
  - */
  -
  -public class PortletApplicationManager implements JetspeedEngineConstants
  +public class PortletApplicationManager implements PortletApplicationManagement
   {
  -    private static final Log log = LogFactory.getLog("deployment");
  -    
  -    /**
  -     * Command line utility to deploy a portlet application to an application server.
  -     * The command line has the following options:
  -     *
  -     * PortletApplicationManager
  -     * -DWebappDir={Webapps directory of application server}
  -     * -DWarFileName={Name of the WAR file to deploy}
  -     * -Daction={deploy|register|undeploy|unregister|start|stop|reload}
  -     * -DPortletAppName= Name of the Portlet application
  -     * -DApplicationServer={Catalina}
  -     * -DApplicationType={webapp|local}
  -     *    (default webapp)
  -     * -DServer={host name of the target server}
  -     *   (optional: required for if deploying to Catalina)
  -     * -DServerPort={port of the target server. Default: localhost}
  -     *   (optional: required for if deploying to Catalina. Default: 8080)
  -     * -DUserName={User name to access the servers management system}
  -     *   (optional: required for if deploying to Catalina)
  -     * -DPassword={Password to access the servers management system}
  -     *   (optional: required for if deploying to Catalina)
  -     * -DImpl=(full class name i.e. org.apache.jetspeed.tools.pamanager.FileSystemPAM)
  -     *
  -     *Notes: The deploy action requires the WarFileName. If no ApplicationServer
  -     *       is defined it requires in additionthe WebappDir.
  -     *       All other actions require the PortletAppName. If the ApplicationServer
  -     *       is not defined it will use catalina as default.
  -    
  -     */
  -
  -    public static void main(String args[])
  -    {
  -        String arg;
  -        Engine engine = null;
  -        int i = 0;        
  -
  -        // Read the command line
  -        String strWebAppDir = "";
  -        String strAction = "";
  -        String strWarFileName = "";
  -        String strPortletAppName = "";
  -        String strPortalName = "jetspeed";
  -        String applicationType = "webapp";
  -		String strUserName = "";
  -		String strPassword = "";
  -		String strServer = "localhost";
  -        String className = "org.apache.jetspeed.tools.pamanager.FileSystemPAM"; // default
  -        Deployment deployer = null;
  -        Registration registrator = null;
  -        Lifecycle lifecycle = null;
  -        
  -		int intServerPort = 8080;
  -        String jetspeedPropertiesFile = System.getProperty("pam.jetspeed.properties", "/WEB-INF/conf/jetspeed.properties");
  -        String appsDirectory = System.getProperty("pam.apps.directory", "/WEB-INF/apps/");
  -        
  -        while (i < args.length && args[i].startsWith("-"))
  -        {
  -            arg = args[i++];
  +    private static final Log    log = LogFactory.getLog("deployment");
  +    private static final String PORTLET_XML = "WEB-INF/portlet.xml";
   
  -            // use this type of check for arguments that require arguments
  -            if (arg.equalsIgnoreCase("-PortletAppName"))
  -            {
  -                if (i < args.length)
  -                    strPortletAppName = args[i++];
  -            }
  -            else if (arg.equalsIgnoreCase("-Impl"))
  -            {
  -                if (i < args.length)
  -                    className = args[i++];
  -            }            
  -            else if (arg.equalsIgnoreCase("-Action"))
  -            {
  -                if (i < args.length)
  -                    strAction = args[i++];
  -            }
  -            else if (arg.equalsIgnoreCase("-WebAppDir"))
  -            {
  -                if (i < args.length)
  -                    strWebAppDir = args[i++];
  -            }
  -            else if (arg.equalsIgnoreCase("-WarFileName"))
  -            {
  -                if (i < args.length)
  -                    strWarFileName = args[i++];
  -            }
  -            else if (arg.equalsIgnoreCase("-PortalName"))
  -            {
  -                if (i < args.length)
  -                    strPortalName = args[i++];
  -            }
  -            else if (arg.equalsIgnoreCase("-UserName"))
  -            {
  -                if (i < args.length)
  -                    strUserName = args[i++];
  -            }
  -			else if (arg.equalsIgnoreCase("-Password"))
  -			{
  -				if (i < args.length)
  -					strPassword = args[i++];
  -			}
  -			else if (arg.equalsIgnoreCase("-Server"))
  -			{
  -				if (i < args.length)
  -					strServer= args[i++];
  -			}
  -            else if (arg.equalsIgnoreCase("-ServerPort"))
  -            {
  -                if (i < args.length)
  -                    intServerPort = Integer.parseInt(args[i++]);
  -            }
  -            else if (arg.equalsIgnoreCase("-ApplicationType"))
  -            {
  -                if (i < args.length)
  -                {
  -                    applicationType = args[i++];
  -                }
  -            }
  -            else if (arg.equalsIgnoreCase("-h"))
  -            {
  -                helpScreen();
  -                return;
  -            }
  -            else if (arg.equalsIgnoreCase("-?"))
  -            {
  -                helpScreen();
  -                return;
  -            }
  -        }
  -        
  -        // Portlet Application Name and action are required by all functions.
  -        // Make sure that the values were defined from the command line.
  -        if (strPortletAppName.length() == 0 || strAction.length() == 0)
  -        {
  -            System.out.println(
  -                "\nPortlet Application Name and/or action are not defined."
  -                    + "Please use '-PortletAppName appName' and/or '-Action deploy' from the command line\n");
  -            helpScreen();
  -            log.error("PAM Error: Invalid parameter(s) passed, cannot process PAM request.");
  -            if (!log.isInfoEnabled())
  -            {
  -                logRequest(args, true);
  -            }            
  -            return;
  -        }
  -
  -        String strAppRoot = strWebAppDir + strPortalName;
  +    protected PortletEntityAccessComponent entityAccess;
  +    protected PortletFactory        portletFactory;
  +    protected PortletRegistry       registry;
  +    protected PortletWindowAccessor windowAccess;
  +    protected SearchEngine searchEngine;
   
  +    /**
  +	 * Creates a new PortletApplicationManager object.
  +	 */
  +	public PortletApplicationManager(PortletFactory portletFactory, PortletRegistry registry,
  +		PortletEntityAccessComponent entityAccess, PortletWindowAccessor windowAccess)
  +	{
  +		this.portletFactory     = portletFactory;
  +		this.registry		    = registry;
  +		this.entityAccess	    = entityAccess;
  +		this.windowAccess	    = windowAccess;
  +	}
  +
  +	public void setSearchEngine(SearchEngine searchEngine)
  +	{
  +		this.searchEngine = searchEngine;
  +	}
  +
  +	public void startLocalPortletApplication(String contextName, FileSystemHelper warStruct,
  +		ClassLoader paClassLoader)
  +		throws RegistryException
  +	{
  +        checkValidContextName(contextName, true);
  +        startPA(contextName, warStruct, paClassLoader, true);
  +	}
  +
  +	public void startPortletApplication(String contextName, FileSystemHelper warStruct,
  +		ClassLoader paClassLoader)
  +		throws RegistryException
  +	{
  +        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
  +        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
           try
           {
  -            // Start the registry service -- it's needed by many actions
  -            Configuration properties =
  -                (Configuration) new PropertiesConfiguration(strAppRoot + jetspeedPropertiesFile);
  -
  -            properties.setProperty(APPLICATION_ROOT_KEY, strAppRoot);
  -
  -            // Override the properties with PAM specifice settings
  -            overrideProperties(strAppRoot, properties);
  -
  -            engine = Jetspeed.createEngine(properties, strAppRoot, null, SpringEngine.class);            
  +            checkValidContextName(contextName, false);
  +            startPA(contextName, warStruct, paClassLoader, false);
           }
  -        catch (Exception e)
  +        finally
           {
  -            String msg = "PAM Error: Failed to create the Jetspeed Engine. Error: ";
  -            System.out.println(msg + e.getMessage());
  -            log.error(msg, e);
  -            shutdownAndExit(engine);
  +            Thread.currentThread().setContextClassLoader(contextClassLoader);
           }
  +	}
   
  -        logRequest(args, false);
  -        
  +	public void stopLocalPortletApplication(String contextName)
  +		throws RegistryException
  +	{
  +		checkValidContextName(contextName, true);
  +		stopPA(contextName);
  +	}
  +
  +	public void stopPortletApplication(String contextName)
  +		throws RegistryException
  +	{
  +        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
  +        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
           try
           {
  -            System.out.println("Ready to run PAM implementation: " + className);
  -            System.out.print("Supporting interfaces: Deployment");
  -            // Class clas = Class.forName(className);
  -            PortletRegistry portletRegistry = (PortletRegistry) engine.getComponentManager()
  -                    .getComponent(PortletRegistry.class);
  -            deployer = (Deployment) engine.getComponentManager().getComponent("PAM");
  -            if (deployer instanceof Registration)
  -            {                
  -                System.out.print(", Registration");
  -                registrator = (Registration)deployer;
  -            }
  -            if (deployer instanceof Lifecycle)
  -            {
  -                System.out.print(", Lifecycle");
  -                lifecycle = (Lifecycle)deployer;
  -            }            
  -            System.out.println();
  +            checkValidContextName(contextName, false);
  +            stopPA(contextName);
           }
  -        catch (Exception e)
  +        finally
           {
  -            String msg = "PAM Error: Failed to create PAM implementation class object: " + className + " Error: ";
  -            System.out.println(msg  + e.getMessage());
  -            log.error(msg, e);
  -            shutdownAndExit(engine);                        
  +            Thread.currentThread().setContextClassLoader(contextClassLoader);
           }
  -        
  +	}
  +
  +	public void unregisterPortletApplication(String paName)
  +		throws RegistryException
  +	{
  +        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
  +        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
           try
           {
  -            // Invoke the functions
  -            if (strAction.compareToIgnoreCase("deploy") == 0)
  +            MutablePortletApplication pa = null;
  +            
  +            try
               {
  -                // Make sure that the WarFileName and the ApplicationServer are defined
  -                if (strWarFileName.length() == 0)
  -                {
  -                    System.out.println(
  -                        "\nDeploy action requires the war file name. Use '-WarFileName file.war' to specify the file name");
  -                    log.error("PAM Error: Web application (WAR) file name not specified.");
  -                    shutdownAndExit(engine);                
  -                }
  -                else
  -                {
  -                    if (applicationType.equals("local"))
  -                    {
  -                        String portletAppRoot = strAppRoot + appsDirectory;
  -                        deploy(deployer, portletAppRoot, strWarFileName, strPortletAppName); // [RUN]
  -                    }
  -                    else
  -                    {
  -                        // Requires WebAppDir
  -                        if (strWebAppDir.length() == 0)
  -                        {
  -                            System.out.println(
  -                                "\nDeploy action requires the definition of the ApplicationServer or the Web application directory.");
  -                            log.error("PAM Deploy Error: Web application (WAR) directory name not specified.");
  -                            shutdownAndExit(engine);                        
  -                        }
  -    
  -                        // File deploy uses Directory and warfile
  -                        deploy(deployer, strWebAppDir, strWarFileName, strPortletAppName); // [RUN]
  -                    }
  -                }
  -            }
  -            else if (strAction.compareToIgnoreCase("register") == 0)
  -            {
  -                // Requires WebAppDir
  -                if (strWebAppDir.length() == 0)
  -                {
  -                    System.out.println("\nRegister action requires the definition of the Web application directory.");
  -                    log.error("PAM Register Error: Web application (WAR) directory name not specified.");                        
  -                    shutdownAndExit(engine);
  -                }
  -                if (null == registrator)
  -                {
  -                    String msg = "PAM Register Error: Registration interface not supported by implementation: " + className;            
  -                    System.out.println("\n" + msg);
  -                    log.error(msg);
  -                    shutdownAndExit(engine);                                
  -                }
  -    
  -                register(registrator, strPortletAppName, strWarFileName); // [RUN]
  -            }
  -            else if (strAction.compareToIgnoreCase("unregister") == 0)
  -            {          
  -                if (null == registrator)
  -                {
  -                    String msg = "PAM Register Error: Registration interface not supported by implementation: " + className;            
  -                    System.out.println("\n" + msg);
  -                    log.error(msg);  
  -                    shutdownAndExit(engine);                
  -                }
  -                
  -                // Application server can be null -- using Catalina as default
  -                unregister(registrator, strPortletAppName); // [RUN]
  -            }
  -            else if (strAction.compareToIgnoreCase("undeploy") == 0)
  -            {
  -                
  -                undeploy(deployer, strWebAppDir, strPortletAppName, strServer, intServerPort, strUserName, strPassword); // [RUN]
  -            }
  -            else if (strAction.compareToIgnoreCase("start") == 0)
  -            {
  -                if (null == lifecycle)
  -                {
  -                    String msg = "PAM Lifecycle Error: Lifecycle interface not supported by implementation: " + className;            
  -                    System.out.println("\n" + msg);
  -                    log.error(msg);
  -                    shutdownAndExit(engine);                                
  -                }
  -    
  -                start(lifecycle, strPortletAppName, strServer, intServerPort, strUserName, strPassword); // [RUN]
  +                pa = (MutablePortletApplication) registry.getPortletApplication(paName);
               }
  -            else if (strAction.compareToIgnoreCase("stop") == 0)
  +            catch (Exception e)
               {
  -                stop(lifecycle, strPortletAppName, strServer, intServerPort, strUserName, strPassword); // [RUN]
  +                // ignore errors during portal shutdown
               }
  -            else if (strAction.compareToIgnoreCase("reload") == 0)
  +
  +            if (pa != null)
               {
  -                if (null == lifecycle)
  +                if (portletFactory.getPortletApplicationClassLoader(pa) != null)
                   {
  -                    String msg = "PAM Lifecycle Error: Lifecycle interface not supported by implementation: " + className;            
  -                    System.out.println("\n" + msg);
  -                    log.error(msg);
  -                    shutdownAndExit(engine);                                
  +                    throw new RegistryException("Portlet Application " + paName + " still running");
                   }
  -                // Application server can be null -- using Catalina as default
  -                reload(lifecycle, strPortletAppName, strServer, intServerPort, strUserName, strPassword); // [RUN]
  -            }
  -            else
  -            {
  -                System.out.println("\nAction: " + strAction + " not recognized by the PortletApplicationManager.");
  -                helpScreen();
  -            }
  -        }
  -        catch (Exception e)
  -        {
  -            String msg = "PAM Error: Failed during execution of " + strAction + ", error = " + e.getMessage();
  -            System.out.println(msg);
  -            log.error(msg);                        
  -            shutdownAndExit(engine);                    
  -        }
  -        
  -        try
  -        {
  -            if (engine != null)
  -            {
  -                engine.shutdown();
  -            }
  -        }
  -        catch (JetspeedException e1)
  -        {
  -            System.out.println("Failed shutting down the engine. Error: " + e1.getMessage());
  -            log.error("PAM Error: Failed shutting down the engine.", e1);                        
  -            System.exit(0);            
  -        }
  -        
  -        String msg = "PAM: completed operation " + strAction;
  -        System.out.println(msg);
  -        log.info(msg);
  -        System.exit(0);
  -    }
   
  -    public static void shutdownAndExit(Engine engine)
  -    {
  -        try
  -        {
  -            if (engine != null)
  -            {
  -                engine.shutdown();
  +                unregisterPortletApplication(pa, true);
               }
           }
  -        catch (JetspeedException e1)
  +        finally
           {
  -            System.out.println("Failed shutting down the engine. Error: " + e1.getMessage());
  -            log.error("PAM Error: Failed shutting down the engine.", e1);                        
  +            Thread.currentThread().setContextClassLoader(contextClassLoader);
           }
  -        
  -        System.exit(0);                    
  -    }
  -    
  -    public static void helpScreen()
  -    {
  -        System.out.println("\nPortletApplicationManager [options]\n");
  -        System.out.println("\t-action\t\t\t{deploy|undeploy|start|stop|reload}\n");
  -        System.out.println("\t-PortletAppName\t\t{AppName}\n");
  -        System.out.println("\t-WebAppDir\t\t{Path to target WebApp directory}\n");
  -        System.out.println("\t-WarFileName\t\t{Path to war file to deploy}\n");
  -        System.out.println("\t-Impl\t\t{class name of implementation}\n");
  -        System.out.println("\t-ApplicationType\t{webapp|local}\n");
  -
  -        System.out.println("\nNotes:");
  -        System.out.println("-Each command requires at least the action and the PortletAppName options.");
  -        System.out.println("-File system deploy requires the WebAppDir and War file option");
  -        System.out.println("-Deploy and undeploy actions require the WarFileName");
  +	}
   
  -        System.out.println(
  -            "\nExample: PortletApplicationManager -action deploy -PortletAppName DemoApp -ApplicationServer Catalina\n");
  +	protected void checkValidContextName(String contextName, boolean local)
  +		throws RegistryException
  +	{
  +		int prefixLength = LOCAL_PA_PREFIX.length();
   
  -    }
  +		if ((contextName.length() >= prefixLength)
  +			&& contextName.substring(0, prefixLength).equalsIgnoreCase(LOCAL_PA_PREFIX))
  +		{
  +			if (!local)
  +			{
  +				throw new RegistryException("Prefix \"" + LOCAL_PA_PREFIX
  +					+ "\" is reserved for Local Portlet Applications only.");
  +			}
  +		}
  +		else if (local)
  +		{
  +			throw new RegistryException("Prefix \"" + LOCAL_PA_PREFIX
  +				+ "\" is required for Local Portlet Applications.");
  +		}
  +	}
  +
  +	protected MutablePortletApplication registerPortletApplication(PortletApplicationWar paWar,
  +		MutablePortletApplication oldPA, boolean local)
  +		throws RegistryException
  +	{
  +		if (oldPA != null)
  +		{
  +			unregisterPortletApplication(oldPA, false);
  +			oldPA = null;
  +		}
  +
  +		MutablePortletApplication pa		 = null;
  +		boolean					  registered = false;
  +		String					  paName     = paWar.getPortletApplicationName();
  +
  +		try
  +		{
  +			log.info("Loading portlet.xml...." + paName);
  +			pa = paWar.createPortletApp();
   
  -    // Implementaion of the API's
  +			if (local)
  +			{
  +				pa.setApplicationType(MutablePortletApplication.LOCAL);
  +			}
  +			else
  +			{
  +				pa.setApplicationType(MutablePortletApplication.WEBAPP);
  +			}
   
  -    /**
  -     * Registers the already deployed WAR into the Portal registry
  -     *
  -     * @param registrator PAM implementation supporting Registration interface
  -     * @param webApplicationName The webapps directory or name inside the Application Server
  -     * @param portletApplicationName The Portlet Application name
  -     * @throws PortletApplicationException
  -     * @throws IOException
  -     * @throws FileNotDeployableException
  -     */
  -
  -    public static void register(Registration registrator,                                
  -                                String portletApplicationName,
  -                                String warFile)
  -    throws PortletApplicationException, FileNotDeployableException, IOException
  -    {
  -        System.out.println("Registering Portlet Application [" + portletApplicationName + "]...");  
  -              
  -        StandardDeploymentObject deploymentObject = new StandardDeploymentObject(new File(warFile));
  -        registrator.register(new PortletApplicationWar(deploymentObject.getFileObject(),  portletApplicationName, "/"+portletApplicationName ) );
  -        System.out.println("...PAM Register done");   
  -        deploymentObject.close();
  -    }
  +			// load the web.xml
  +			log.info("Loading web.xml...." + paName);
  +			MutableWebApplication wa = paWar.createWebApp();
  +			paWar.validate();
   
  -    /**
  -     * Unregisterd a deployed portlet application
  -     *
  -     * @param registrator PAM implementation supporting Registration interface
  -     * @param webApplicationName The webapps directory or name inside the Application Server
  -     * @param portletApplicationName The Portlet Application name
  -     */
  -
  -    public static void unregister(Registration registrator,
  -                                  
  -                                  String portletApplicationName)
  -    throws PortletApplicationException    
  -    {
  -        System.out.println("Unregistering Portlet Application [" + portletApplicationName + "...");
  -        registrator.unregister(portletApplicationName);
  -        System.out.println("...PAM Unregister done");        
  -    }
  +			if (local)
  +			{
  +				wa.setContextRoot("<portal>");
  +			}
   
  -    /**
  -     * Deploys the specified war file to the webapps dirctory specified.
  -     *
  -     * @param webAppsDir The webapps directory or name inside the Application Server
  -     * @param warFile The warFile containing the Portlet Application
  -     * @param portletApplicationName The Portlet Application name
  -     * @throws PortletApplicationException
  -     * @throws IOException
  -     * @throws FileNotDeployableException
  -     */
  -
  -    public static void deploy(Deployment deployer,
  -                              String webAppsDir, 
  -                              String warFile,
  -                              String portletApplicationName)
  -    throws PortletApplicationException, FileNotDeployableException, IOException        
  -    {
  -        System.out.println("Deploying Web Application [" + webAppsDir + "] to Portlet Application [" + portletApplicationName + "]...");
  -               
  -        StandardDeploymentObject deploymentObject = new StandardDeploymentObject(new File(warFile));
  -        deployer.deploy(new PortletApplicationWar(deploymentObject.getFileObject(), portletApplicationName, "/"+portletApplicationName));
  -        System.out.println("...PAM Deploy done");   
  -        deploymentObject.close();
  -    }
  +			pa.setWebApplicationDefinition(wa);
  +		}
  +		catch (Exception e)
  +		{
  +			String msg = "Failed to load portlet application for "
  +				+ paWar.getPortletApplicationName();
  +			log.error(msg);
  +			throw new RegistryException(msg);
  +		}
  +
  +		// register the portlet application
  +		try
  +		{
  +			registry.registerPortletApplication(pa);
  +			registered = true;
  +			log.info("Registered the portlet application " + paName);
   
  -    /**
  -     * Prepares the specified war file for deployment.
  -     *
  -     * @param paName The Portlet Application name
  -     * @throws PortletApplicationException
  -     * @throws IOException
  -     */    
  -    public static void undeploy(Deployment deployer,
  -                                String webApplicationName, 
  -                                String portletApplicationName, 
  -                                String host, 
  -                                int port, 
  -                                String user, 
  -                                String password)
  -    throws PortletApplicationException, IOException    
  -    {
  -        if (deployer instanceof ApplicationServerPAM)
  -        {
  -            ((ApplicationServerPAM)deployer).start();            
  -        }
  -        System.out.println("Un-deploying Web Application [" + webApplicationName + "], Portlet Application [" + portletApplicationName + "]...");
  -        
  -        String webAppPath = deployer.getDeploymentPath(webApplicationName);
  -        File warFile = new File(webAppPath);
  -        deployer.undeploy(new PortletApplicationWar(new DirectoryHelper(warFile), portletApplicationName, "/"+portletApplicationName));
  -        System.out.println("...PAM Undeploy done");                                
  -    }
  +			// add to search engine result
  +			if (searchEngine != null)
  +			{
  +				searchEngine.add(pa);
  +				searchEngine.add(pa.getPortletDefinitions());
  +				log.info("Registered the portlet application in the search engine... " + paName);
  +			}
   
  -    /**
  -     * Starts the specified Portlet Application on the Application Server
  -     * 
  -     * @param lifecycle
  -     * @param portletApplicationName
  -     * @param host
  -     * @param port
  -     * @param user
  -     * @param password
  -     * @throws PortletApplicationException
  -     */
  -    public static void start(Lifecycle lifecycle,
  -                             String portletApplicationName, 
  -                             String host, 
  -                             int port, 
  -                             String user,
  -                             String password)
  -    throws PortletApplicationException
  -    {
  -        if (lifecycle instanceof ApplicationServerPAM)
  -        {
  -            ((ApplicationServerPAM)lifecycle).start();            
  -        }
  -        System.out.println("Starting Portlet Application [" + portletApplicationName + "...");
  -     
  -        lifecycle.startPortletApplication(portletApplicationName);
  -        System.out.println("...PAM Start done");                        
  -    }
  +			return pa;
  +		}
  +		catch (Exception e)
  +		{
  +			String msg = "Failed to register portlet application, " + paName;
  +			log.error(msg, e);
   
  -    /**
  -     * Stops a portlet application from running on the Application Server
  -     *
  -     * @param lifecycle
  -     * @param portletApplicationName
  -     * @param appServer
  -     * @param host
  -     * @param port
  -     * @param user
  -     * @param password
  -     */    
  -    public static void stop(Lifecycle lifecycle, 
  -                            String portletApplicationName, 
  -                            String host, 
  -                            int port, 
  -                            String user, 
  -                            String password)
  -    throws PortletApplicationException        
  -    {
  -        Map map = new HashMap();        
  -        if (lifecycle instanceof ApplicationServerPAM)
  -        {
  -            ((ApplicationServerPAM)lifecycle).start();            
  -        }
  -        System.out.println("Stopping Portlet Application [" + portletApplicationName + "...");
  -      
  -        lifecycle.stopPortletApplication(portletApplicationName);
  -        System.out.println("...PAM Stop done");                
  -    }
  +			if (registered)
  +			{
  +				try
  +				{
  +					registry.removeApplication(pa);
  +				}
  +				catch (Exception re)
  +				{
  +					log.error("Failed to rollback registration of portlet application" + paName, re);
  +				}
  +			}
   
  -    /**
  -     * Reloads a portlet application.
  -     * 
  -     * @param lifecycle
  -     * @param portletApplicationName
  -     * @param appServer
  -     * @param host
  -     * @param port
  -     * @param user
  -     * @param password
  -     * @throws PortletApplicationException
  -     */    
  -    public static void reload(Lifecycle lifecycle, 
  -                              String portletApplicationName, 
  -                              String host, 
  -                              int port, 
  -                              String user, 
  -                              String password)
  -    throws PortletApplicationException    
  -    {        
  -        Map map = new HashMap();        
  -        if (lifecycle instanceof ApplicationServerPAM)
  -        {
  -            ((ApplicationServerPAM)lifecycle).start();            
  -        }
  -        System.out.println("Reloading Portlet Application [" + portletApplicationName + "...");
  -     
  -        lifecycle.reloadPortletApplication(portletApplicationName);
  -        System.out.println("...PSM Reload done");        
  -    }
  -
  -    /*
  -      * Method to override jetspeed properties.
  -      * @param properties The base configuration properties for the Jetspeed system.
  -      */
  -    public static void overrideProperties(String strApplicationRoot, Configuration properties) throws IOException
  -    {
  -        String pamPropertiesFile = System.getProperty("pam.properties", "/WEB-INF/conf/pam.properties");
  -        
  -        String testPropsPath = strApplicationRoot + pamPropertiesFile;
  -        File testFile = new File(testPropsPath);
  -        if (testFile.exists())
  -        {
  -            FileInputStream is = new FileInputStream(testPropsPath);
  -            Properties props = new Properties();
  -            props.load(is);
  +			throw new RegistryException(msg, e);
  +		}
  +	}
  +
  +	protected void startPA(String contextName, FileSystemHelper warStruct,
  +		ClassLoader paClassLoader, boolean local)
  +		throws RegistryException
  +	{
  +		PortletApplicationWar paWar = null;
  +
  +		try
  +		{
  +			try
  +			{
  +				paWar = new PortletApplicationWar(warStruct, contextName, "/" + contextName);
   
  -            Iterator it = props.entrySet().iterator();
  -            while (it.hasNext())
  -            {
  -                Entry entry = (Entry) it.next();
  -                //if (entry.getValue() != null && ((String)entry.getValue()).length() > 0)
  -                properties.setProperty((String) entry.getKey(), (String) entry.getValue());
  -            }
  -        }
  -    }
  -    
  -    public static void logRequest(String[] args, boolean logAsError)
  -    {
  -        String startMsg = "Starting a PAM request. Parameters: ";
  -        if (logAsError)
  -        {
  -            log.error(startMsg);
  -        }
  -        else
  +				if (paClassLoader == null)
  +				{
  +					paClassLoader = paWar.createClassloader(getClass().getClassLoader());
  +				}
  +			}
  +			catch (IOException e)
  +			{
  +				String msg = "Failed to create PA WAR for " + contextName;
  +				log.error(msg, e);
  +				throw new RegistryException(msg, e);
  +			}
  +
  +			MutablePortletApplication pa = (MutablePortletApplication) registry
  +				.getPortletApplication(contextName);
  +
  +			if ((pa != null) && (paWar.getPortletApplicationChecksum() == pa.getChecksum()))
  +			{
  +                portletFactory.unregisterPortletApplication(pa);
  +			}
  +			else
  +			{
  +				pa = registerPortletApplication(paWar, pa, local);
  +			}
  +            portletFactory.registerPortletApplication(pa, paClassLoader);
  +		}
  +		finally
  +		{
  +			if (paWar != null)
  +			{
  +				try
  +				{
  +					paWar.close();
  +				}
  +				catch (IOException e)
  +				{
  +					log.error("Failed to close PA WAR for " + contextName, e);
  +				}
  +			}
  +		}
  +	}
  +
  +	protected void stopPA(String contextName)
  +		throws RegistryException
  +	{
  +		MutablePortletApplication pa = null;
  +        
  +        try
           {
  -            log.info(startMsg);            
  +            pa = (MutablePortletApplication) registry.getPortletApplication(contextName);
           }
  -        
  -        int ix;
  -        
  -        for (ix = 0; ix < args.length; ix++)
  +        catch (Exception e)
           {
  -            String paramName = args[ix];            
  -            String paramValue = "--PARAMS OUT OF BALANCE--";
  -            if (ix <= args.length)
  -            {
  -                paramValue = args[++ix];
  -            }
  -            if (logAsError)
  -            {            
  -                log.error(paramName + " : " + paramValue);
  -            }
  -            else
  -            {
  -                log.info(paramName + " : " + paramValue);
  -            }
  +            // ignore errors during portal shutdown
           }
  -    }
  +		if (pa != null)
  +		{
  +			portletFactory.unregisterPortletApplication(pa);
  +		}
  +	}
  +
  +	protected void unregisterPortletApplication(MutablePortletApplication pa,
  +		boolean purgeEntityInfo)
  +		throws RegistryException
  +	{
  +		if (searchEngine != null)
  +		{
  +			searchEngine.remove(pa);
  +			searchEngine.remove(pa.getPortletDefinitions());
  +		}
  +
  +		log.info("Remove all registry entries defined for portlet application " + pa.getName());
  +
  +		Iterator portlets = pa.getPortletDefinitions().iterator();
  +
  +		while (portlets.hasNext())
  +		{
  +			PortletDefinition portletDefinition = (PortletDefinition) portlets.next();
  +			Iterator		  entities = entityAccess.getPortletEntities(portletDefinition)
  +													 .iterator();
  +
  +			while (entities.hasNext())
  +			{
  +				PortletEntity entity = (PortletEntity) entities.next();
  +
  +				if (purgeEntityInfo)
  +				{
  +					try
  +					{
  +						entityAccess.removePortletEntity(entity);
  +					}
  +					catch (PortletEntityNotDeletedException e)
  +					{
  +						String msg = "Failed to delete Portlet Entity " + entity.getId();
  +						log.error(msg, e);
  +						throw new RegistryException(msg, e);
  +					}
  +				}
  +
  +				entityAccess.removeFromCache(entity);
  +				windowAccess.removeWindows(entity);
  +			}
  +		}
  +
  +		// todo keep (User)Prefs?
  +		registry.removeApplication(pa);
  +	}
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message