portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raph...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/controllerfactory ControllerFactoryService.java JetspeedControllerFactoryService.java
Date Wed, 02 May 2001 21:15:28 GMT
raphael     01/05/02 14:15:28

  Modified:    src/java/org/apache/jetspeed/om/newregistry
                        PortletInfoEntry.java
               src/java/org/apache/jetspeed/om/newregistry/base
                        BasePortletInfoEntry.java
               src/java/org/apache/jetspeed/portal PortletSet.java
               src/java/org/apache/jetspeed/portal/factory
                        PortletControlFactory.java
                        PortletControllerFactory.java
                        PortletSetFactory.java
  Added:       src/java/org/apache/jetspeed/services ControlFactory.java
                        ControllerFactory.java
               src/java/org/apache/jetspeed/services/controlfactory
                        ControlFactoryService.java
                        JetspeedControlFactoryService.java
               src/java/org/apache/jetspeed/services/controllerfactory
                        ControllerFactoryService.java
                        JetspeedControllerFactoryService.java
  Log:
  Rewrite the control and controller factory as services and make them
  use the Registry for looking up classes
  
  Revision  Changes    Path
  1.3       +14 -2     jakarta-jetspeed/src/java/org/apache/jetspeed/om/newregistry/PortletInfoEntry.java
  
  Index: PortletInfoEntry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/newregistry/PortletInfoEntry.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PortletInfoEntry.java	2001/05/02 14:17:00	1.2
  +++ PortletInfoEntry.java	2001/05/02 21:14:50	1.3
  @@ -55,13 +55,14 @@
   package org.apache.jetspeed.om.newregistry;
   
   import java.util.Enumeration;
  +import java.util.Map;
   
   /**
    * The PortletInfoEntry defines all the common description properties 
    * for all the portlet related entries.
    * 
    * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
  - * @version $Id: PortletInfoEntry.java,v 1.2 2001/05/02 14:17:00 raphael Exp $
  + * @version $Id: PortletInfoEntry.java,v 1.3 2001/05/02 21:14:50 raphael Exp $
    */
   public interface PortletInfoEntry extends RegistryEntry
   {
  @@ -80,6 +81,11 @@
       /** @return an enumeration of this entry parameter names */
       public Enumeration getParameterNames();
       
  +    /** Returns a map of parameter values keyed on the parameter names 
  +     *  @return the parameter values map
  +     */
  +    public Map getParameterMap();
  +
       /** Search for a named parameter and return the associated
        *  parameter object. The search is case sensitive.
        *
  @@ -87,7 +93,13 @@
        *  @param name the parameter name to look for
        */
       public Parameter getParameter( String name );
  -    
  +        
  +    /** Adds a new parameter for this entry
  +     *  @param name the new parameter name
  +     *  @param value the new parameter value
  +     */
  +    public void addParameter( String name, String value );
  +
       /** Adds a new parameter for this entry
        *  @param parameter the new parameter to add
        */
  
  
  
  1.3       +38 -5     jakarta-jetspeed/src/java/org/apache/jetspeed/om/newregistry/base/BasePortletInfoEntry.java
  
  Index: BasePortletInfoEntry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/newregistry/base/BasePortletInfoEntry.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BasePortletInfoEntry.java	2001/05/02 14:17:12	1.2
  +++ BasePortletInfoEntry.java	2001/05/02 21:14:58	1.3
  @@ -56,10 +56,7 @@
   
   import org.apache.jetspeed.om.newregistry.*;
   
  -import java.util.Vector;
  -import java.util.Hashtable;
  -import java.util.Enumeration;
  -import java.util.Iterator;
  +import java.util.*;
   
   /**
    * The BasePortletInfoEntry is a bean like implementation of the PortletInfoEntry
  @@ -67,7 +64,7 @@
    * 
    * @see org.apache.jetspeed.om.newregistry.PortletInfoEntry
    * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
  - * @version $Id: BasePortletInfoEntry.java,v 1.2 2001/05/02 14:17:12 raphael Exp $
  + * @version $Id: BasePortletInfoEntry.java,v 1.3 2001/05/02 21:14:58 raphael Exp $
    */
   public abstract class BasePortletInfoEntry extends BaseRegistryEntry
   {
  @@ -132,6 +129,42 @@
       }
       
       
  +    /** Returns a map of parameter values keyed on the parameter names 
  +     *  @return the parameter values map
  +     */
  +    public Map getParameterMap()
  +    {
  +        Hashtable params = new Hashtable();
  +        Enumeration en = parameter.elements();
  +        while(en.hasMoreElements())
  +        {
  +            Parameter param = (Parameter)en.nextElement();
  +            params.put(param.getName(),param.getValue());
  +        }
  +        
  +        return params;
  +        
  +    }
  +
  +    /** Adds a new parameter for this entry
  +     *  @param name the new parameter name
  +     *  @param value the new parameter value
  +     */
  +    public void addParameter( String name, String value )
  +    {
  +        if (name != null)
  +        {
  +            Parameter p = getParameter(name);
  +            if (p == null)
  +            {
  +                p = new BaseParameter();
  +                p.setName(name);
  +            }
  +            
  +            p.setValue(value);
  +        }
  +    }
  +
       /** Adds a new parameter for this entry
        *  @param parameter the new parameter to add
        */
  
  
  
  1.20      +15 -12    jakarta-jetspeed/src/java/org/apache/jetspeed/portal/PortletSet.java
  
  Index: PortletSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/PortletSet.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- PortletSet.java	2001/03/07 06:45:40	1.19
  +++ PortletSet.java	2001/05/02 21:15:03	1.20
  @@ -60,7 +60,7 @@
   import java.util.Enumeration;
   
   //Jetspeed stuff
  -import org.apache.jetspeed.portal.factory.PortletControllerFactory;
  +import org.apache.jetspeed.services.ControllerFactory;
   import org.apache.jetspeed.profiler.*;
   import org.apache.jetspeed.capability.*;
   import org.apache.jetspeed.util.*;
  @@ -81,7 +81,7 @@
   
   @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
  -@version $Id: PortletSet.java,v 1.19 2001/03/07 06:45:40 taylor Exp $
  +@version $Id: PortletSet.java,v 1.20 2001/05/02 21:15:03 raphael Exp $
   */
   public class PortletSet implements Portlet {
   
  @@ -139,15 +139,18 @@
   
           /**
           */
  -        public void init() throws PortletException {
  -
  -                String controllerClassname = 
  -                        JetspeedResources.getString( JetspeedResources.PORTLETCONTROLLER_DEFAULT_CLASSNAME_KEY );
  +        public void init() throws PortletException
  +        {
  +                
  +            if (getPortletConfig()==null)
  +            {
  +                setPortletConfig(new PortletConfig());
  +            }
                   
  -                if (getPortletConfig()==null) setPortletConfig(new PortletConfig());
  -                if (getController()==null)
  -                        setController(PortletControllerFactory
  -                                .getPortletController( controllerClassname ) );
  +            if (getController()==null)
  +            {
  +                setController( ControllerFactory.getPortletController("") );
  +            }
           }
   
           /**
  @@ -245,6 +248,7 @@
           */
           public synchronized void setController(PortletController controller) {
                   this.controller=controller;
  +                controller.setPortlets(this);
           }
   
   
  @@ -273,10 +277,9 @@
                   } else {
   
                           if ( ! controller.supportsType( map.getPreferredType() ) ) {
  -                                setController( PortletControllerFactory.getPortletController() );
  +                                setController( ControllerFactory.getPortletController("") );
                           }
   
  -                        controller.setPortlets(this);
                           return controller.getContent( rundata );
   
                   }
  
  
  
  1.25      +27 -144   jakarta-jetspeed/src/java/org/apache/jetspeed/portal/factory/PortletControlFactory.java
  
  Index: PortletControlFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/factory/PortletControlFactory.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- PortletControlFactory.java	2001/03/07 06:46:34	1.24
  +++ PortletControlFactory.java	2001/05/02 21:15:09	1.25
  @@ -56,24 +56,19 @@
   
   //jetspeed stuff
   import org.apache.jetspeed.portal.Portlet;
  -import org.apache.jetspeed.portal.PortletSet;
   import org.apache.jetspeed.portal.PortletControl;
  -import org.apache.jetspeed.portal.PortletControlConfig;
   import org.apache.jetspeed.services.resources.JetspeedResources;
  -import org.apache.jetspeed.util.MimeType;
  +import org.apache.jetspeed.services.ControlFactory;
   import org.apache.jetspeed.xml.api.portletmarkup.Control;
  -import org.apache.jetspeed.xml.api.portletmarkup.Parameter;
  -import org.apache.turbine.util.Log;
  -
  -import java.util.Hashtable;
  -import java.util.Map;
    
   /**
  +This class has been replaced by the ControlFactoryService
  +@deprecated
   @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
  -@version $Id: PortletControlFactory.java,v 1.24 2001/03/07 06:46:34 taylor Exp $
  +@version $Id: PortletControlFactory.java,v 1.25 2001/05/02 21:15:09 raphael Exp $
   */
  -public class PortletControlFactory {
  -
  +public class PortletControlFactory
  +{
   
       /**
       HTML default portlet
  @@ -81,163 +76,51 @@
       private static String PORTLETCONTROL_DEFAULT_CLASSNAME =
           JetspeedResources.getString( JetspeedResources.PORTLETCONTROL_DEFAULT_CLASSNAME_KEY );
   
  -            
  -    public static final Hashtable mimeTypeMap = new Hashtable();
  -
  -    /**
  -    Static initializer.  Performs actions need by this PortletControllerFactory.
  -    */
  -    static {
  -        mimeTypeMap.put( MimeType.WML, "org.apache.jetspeed.portal.controls.ClearPortletControl" );
  -        mimeTypeMap.put( MimeType.HTML, PORTLETCONTROL_DEFAULT_CLASSNAME );
  -    }
  -            
  -            
  -    /*
  -    TODO.  consider a better mechanism for PortletControls... don't provide an
  -    init() and only have these be one at a time and thread safe.  This say we
  -    don't have to instantiate them all the time.
  -    */
  -
       /**
  +        @deprecated
       */
  -    public static PortletControl getPortletControl( Portlet portlet ) {
  +    public static PortletControl getPortletControl( Portlet portlet )
  +    {
           return getPortletControl( PORTLETCONTROL_DEFAULT_CLASSNAME, portlet );
       }
   
       /**
  +        @deprecated
       */
       public static PortletControl getPortletControl( String classname, 
  -                                                    Portlet portlet ) {
  -
  -        if (portlet == null) {
  -            throw new IllegalArgumentException( "Portlet not specified" );
  -        }
  -
  -        PortletControl pc = null;
  -        try {
  +                                                    Portlet portlet )
  +    {
   
  -            pc = (PortletControl)Class.forName( classname ).newInstance();
  +        PortletControl pc = ControlFactory.getPortletControl(classname);
  +        return ControlFactory.initControl(pc,portlet);
   
  -        } catch ( Throwable t ) {
  -            Log.error( t );
  -            return null;
  -        }
  -
  -        PortletControlConfig pcConf = new PortletControlConfig();
  -        pcConf.setParameters(portlet.getPortletConfig().getParameters());
  -        pcConf.setInitParameters(getParameters(null));
  -        pc.setConfig( pcConf );
  -        pc.init( portlet );
  -
  -        return pc;
  -
       }
   
       /**
  +        @deprecated
       */
  -    public static PortletControl getPortletControl( String classname ) {
  -
  -        PortletControl pc = null;
  -
  -        try {
  -
  -            pc = (PortletControl)Class.forName( classname ).newInstance();
  -
  -        } catch ( Throwable t ) {
  -            Log.error( t );
  -            return null;
  -        }
  -
  -        return pc;
  -
  +    public static PortletControl getPortletControl( String classname )
  +    {
  +        return ControlFactory.getPortletControl(classname);
       }
   
       /**
  +        @deprecated
       */
       public static PortletControl getPortletControl( Control control, 
  -                                                    Portlet portlet) {
  -
  -        PortletControl pc = null;
  -
  -        String name = PORTLETCONTROL_DEFAULT_CLASSNAME;
  -        if (control==null) {
  -            if (portlet instanceof PortletSet) return null;
  -        } else {
  -            name=control.getName();
  -        }
  -
  -        PortletControlConfig pcConf = new PortletControlConfig();
  -        pcConf.setParameters(portlet.getPortletConfig().getParameters());
  -        pcConf.setInitParameters(getParameters(control));
  -
  -        pc = getPortletControl(name);
  -
  -        pc.setConfig(pcConf);
  -        pc.init(portlet);
  -
  -        return pc;
  -
  -    }
  -
  -    /**
  -    */
  -    public static PortletControl getPortletControl( Control control ) {
  -
  -        PortletControl pc = null;
  -
  -        String name = PORTLETCONTROL_DEFAULT_CLASSNAME;
  -        if (control!=null) name=control.getName();
  -
  -        pc = getPortletControl(name);
  -
  -        PortletControlConfig pcConf = new PortletControlConfig();
  -        pcConf.setInitParameters(getParameters(control));
  -        pc.setConfig(pcConf);
  -
  -        return pc;
  -
  +                                                    Portlet portlet)
  +    {
  +        PortletControl pc = ControlFactory.getPortletControl(control);
  +        return ControlFactory.initControl(pc,portlet);
       }
   
       /**
  +        @deprecated
       */
  -    static Map getParameters(Control control) {
  -        Hashtable hash = new Hashtable();
  -
  -        if (control!=null) {
  -            Parameter[] params = control.getParameter();
  -
  -            for (int i=0; i < params.length; i++ ) {
  -                hash.put(params[i].getName(),params[i].getValue());
  -            }
  -        }
  -        return hash;
  +    public static PortletControl getPortletControl( Control control )
  +    {
  +        return ControlFactory.getPortletControl(control);
       }
   
  -
  -    //BEGIN methods for accessing via MimeTypes
  -    
  -    
  -    /**
  -    */
  -    public static PortletControl getPortletControl( MimeType mimeType,
  -                                                    Portlet portlet ) {
  -        
  -        String classname = (String)mimeTypeMap.get( mimeType );
  -        
  -        if ( classname == null ) {
  -            
  -            throw new RuntimeException( "Could not find a PortletControl for you given MimeType: " + mimeType.toString() );
  -
  -        }
  -        
  -        return getPortletControl( classname, portlet );
  -        
  -    }
  -    
  -    
  -    //END methods for accessing via MimeTypes    
  -    
  -    
   }
   
  
  
  
  1.35      +26 -182   jakarta-jetspeed/src/java/org/apache/jetspeed/portal/factory/PortletControllerFactory.java
  
  Index: PortletControllerFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/factory/PortletControllerFactory.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- PortletControllerFactory.java	2001/03/07 06:46:35	1.34
  +++ PortletControllerFactory.java	2001/05/02 21:15:11	1.35
  @@ -59,21 +59,18 @@
   
   //jetspeed stuff
   import org.apache.jetspeed.portal.*;
  -import org.apache.jetspeed.util.*;
  -import org.apache.jetspeed.cache.disk.*;
  -
   import org.apache.jetspeed.xml.api.portletmarkup.Controller;
  -import org.apache.jetspeed.xml.api.portletmarkup.Parameter;
   
   //turbine stuff
  -import org.apache.turbine.util.*;
  -import org.apache.jetspeed.services.resources.JetspeedResources;
  +import org.apache.turbine.util.ParameterParser;
  +import org.apache.jetspeed.services.ControllerFactory;
   
   /**
   Used to create references to PortletControllers
   
  +@deprecated This class has been replaced by the ControllerFactoryService
   @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
  -@version $Id: PortletControllerFactory.java,v 1.34 2001/03/07 06:46:35 taylor Exp $
  +@version $Id: PortletControllerFactory.java,v 1.35 2001/05/02 21:15:11 raphael Exp $
   */
   public class PortletControllerFactory {
   
  @@ -82,122 +79,43 @@
       public static final String CARD_CONTROLLER = "org.apache.jetspeed.portal.controllers.CardPortletController";    
       public static final String WAP_CONTROLLER = "org.apache.jetspeed.portal.controllers.WMLCardController";    
   
  -    public static final Hashtable mimeTypeMap = new Hashtable();
  -
  -    /**
  -    Static initializer.  Performs actions need by this PortletControllerFactory.
  -    */
  -    static {
  -        mimeTypeMap.put( MimeType.WML,  ROWCOLUMN_CONTROLLER );
  -        mimeTypeMap.put( MimeType.HTML, ROWCOLUMN_CONTROLLER );
  -    }
  -    
       /**
       Get the default PortletController
  -    */
  -    public static PortletController getPortletController() {
  -
  -        String classname = 
  -            JetspeedResources.getString( JetspeedResources.PORTLETCONTROLLER_DEFAULT_CLASSNAME_KEY );
  -
  -        return getPortletController( classname );
  -
  -    }
  -
  -    /**
  -    Get the default PortletController with the given portlets
  -    */
  -    public static PortletController getPortletController( PortletSet portlets ) {
  -
  -        String classname = 
  -            JetspeedResources.getString( JetspeedResources.PORTLETCONTROLLER_DEFAULT_CLASSNAME_KEY );
  -
  -        return getPortletController( classname,
  -                                     portlets,
  -                                     null );
  -
  -    }
  -
  -
  -    /**
  -    Get the default PortletController with the given Portlet
  -    */
  -    public static PortletController getPortletController( Portlet portlet,
  -                                                          ParameterParser params ) {
  -        PortletSet portlets = new PortletSet();
  -        portlets.addPortlet(portlet);
  -
  -        String classname = 
  -            JetspeedResources.getString( JetspeedResources.PORTLETCONTROLLER_DEFAULT_CLASSNAME_KEY );
  -
  -
  -        return getPortletController( classname,
  -                                     portlets,
  -                                     null,
  -                                     params );
  -    }
  -
  -
  -    /**
  -    Get the default PortletController with the given PortletControl
  +    @deprecated
       */
  -    public static PortletController getPortletController( PortletControl control,
  -                                                          ParameterParser params ) {
  -        PortletSet portlets = new PortletSet();
  -        portlets.addPortlet( control.getPortlet() );
  -        String classname = 
  -            JetspeedResources.getString( JetspeedResources.PORTLETCONTROLLER_DEFAULT_CLASSNAME_KEY );
  -
  -        return getPortletController( classname,
  -                            portlets,
  -                            null,
  -                            params );
  +    public static PortletController getPortletController()
  +    {
  +        return getPortletController( "" );
       }
   
       /**
  +    @deprecated
       */
       public static PortletController getPortletController( String classname,
                                                             PortletSet portlets,
  -                                                          ParameterParser params ) {
  -
  -        return getPortletController(classname,portlets,new Hashtable(), params );
  +                                                          ParameterParser params )
  +    {
  +        return ControllerFactory.getPortletController( classname );
       }
   
       /**
       The actual implementation of the getInstance() method.  Handles creating
       the specified classname, given portlets, and gives the PC the given rundata.
  +    @deprecated
       */
       public static PortletController getPortletController( String classname,
                                                             PortletSet portlets,
                                                             Map initParams,
  -                                                          ParameterParser params ) {
  -
  -        if (portlets == null) {
  -            throw new IllegalArgumentException( "Portlet not specified" );
  -        }
  -
  +                                                          ParameterParser params )
  +    {
           if (initParams == null ) {
               initParams = new Hashtable();
           }
  -
  -        PortletController pc = null;
  -
  -        try {
  -
  -            pc = (PortletController)Class.forName( classname ).newInstance();
  -
  -        } catch ( Throwable t ) {
  -            Log.error( t );
  -            return null;
  -        }
   
  -        PortletControllerConfig pcConf = new PortletControllerConfig();
  -        pcConf.setInitParameters( initParams );
  -        pcConf.setParameters( params );
  -        pc.setConfig(pcConf);
  -        pc.setPortlets(portlets);
  +        PortletController pc = ControllerFactory.getPortletController( classname );
  +        pc.getConfig().setInitParameters( initParams );
           pc.init();
  -
  +        
           return pc;
   
       }
  @@ -205,97 +123,23 @@
       /**
       The actual implementation of the getInstance() method.  Handles creating
       the specified classname.
  +    @deprecated
       */
  -    public static PortletController getPortletController( String classname ) {
  -
  -        PortletController pc = null;
  -
  -        try {
  -
  -            pc = (PortletController)Class.forName( classname ).newInstance();
  -
  -        } catch ( Throwable t ) {
  -            Log.error( t );
  -            return null;
  -        }
  -
  -        PortletControllerConfig pcConf = new PortletControllerConfig();
  -        pcConf.setInitParameters( new Hashtable() );
  -        pc.setConfig(pcConf);
  -
  -        return pc;
  -
  +    public static PortletController getPortletController( String classname )
  +    {
  +        return ControllerFactory.getPortletController( classname );
       }
   
  -
       /**
       The actual implementation of the getInstance() method.  Handles creating
       the specified classname.
  +    @deprecated
       */
       public static PortletController getPortletController( Controller controller, 
  -                                                          ParameterParser params ) {
  -
  -
  -        PortletController pc = null;
  -        PortletControllerConfig pcConf = new PortletControllerConfig();
  -
  -        pcConf.setInitParameters( getParameters(controller) );
  -        pcConf.setParameters( params );
  -
  -        if (controller!=null) {
  -            pc = getPortletController( controller.getName() );
  -        } else {
  -
  -            String controllerClassname = 
  -                JetspeedResources.getString( JetspeedResources.PORTLETCONTROLLER_DEFAULT_CLASSNAME_KEY );
  -
  -            pc = getPortletController( controllerClassname );
  -        }
  -
  -        pc.setConfig(pcConf);
  -        pc.init();
  -
  -        return pc;
  +                                                          ParameterParser params )
  +    {
  +        return ControllerFactory.getPortletController( controller );
       }
   
  -    /**
  -    */
  -    static Map getParameters(Controller controller) {
  -        Hashtable hash = new Hashtable();
  -        if (controller!=null) {
  -            Parameter[] params = controller.getParameter();
  -
  -            for (int i=0; i < params.length; i++ ) {
  -                hash.put(params[i].getName(),params[i].getValue());
  -            }
  -        }
  -
  -        return hash;
  -    }
  -
  -    //BEGIN methods for accessing via MimeTypes
  -    
  -    
  -    /**
  -    Given a MimeType, get a default PortletController for it.
  -    */
  -    public static PortletController getPortletController( MimeType mimeType,
  -                                                          PortletSet portlets,
  -                                                          ParameterParser params ) {
  -        
  -        String classname = (String)mimeTypeMap.get( mimeType );
  -        
  -        if ( classname == null ) {
  -            
  -            throw new RuntimeException( "Could not find a PortletController for you given MimeType: " + mimeType.toString() );
  -        }
  -        
  -        return getPortletController( classname, portlets, new Hashtable(), params );
  -        
  -    }
  -    
  -    
  -    //END methods for accessing via MimeTypes    
  -    
   }
   
  
  
  
  1.20      +8 -5      jakarta-jetspeed/src/java/org/apache/jetspeed/portal/factory/PortletSetFactory.java
  
  Index: PortletSetFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/factory/PortletSetFactory.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- PortletSetFactory.java	2001/05/02 10:47:49	1.19
  +++ PortletSetFactory.java	2001/05/02 21:15:13	1.20
  @@ -62,6 +62,8 @@
   import org.apache.jetspeed.profiler.*;
   import org.apache.jetspeed.capability.*;
   import org.apache.jetspeed.services.Registry; 
  +import org.apache.jetspeed.services.ControlFactory;
  +import org.apache.jetspeed.services.ControllerFactory;
   import org.apache.jetspeed.om.newregistry.PortletEntry;
   
   //Castor defined API
  @@ -85,7 +87,7 @@
   
   @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
   @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
  -@version $Id: PortletSetFactory.java,v 1.19 2001/05/02 10:47:49 raphael Exp $
  +@version $Id: PortletSetFactory.java,v 1.20 2001/05/02 21:15:13 raphael Exp $
   */
   public class PortletSetFactory extends BasePortletFactory {
   
  @@ -330,8 +332,7 @@
           PortletSet set = new PortletSet();
   
           // set the controller for this PortletSet
  -        set.setController( PortletControllerFactory.getPortletController( portlets.getController(),
  -                                                                          rundata.getParameters() ) );
  +        set.setController( ControllerFactory.getPortletController( portlets.getController() ) );
   
           PortletConfig pc = PortletConfigFactory.getPortletConfig( portlets, rundata );
           set.setPortletConfig( pc );
  @@ -389,8 +390,10 @@
           }
   
           // Decorate with a control if required and return
  -        if ( portlets.getControl() != null ) {
  -            return PortletControlFactory.getPortletControl( portlets.getControl(), set );
  +        if ( portlets.getControl() != null )
  +        {
  +            PortletControl control = ControlFactory.getPortletControl(portlets.getControl());
  +            return ControlFactory.initControl(control,set);            
           }
   
           // Or return the set
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/ControlFactory.java
  
  Index: ControlFactory.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.services;
  
  import org.apache.jetspeed.portal.Portlet;
  import org.apache.jetspeed.portal.PortletControl;
  import org.apache.jetspeed.xml.api.portletmarkup.Control;
  import org.apache.jetspeed.services.controlfactory.ControlFactoryService;
  import org.apache.turbine.services.TurbineServices;
  
  /**
   * <P>This is a commodity static accessor class around the 
   * <code>ControlFactoryService</code></P>
   * 
   * @see org.apache.jetspeed.services.controlfactory.ControlFactoryService
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @version $Id: ControlFactory.java,v 1.1 2001/05/02 21:15:21 raphael Exp $
   */
  public class ControlFactory {
   
      /** 
       * Commodity method for getting a reference to the service
       * singleton
       */
      private static ControlFactoryService getService() {
          return (ControlFactoryService)TurbineServices
                  .getInstance()
                  .getService(ControlFactoryService.SERVICE_NAME);     
      }
  
      /**
       * Instanciates a PortletControl based on a Registry entry, if available 
       * or directly from a classname.
       *
       * @param name a PortletControl name available in the registry or a classname
       * @return the created PortletControl
       */
      public static PortletControl getPortletControl( String name )
      {
          return getService().getPortletControl(name);
      }
  
      /**
       * Instanciates a PortletControl based on a PSML Control object
       *
       * @param control the PSML control object
       * @return the created PortletControl
       */
      public static PortletControl getPortletControl( Control control )
      {
          return getService().getPortletControl(control);
      }
  
      /**
       * Associates a PortletControl wit an existing Portlet and
       * returns the Control
       *
       * @param pc the existing PortletControl
       * @param portlet the existing Portlet to be associated with the control
       * @return first PortletControl associated with the portlet
       */
      public static PortletControl initControl( PortletControl pc, Portlet portlet )
      {
          return getService().initControl(pc,portlet);
      }
      
  }
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/ControllerFactory.java
  
  Index: ControllerFactory.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.services;
  
  import org.apache.jetspeed.portal.Portlet;
  import org.apache.jetspeed.portal.PortletController;
  import org.apache.jetspeed.xml.api.portletmarkup.Controller;
  import org.apache.jetspeed.services.controllerfactory.ControllerFactoryService;
  import org.apache.turbine.services.TurbineServices;
  
  /**
   * <P>This is a commodity static accessor class around the 
   * <code>ControllerFactoryService</code></P>
   * 
   * @see org.apache.jetspeed.services.controllerfactory.ControllerFactoryService
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @version $Id: ControllerFactory.java,v 1.1 2001/05/02 21:15:21 raphael Exp $
   */
  public class ControllerFactory {
   
      /** 
       * Commodity method for getting a reference to the service
       * singleton
       */
      private static ControllerFactoryService getService() {
          return (ControllerFactoryService)TurbineServices
                  .getInstance()
                  .getService(ControllerFactoryService.SERVICE_NAME);     
      }
  
      /**
       * Instanciates a PortletController based on a Registry entry, if available 
       * or directly from a classname.
       *
       * @param name a PortletController name available in the registry or a classname
       * @return the created PortletController
       */
      public static PortletController getPortletController( String name )
      {
          return getService().getPortletController(name);
      }
  
      /**
       * Instanciates a PortletController based on a PSML Controller object
       *
       * @param controller the PSML controller object
       * @return the created PortletController
       */
      public static PortletController getPortletController( Controller controller )
      {
          return getService().getPortletController(controller);
      }
  
  }
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/controlfactory/ControlFactoryService.java
  
  Index: ControlFactoryService.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.services.controlfactory;
  
  //jetspeed stuff
  import org.apache.jetspeed.portal.Portlet;
  import org.apache.jetspeed.portal.PortletControl;
  import org.apache.jetspeed.xml.api.portletmarkup.Control;
  import org.apache.turbine.services.Service;
   
  /**
   * This service creates new PortletControl instances from various
   * descriptor objects.
   * 
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @version $Id: ControlFactoryService.java,v 1.1 2001/05/02 21:15:24 raphael Exp $
   */
  public interface ControlFactoryService extends Service
  {
  
      /** The default control to use when none is specified */
      public String SERVICE_NAME = "ControlFactory";
              
      /**
       * Instanciates a PortletControl based on a Registry entry, if available 
       * or directly from a classname.
       *
       * @param name a PortletControl name available in the registry or a classname
       * @return the created PortletControl
       */
      public PortletControl getPortletControl( String name );
  
      /**
       * Instanciates a PortletControl based on a PSML Control object
       *
       * @param control the PSML control object
       * @return the created PortletControl
       */
      public PortletControl getPortletControl( Control control );
  
      /**
       * Associates a PortletControl wit an existing Portlet and
       * returns the Control
       *
       * @param pc the existing PortletControl
       * @param portlet the existing Portlet to be associated with the control
       * @return first PortletControl associated with the portlet
       */
      public PortletControl initControl( PortletControl pc, Portlet portlet );
  
  }
  
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/controlfactory/JetspeedControlFactoryService.java
  
  Index: JetspeedControlFactoryService.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.services.controlfactory;
  
  //jetspeed stuff
  import org.apache.jetspeed.portal.Portlet;
  import org.apache.jetspeed.portal.PortletSet;
  import org.apache.jetspeed.portal.PortletControl;
  import org.apache.jetspeed.portal.PortletControlConfig;
  import org.apache.jetspeed.om.newregistry.PortletControlEntry;
  import org.apache.jetspeed.services.Registry;
  import org.apache.jetspeed.xml.api.portletmarkup.Control;
  import org.apache.jetspeed.xml.api.portletmarkup.Parameter;
  
  import org.apache.turbine.services.*;
  import org.apache.turbine.services.resources.ResourceService;
  import org.apache.turbine.util.Log;
  
  import java.util.Enumeration;
  import java.util.Hashtable;
  import java.util.Map;
  import javax.servlet.ServletConfig;
  
  /**
   * Simple implementation of the ControlFactoryService. This implementation
   * creates a new object instance for each invocation.
   * 
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @version $Id: JetspeedControlFactoryService.java,v 1.1 2001/05/02 21:15:25 raphael Exp $
   */
  public class JetspeedControlFactoryService extends TurbineBaseService
      implements ControlFactoryService
  {
  
      /** The default control to use when none is specified */
      private String defaultControl = null;
              
      /**
       * This is the early initialization method called by the 
       * Turbine <code>Service</code> framework
       */
      public void init( ServletConfig conf ) throws InitializationException
      {
  
          ResourceService serviceConf = ((TurbineServices)TurbineServices.getInstance())
                                                       .getResources(ControlFactoryService.SERVICE_NAME);
  
          this.defaultControl = serviceConf.getString("default");
          
          setInit(true);
  
      }
              
      /**
       * Instanciates a PortletControl based on a Registry entry, if available 
       * or directly from a classname.
       *
       * @param name a PortletControl name available in the registry or a classname
       * @return the created PortletControl
       */
      public PortletControl getPortletControl( String name )
      {
  
          PortletControl pc = null;
          PortletControlEntry entry = (PortletControlEntry)Registry.getEntry(Registry.PORTLET_CONTROL, name);
          Map params = null;
          
          try
          {
              if (entry == null)
              {
                  pc = (PortletControl)Class.forName(name).newInstance();
                  params = new Hashtable();
              }
              else
              {
                  pc = (PortletControl)Class.forName(entry.getClassname()).newInstance();
                  params = entry.getParameterMap();
              }
          }
          catch (Exception e)
          {
              Log.error("Unable to instanciate control "+name+", using default", e);
              if (defaultControl != null) return getPortletControl( defaultControl );
          }
  
          PortletControlConfig pcConf = new PortletControlConfig();
          pcConf.setInitParameters(params);
          pc.setConfig(pcConf);
  
          return pc;
  
      }
  
      /**
       * Instanciates a PortletControl based on a PSML Control object
       *
       * @param control the PSML control object
       * @return the created PortletControl
       */
      public PortletControl getPortletControl( Control control )
      {
  
          PortletControl pc = null;
  
          if (control!=null)
          {
              pc = getPortletControl(control.getName());
              pc.getConfig().getInitParameters().putAll(getParameters(control));
          }
          else
          {
              if (defaultControl!=null)
              {
                  pc = getPortletControl(this.defaultControl);
              }
          }
  
          return pc;
      }
  
  
      /**
       * Associates a PortletControl wit an existing Portlet and
       * returns the Control
       *
       * @param pc the existing PortletControl
       * @param portlet the existing Portlet to be associated with the control
       * @return first PortletControl associated with the portlet
       */
      public PortletControl initControl( PortletControl pc, Portlet portlet )
      {
  
          if (portlet == null)
          {
              throw new IllegalArgumentException( "Portlet not specified" );
          }
  
          if ( pc == null )
          {
              throw new IllegalArgumentException( "PortletControl not specified" );
          }
  
          pc.getConfig().setParameters(portlet.getPortletConfig().getParameters());
          pc.init( portlet );
  
          return pc;
  
      }
  
      /**
       * Retrieves the parameters from a PSML Control object
       *
       * @param control the PSML object to explore
       * @return a Map of the existing control parameters or an empty map
       */
      protected Map getParameters(Control control)
      {
          Hashtable hash = new Hashtable();
  
          if (control!=null)
          {
              Parameter[] params = control.getParameter();
  
              for (int i=0; i < params.length; i++ )
              {
                  hash.put(params[i].getName(),params[i].getValue());
              }
          }
          return hash;
      }
  
  }
  
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/controllerfactory/ControllerFactoryService.java
  
  Index: ControllerFactoryService.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.services.controllerfactory;
  
  //jetspeed stuff
  import org.apache.jetspeed.portal.Portlet;
  import org.apache.jetspeed.portal.PortletController;
  import org.apache.jetspeed.xml.api.portletmarkup.Controller;
  import org.apache.turbine.services.Service;
   
  /**
   * This service creates new PortletController instances from various
   * descriptor objects.
   * 
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @version $Id: ControllerFactoryService.java,v 1.1 2001/05/02 21:15:27 raphael Exp $
   */
  public interface ControllerFactoryService extends Service
  {
  
      /** The default control to use when none is specified */
      public String SERVICE_NAME = "ControllerFactory";
              
      /**
       * Instanciates a PortletController based on a Registry entry, if available 
       * or directly from a classname.
       *
       * @param name a PortletController name available in the registry or a classname
       * @return the created PortletController
       */
      public PortletController getPortletController( String name );
  
      /**
       * Instanciates a PortletController based on a PSML Controller object
       *
       * @param control the PSML controller object
       * @return the created PortletController
       */
      public PortletController getPortletController( Controller controller );
  
  }
  
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/controllerfactory/JetspeedControllerFactoryService.java
  
  Index: JetspeedControllerFactoryService.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.services.controllerfactory;
  
  //jetspeed stuff
  import org.apache.jetspeed.portal.Portlet;
  import org.apache.jetspeed.portal.PortletSet;
  import org.apache.jetspeed.portal.PortletController;
  import org.apache.jetspeed.portal.PortletControllerConfig;
  import org.apache.jetspeed.om.newregistry.PortletControllerEntry;
  import org.apache.jetspeed.services.Registry;
  import org.apache.jetspeed.xml.api.portletmarkup.Controller;
  import org.apache.jetspeed.xml.api.portletmarkup.Parameter;
  
  import org.apache.turbine.services.*;
  import org.apache.turbine.services.resources.ResourceService;
  import org.apache.turbine.util.Log;
  
  import java.util.Enumeration;
  import java.util.Hashtable;
  import java.util.Map;
  import javax.servlet.ServletConfig;
  
  /**
   * Simple implementation of the ControllerFactoryService. This implementation
   * creates a new object instance for each invocation.
   * 
   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
   * @version $Id: JetspeedControllerFactoryService.java,v 1.1 2001/05/02 21:15:27 raphael Exp $
   */
  public class JetspeedControllerFactoryService extends TurbineBaseService
      implements ControllerFactoryService
  {
  
      /** The default controller to use when none is specified */
      private String defaultController = null;
              
      /**
       * This is the early initialization method called by the 
       * Turbine <code>Service</code> framework
       */
      public void init( ServletConfig conf ) throws InitializationException
      {
  
          ResourceService serviceConf = ((TurbineServices)TurbineServices.getInstance())
                                                       .getResources(ControllerFactoryService.SERVICE_NAME);
  
          this.defaultController = serviceConf.getString("default");
          
          setInit(true);
  
      }
              
      /**
       * Instanciates a PortletController based on a Registry entry, if available 
       * or directly from a classname.
       *
       * @param name a PortletController name available in the registry or a classname
       * @return the created PortletController
       */
      public PortletController getPortletController( String name )
      {
  
          PortletController pc = null;
          PortletControllerEntry entry = (PortletControllerEntry)Registry
                                              .getEntry(Registry.PORTLET_CONTROLLER, name);
          Map params = null;
          
          try
          {
              if (entry == null)
              {
                  pc = (PortletController)Class.forName(name).newInstance();
                  params = new Hashtable();
              }
              else
              {
                  pc = (PortletController)Class.forName(entry.getClassname()).newInstance();
                  params = entry.getParameterMap();
              }
          }
          catch (Exception e)
          {
              Log.error("Unable to instanciate controller "+name+", using default", e);
              if (defaultController != null) return getPortletController( defaultController );
          }
  
          PortletControllerConfig pcConf = new PortletControllerConfig();
          pcConf.setInitParameters(params);
          pc.setConfig(pcConf);
          pc.init();
          
          return pc;
  
      }
  
      /**
       * Instanciates a PortletController based on a PSML Controller object
       *
       * @param controller the PSML controller object
       * @return the created PortletController
       */
      public PortletController getPortletController( Controller controller )
      {
  
          PortletController pc = null;
  
          if (controller!=null)
          {
              pc = getPortletController(controller.getName());
              pc.getConfig().getInitParameters().putAll(getParameters(controller));
          }
          else
          {
              if (defaultController!=null)
              {
                  pc = getPortletController(this.defaultController);
              }
          }
  
          pc.init();
  
          return pc;
      }
  
      /**
       * Retrieves the parameters from a PSML Controller object
       *
       * @param controller the PSML object to explore
       * @return a Map of the existing controller parameters or an empty map
       */
      protected Map getParameters(Controller controller)
      {
          Hashtable hash = new Hashtable();
  
          if (controller!=null)
          {
              Parameter[] params = controller.getParameter();
  
              for (int i=0; i < params.length; i++ )
              {
                  hash.put(params[i].getName(),params[i].getValue());
              }
          }
          return hash;
      }
  
  }
  
  
  
  

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