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

Gavin King gavin.king at jboss.com
Mon Jul 17 14:11:36 EDT 2006


  User: gavin   
  Date: 06/07/17 14:11:36

  Modified:    src/main/org/jboss/seam  Component.java
  Log:
  improved impl of factory methods
  
  Revision  Changes    Path
  1.146     +14 -10    jboss-seam/src/main/org/jboss/seam/Component.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Component.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/Component.java,v
  retrieving revision 1.145
  retrieving revision 1.146
  diff -u -b -r1.145 -r1.146
  --- Component.java	14 Jul 2006 19:21:17 -0000	1.145
  +++ Component.java	17 Jul 2006 18:11:36 -0000	1.146
  @@ -86,7 +86,7 @@
    *
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
    * @author Gavin King
  - * @version $Revision: 1.145 $
  + * @version $Revision: 1.146 $
    */
   @Scope(ScopeType.APPLICATION)
   public class Component
  @@ -1357,11 +1357,8 @@
   
      private static Object handleFactoryMethodResult(String name, Component component, Object result, ScopeType scope)
      {
  -      if (result==null) //a factory method with a void return type
  -      {
  -         return Contexts.lookupInStatefulContexts(name);
  -      }
  -      else //a factory method returning a value
  +      Object value = Contexts.lookupInStatefulContexts(name); //see if a value was outjected by the factory method
  +      if (value==null) //usually a factory method returning a value
         {
            if (scope==ScopeType.UNSPECIFIED)
            {
  @@ -1369,15 +1366,22 @@
               {
                  throw new IllegalArgumentException("no scope specified for factory method defined in components.xml: " + name);
               }
  +            else //an @Factory method defaults to the same scope as the component
  +            {
               scope = component.getScope();
            }
  -         if ( !scope.getContext().isSet(name) ) //just in case the factory method sets the variable _and_ returns a value - should we really allow that?
  -         {
  +         }
               scope.getContext().set(name, result);
            }
  -         return result;
  +      else //usually a factory method with a void return type
  +      {
  +         if (scope!=ScopeType.UNSPECIFIED)
  +         {
  +            throw new IllegalArgumentException("factory method with defined scope outjected a value: " + name);
         }
      }
  +      return result;
  +   }
   
      public static Object newInstance(String name)
      {
  
  
  



More information about the jboss-cvs-commits mailing list