portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/messaging PortletMessageComponent.java
Date Fri, 12 Nov 2004 06:28:56 GMT
taylor      2004/11/11 22:28:56

  Modified:    portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/spring
                        ModelBeanImpl.java PortletApplicationModelImpl.java
               portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/model
                        PortletApplicationModel.java ModelBean.java
               portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks
                        GenericFrameworkPortlet.java
  Added:       portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks
                        ExternalComponentSupport.java Lookup.java
               portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/messaging
                        PortletMessageComponent.java
  Log:
  - added simple messaging api as place holder / abstraction
  - continued quixotic fw development, despite the general disdain
  
  Revision  Changes    Path
  1.2       +46 -2     jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/spring/ModelBeanImpl.java
  
  Index: ModelBeanImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/spring/ModelBeanImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ModelBeanImpl.java	4 Nov 2004 18:09:33 -0000	1.1
  +++ ModelBeanImpl.java	12 Nov 2004 06:28:56 -0000	1.2
  @@ -29,13 +29,23 @@
   
       private String beanName;
       private int beanType;
  -    
  +    private boolean requiresExternalSupport = false;
  +    private String lookupKey;
  +
       public ModelBeanImpl(String beanName, int beanType)
       {
           this.beanName = beanName;
           this.beanType = beanType;
       }
       
  +    public ModelBeanImpl(String beanName, int beanType, String lookupKey, boolean requiresExternalSupport)
  +    {
  +        this.beanName = beanName;
  +        this.beanType = beanType;
  +        this.lookupKey = lookupKey;
  +        this.requiresExternalSupport = requiresExternalSupport;
  +    }
  +    
       /* (non-Javadoc)
        * @see org.apache.portals.bridges.velocity.model.ModelBean#getBeanName()
        */
  @@ -52,4 +62,38 @@
           return beanType;
       }
   
  +    /**
  +     * @return Returns the lookupKey.
  +     */
  +    public String getLookupKey()
  +    {
  +        return lookupKey;
  +    }
  +    /**
  +     * @param lookupKey The lookupKey to set.
  +     */
  +    public void setLookupKey(String lookupKey)
  +    {
  +        this.lookupKey = lookupKey;
  +    }
  +    /**
  +     * @return Returns the requiresExternalSupport.
  +     */
  +    public boolean isRequiresExternalSupport()
  +    {
  +        return requiresExternalSupport;
  +    }
  +    /**
  +     * @param requiresExternalSupport The requiresExternalSupport to set.
  +     */
  +    public void setRequiresExternalSupport(boolean requiresExternalSupport)
  +    {
  +        this.requiresExternalSupport = requiresExternalSupport;
  +    }
  +    
  +    public boolean isRequiresLookup()
  +    {
  +        return (lookupKey!= null);
  +    }
  +    
   }
  
  
  
  1.3       +76 -8     jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/spring/PortletApplicationModelImpl.java
  
  Index: PortletApplicationModelImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/spring/PortletApplicationModelImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PortletApplicationModelImpl.java	11 Nov 2004 01:46:39 -0000	1.2
  +++ PortletApplicationModelImpl.java	12 Nov 2004 06:28:56 -0000	1.3
  @@ -24,12 +24,16 @@
   import javax.portlet.PortletConfig;
   import javax.portlet.PortletException;
   
  +import org.springframework.beans.PropertyValue;
  +import org.springframework.beans.factory.config.BeanDefinition;
   import org.springframework.beans.factory.xml.XmlBeanFactory;
   
   import org.apache.commons.validator.Validator;
   import org.apache.commons.validator.ValidatorException;
   import org.apache.commons.validator.ValidatorResources;
   import org.apache.commons.validator.ValidatorResults;
  +import org.apache.portals.bridges.frameworks.ExternalComponentSupport;
  +import org.apache.portals.bridges.frameworks.Lookup;
   import org.apache.portals.bridges.frameworks.model.ModelBean;
   import org.apache.portals.bridges.frameworks.model.PortletApplicationModel;
   import org.apache.portals.bridges.frameworks.spring.ModelBeanImpl;
  @@ -93,6 +97,10 @@
        */    
       private Map actionForwardMap = null;
       
  +    private Map modelBeanMap = new HashMap();
  +    
  +    private Map externalSupportMap = new HashMap();
  +    
       private static Object semaphore = new Object();
       
       private String springConfig;
  @@ -104,6 +112,11 @@
           this.validatorConfig = validatorConfig;
       }
       
  +    public void setExternalSupport(Map map)
  +    {
  +        this.externalSupportMap = map;
  +    }
  +    
       public void init(PortletConfig config)
       throws PortletException
       {
  @@ -172,7 +185,7 @@
            
            // View to Validator Map
            synchronized (semaphore)
  -         {
  +         {             
                viewValidatorMap = (Map)springFactory.getBean(PORTLET_VIEW_VALIDATOR_MAP);
                if (viewValidatorMap == null)
                {
  @@ -198,17 +211,45 @@
                {
                    actionForwardMap = new HashMap();              
                }
  -         }                          
  +         }
  +         
  +         
       }
       
  -    public ModelBean getBean(String view)
  +    public ModelBean getModelBean(String view)
       {
  +        ModelBean modelBean;
           String beanName = (String)viewBeanMap.get(view);
           if (beanName != null)
           {
  -            return new ModelBeanImpl(beanName, ModelBean.POJO);
  +            modelBean = (ModelBean)modelBeanMap.get(beanName);
  +            if (modelBean == null)
  +            {
  +                BeanDefinition bd = springFactory.getBeanDefinition(beanName);
  +                Object bean = springFactory.getBean(beanName);
  +                if (bd == null || bean == null)
  +                {
  +                    return new ModelBeanImpl(beanName, ModelBean.POJO);
  +                }                   
  +                String lookup = null;
  +                boolean requiresExternalSupport = false;
  +                PropertyValue value = bd.getPropertyValues().getPropertyValue("lookupKey");
  +                if (value != null)
  +                {
  +                    lookup = (String)value.getValue();
  +                }                
  +                if (bean instanceof ExternalComponentSupport)
  +                {
  +                    requiresExternalSupport = true;
  +                }
  +                modelBean = new ModelBeanImpl(beanName, ModelBean.POJO, lookup, requiresExternalSupport);
  +            }
           }
  -        return new ModelBeanImpl(beanName, ModelBean.PREFS_MAP);
  +        else
  +        {
  +            modelBean = new ModelBeanImpl(beanName, ModelBean.PREFS_MAP);
  +        }        
  +        return modelBean;
       }
       
       public String getTemplate(String view)
  @@ -216,11 +257,38 @@
           return (String)logicalViewMap.get(view);
       }
       
  -    public Object createBean(ModelBean mb)
  +    public Object lookupBean(ModelBean mb, String key)
       {
  -        return springFactory.getBean(mb.getBeanName());
  +        Object bean = springFactory.getBean(mb.getBeanName());
  +        if (bean != null)
  +        {
  +            if (mb.isRequiresExternalSupport())
  +            {
  +                ExternalComponentSupport ecs = (ExternalComponentSupport)bean;
  +                ecs.setExternalSupport(externalSupportMap.get(mb.getBeanName()));
  +            }
  +            if (mb.isRequiresLookup())
  +            {
  +                ((Lookup)bean).lookup(key);
  +            }
  +        }
  +        return bean;
       }
   
  +    public Object createBean(ModelBean mb)
  +    {
  +        Object bean = springFactory.getBean(mb.getBeanName());
  +        if (bean != null)
  +        {
  +            if (mb.isRequiresExternalSupport())
  +            {
  +                ExternalComponentSupport ecs = (ExternalComponentSupport)bean;
  +                ecs.setExternalSupport(externalSupportMap.get(mb.getBeanName()));
  +            }
  +        }
  +        return bean;
  +    }
  +    
       public Map createPrefsBean(ModelBean mb, Map original)
       {
           Map prefs = new HashMap();
  
  
  
  1.3       +4 -3      jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/model/PortletApplicationModel.java
  
  Index: PortletApplicationModel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/model/PortletApplicationModel.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PortletApplicationModel.java	11 Nov 2004 01:46:39 -0000	1.2
  +++ PortletApplicationModel.java	12 Nov 2004 06:28:56 -0000	1.3
  @@ -33,11 +33,12 @@
       void init(PortletConfig config)
       throws PortletException;
       
  -    ModelBean getBean(String view);
  +    ModelBean getModelBean(String view);
   
       String getTemplate(String view);
       
       Object createBean(ModelBean mb);
  +    Object lookupBean(ModelBean mb, String key);
       
       Map createPrefsBean(ModelBean mb, Map prefs);
       
  @@ -47,5 +48,5 @@
       String getForward(String view, String status);
       
       String getForward(String actionForward);
  -    
  +    void setExternalSupport(Map map);
   }
  
  
  
  1.2       +5 -1      jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/model/ModelBean.java
  
  Index: ModelBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/model/ModelBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ModelBean.java	4 Nov 2004 18:09:33 -0000	1.1
  +++ ModelBean.java	12 Nov 2004 06:28:56 -0000	1.2
  @@ -32,5 +32,9 @@
       
       int getBeanType();
              
  +    String getLookupKey();
       
  +    boolean isRequiresLookup();
  +    
  +    boolean isRequiresExternalSupport();
   }
  
  
  
  1.7       +50 -18    jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/GenericFrameworkPortlet.java
  
  Index: GenericFrameworkPortlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/GenericFrameworkPortlet.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- GenericFrameworkPortlet.java	11 Nov 2004 01:46:39 -0000	1.6
  +++ GenericFrameworkPortlet.java	12 Nov 2004 06:28:56 -0000	1.7
  @@ -16,6 +16,7 @@
   package org.apache.portals.bridges.frameworks;
   
   import java.io.IOException;
  +import java.io.Serializable;
   import java.lang.reflect.Method;
   import java.util.Iterator;
   import java.util.Map;
  @@ -55,7 +56,6 @@
    */
   public class GenericFrameworkPortlet extends GenericVelocityPortlet
   {
  -
       /**
        * Init Parameter: default spring configuration property
        */
  @@ -83,10 +83,14 @@
       {
       }
   
  +    public void setExternalSupport(Map map)
  +    {
  +        model.setExternalSupport(map);
  +    }
  +    
       public void init(PortletConfig config) throws PortletException
       {
           super.init(config);
  -
           String springConfig = this.getInitParameter(INITPARAM_SPRING_CONFIG);
           if (springConfig == null) { throw new PortletException("Spring Configuration file
not specified"); }
   
  @@ -116,7 +120,7 @@
           String view = determineLogicalView(request);
   
           Object bean = null;
  -        ModelBean mb = model.getBean(view);
  +        ModelBean mb = model.getModelBean(view);
   
           if (mb.getBeanType() == ModelBean.PREFS_MAP)
           {
  @@ -171,8 +175,7 @@
   
       protected void forwardToView(ActionRequest request, ActionResponse response, String
forward)
       {
  -        if (forward == null) { return; // stay on same page
  -        }
  +        if (forward == null) { return; } // stay on same page
   
           String logicalView = null;
           PortletMode newMode = null;
  @@ -399,12 +402,12 @@
       {
   
           // try to get the bean from the session first
  -        Object bean = request.getPortletSession().getAttribute(mb.getBeanName());
  +        Object bean = getBeanFromSession(request, mb); 
           if (bean == null)
           {
               bean = model.createBean(mb);
               if (bean == null) { throw new PortletException("Portlet Action error in creating
bean for view: " + view); }
  -            request.getPortletSession().setAttribute(mb.getBeanName(), bean);
  +            putBeanInSession(request, mb, bean);
           }
   
           Map params = request.getParameterMap();
  @@ -509,16 +512,16 @@
           String template = model.getTemplate(view);
           if (template == null) { throw new PortletException("Template not found for Logical
View: " + view); }
   
  -        ModelBean mb = model.getBean(view);
  -        if (mb.getBeanType() == ModelBean.PREFS_MAP)
  -        {
  -            prefsToContext(request, view, mb);
  -        }
  -        else
  +        ModelBean mb = model.getModelBean(view);
  +        switch (mb.getBeanType())
           {
  +        case ModelBean.PREFS_MAP:
  +            preferencesToContext(request, view, mb);
  +            break;
  +        case ModelBean.POJO:
               beanToContext(request, view, mb);
  +            break;
           }
  -
           putRequestVariable(request, FrameworkConstants.FORWARD_TOOL, new Forwarder(model,
request, response));
           Map errors = (Map)request.getPortletSession().getAttribute(SESSION_ERROR_MESSAGES,
PortletSession.PORTLET_SCOPE);
           if (errors != null)
  @@ -534,28 +537,57 @@
   
       private void beanToContext(RenderRequest request, String view, ModelBean mb)
       {
  -        Object bean = request.getPortletSession().getAttribute(mb.getBeanName());
  +        Object bean;
  +        
  +        String key = (String)request.getAttribute(mb.getLookupKey());
  +        if (key != null)
  +        {
  +            bean = model.lookupBean(mb, key);
  +        }
  +        else
  +        {
  +            bean = getBeanFromSession(request, mb);
  +        }
           if (bean == null)
           {
               bean = model.createBean(mb);
               if (bean == null) { return; }
  -            request.getPortletSession().setAttribute(mb.getBeanName(), bean);
  +            putBeanInSession(request, mb, bean);
           }
           putRequestVariable(request, mb.getBeanName(), bean);
       }
   
  -    private void prefsToContext(RenderRequest request, String view, ModelBean mb)
  +    private void preferencesToContext(RenderRequest request, String view, ModelBean mb)
       {
           Map bean = (Map) request.getPortletSession().getAttribute(view + PREFS_SUFFIX);
           if (bean == null)
           {
               PortletPreferences prefs = request.getPreferences();
               bean = model.createPrefsBean(mb, prefs.getMap());
  -            request.getPortletSession().setAttribute(view + PREFS_SUFFIX, bean);
  +            putBeanInSession(request, mb, bean);
           }
           putRequestVariable(request, FrameworkConstants.PREFS_VARIABLE, bean);
       }
   
  +    
  +    private Object getBeanFromSession(PortletRequest request, ModelBean mb)
  +    {
  +        return request.getPortletSession().getAttribute(makeModelBeanKey(mb));
  +    }
  +
  +    private void putBeanInSession(PortletRequest request, ModelBean mb, Object bean)
  +    {
  +        if (bean instanceof Serializable)
  +        {
  +            request.getPortletSession().setAttribute(makeModelBeanKey(mb), bean);
  +        }
  +    }
  +    
  +    private String makeModelBeanKey(ModelBean mb)
  +    {
  +        return "ModelBean:" + mb.getBeanName();
  +    }
  +    
       /**
        * Specific for Velocity
        * 
  
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/ExternalComponentSupport.java
  
  Index: ExternalComponentSupport.java
  ===================================================================
  /*
   * Copyright 2000-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.portals.bridges.frameworks;
  
  
  /**
   * ExternalComponentSupport
   * 
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: ExternalComponentSupport.java,v 1.1 2004/11/12 06:28:56 taylor Exp $
   */
  public interface ExternalComponentSupport
  {
      void setExternalSupport(Object externalSupportObject);
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/Lookup.java
  
  Index: Lookup.java
  ===================================================================
  /*
   * Copyright 2000-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.portals.bridges.frameworks;
  
  
  /**
   * Lookup
   * 
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: Lookup.java,v 1.1 2004/11/12 06:28:56 taylor Exp $
   */
  public interface Lookup
  {
      boolean lookup(String key);
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portals-bridges/frameworks/src/java/org/apache/portals/bridges/frameworks/messaging/PortletMessageComponent.java
  
  Index: PortletMessageComponent.java
  ===================================================================
  /*
   * Copyright 2000-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.portals.bridges.frameworks.messaging;
  
  import java.io.NotSerializableException;
  import java.io.Serializable;
  
  import javax.portlet.PortletRequest;
  import javax.portlet.PortletSession;
  
  
  /**
   * PortletMessageComponent
   * Naive implementation of Porlet Messages as an abstraction and a place holder for when
the next 
   * spec covers inter-portlet communication
   * 
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: PortletMessageComponent.java,v 1.1 2004/11/12 06:28:56 taylor Exp $
   */
  public class PortletMessageComponent
  {
      public static final void publish(PortletRequest request, String portletTopic, String
messageName, Object message)
      throws NotSerializableException
      {
          String key = portletTopic + ":" + messageName;
          if (message instanceof Serializable)
          {
              request.getPortletSession().setAttribute(key, message, PortletSession.APPLICATION_SCOPE);
          }
          else
          {
              throw new NotSerializableException("Message not serializable for " + key);
          }
      }
  
      public static final Object consume(PortletRequest request, String portletTopic, String
messageName)
      throws NotSerializableException
      {
          String key = portletTopic + ":" + messageName;
          Object object = request.getPortletSession().getAttribute(key, PortletSession.APPLICATION_SCOPE);
          // consume it
          request.getPortletSession().removeAttribute(key, PortletSession.APPLICATION_SCOPE);
       
          return object;
      }
  
      public static final Object receive(PortletRequest request, String portletTopic, String
messageName)
      throws NotSerializableException
      {
          String key = portletTopic + ":" + messageName;
          Object object = request.getPortletSession().getAttribute(key, PortletSession.APPLICATION_SCOPE);
          return object;
      }
      
      public static final void cancel(PortletRequest request, String portletTopic, String
messageName)
      throws NotSerializableException
      {
          String key = portletTopic + ":" + messageName;
          request.getPortletSession().removeAttribute(key, PortletSession.APPLICATION_SCOPE);
      }
      
  }
  
  
  

---------------------------------------------------------------------
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