[jboss-cvs] jboss-seam/src/main/org/jboss/seam/init ...

Gavin King gavin.king at jboss.com
Sun Oct 8 10:01:53 EDT 2006


  User: gavin   
  Date: 06/10/08 10:01:53

  Modified:    src/main/org/jboss/seam/init  Initialization.java
  Log:
  refactored framework
  added converters for page parameters
  fixed bugs in <factory/>
  added <factory value=...>
  
  Revision  Changes    Path
  1.90      +74 -11    jboss-seam/src/main/org/jboss/seam/init/Initialization.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Initialization.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/init/Initialization.java,v
  retrieving revision 1.89
  retrieving revision 1.90
  diff -u -b -r1.89 -r1.90
  --- Initialization.java	5 Oct 2006 21:15:23 -0000	1.89
  +++ Initialization.java	8 Oct 2006 14:01:53 -0000	1.90
  @@ -100,7 +100,7 @@
   /**
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.89 $
  + * @version $Revision: 1.90 $
    */
   public class Initialization
   {
  @@ -112,6 +112,7 @@
      private ServletContext servletContext;
      private boolean isScannerEnabled = true;
      private List<ComponentDescriptor> componentDescriptors = new ArrayList<ComponentDescriptor>();
  +   private List<FactoryDescriptor> factoryDescriptors = new ArrayList<FactoryDescriptor>();
      private Set<Class> installedComponents = new HashSet<Class>();
   
      public Initialization(ServletContext servletContext)
  @@ -157,13 +158,21 @@
               for (Element factory: factoryElements)
               {
                  String scopeName = factory.attributeValue("scope");
  -               Init.instance().addFactory(
  -                     factory.attributeValue("name"),
  -                     factory.attributeValue("expression"),
  -                     scopeName==null ?
  +               String name = factory.attributeValue("name");
  +               if (name==null) 
  +               {
  +                  throw new IllegalArgumentException("must specify name in <factory/> declaration");
  +               }
  +               String method = factory.attributeValue("method");
  +               String value = factory.attributeValue("value");
  +               if (method==null && value==null)
  +               {
  +                  throw new IllegalArgumentException("must specify either method or value in <factory/> declaration for variable: " + name);
  +               }
  +               ScopeType scope = scopeName==null ?
                              ScopeType.UNSPECIFIED :
  -                           ScopeType.valueOf( scopeName.toUpperCase() )
  -                  );
  +                     ScopeType.valueOf( scopeName.toUpperCase() );
  +               factoryDescriptors.add( new FactoryDescriptor(name, scope, method, value) );
               }
   
            }
  @@ -201,7 +210,7 @@
         }
         else if (name==null)
         {
  -         throw new IllegalArgumentException("must specify either class or name in components.xml");
  +         throw new IllegalArgumentException("must specify either class or name in <component/> declaration");
         }
   
         List<Element> props = component.elements("property");
  @@ -210,7 +219,7 @@
            String propName = prop.attributeValue("name");
            if (propName==null)
            {
  -            throw new IllegalArgumentException("no name for property of component: " + name);
  +            throw new IllegalArgumentException("must specify name in <property/> declaration of component: " + name);
            }
            String qualifiedPropName = name + '.' + propName;
            properties.put( qualifiedPropName, getPropertyValue(prop, qualifiedPropName, replacements) );
  @@ -432,7 +441,7 @@
            addComponent( QueueSession.class, context );
         }
   
  -      for ( ComponentDescriptor componentDescriptor : componentDescriptors )
  +      for ( ComponentDescriptor componentDescriptor: componentDescriptors )
         {
            addComponent( componentDescriptor, context );
         }
  @@ -446,6 +455,18 @@
            }
         }
   
  +      for (FactoryDescriptor factoryDescriptor: factoryDescriptors)
  +      {
  +         if ( factoryDescriptor.isValueBinding() )
  +         {
  +            init.addFactoryValueBinding(factoryDescriptor.name, factoryDescriptor.value, factoryDescriptor.scope);
  +         }
  +         else
  +         {
  +            init.addFactoryMethodBinding(factoryDescriptor.name, factoryDescriptor.method, factoryDescriptor.scope);
  +         }
  +      }
  +
      }
   
      private void addComponentRoles(Context context, Class<Object> componentClass) {
  @@ -501,6 +522,48 @@
         return this;
      }
   
  +   private static class FactoryDescriptor
  +   {
  +      private String name;
  +      private ScopeType scope;
  +      private String method;
  +      private String value;
  +      
  +      public FactoryDescriptor(String name, ScopeType scope, String method, String value)
  +      {
  +         super();
  +         this.name = name;
  +         this.scope = scope;
  +         this.method = method;
  +         this.value = value;
  +      }
  +
  +      public String getMethod()
  +      {
  +         return method;
  +      }
  +
  +      public String getValue()
  +      {
  +         return value;
  +      }
  +
  +      public String getName()
  +      {
  +         return name;
  +      }
  +
  +      public ScopeType getScope()
  +      {
  +         return scope;
  +      }
  +      
  +      public boolean isValueBinding()
  +      {
  +         return method==null;
  +      }
  +   }
  +
      private static class ComponentDescriptor
      {
         private String name;
  
  
  



More information about the jboss-cvs-commits mailing list