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

Gavin King gavin.king at jboss.com
Thu Jul 19 03:32:27 EDT 2007


  User: gavin   
  Date: 07/07/19 03:32:27

  Modified:    src/main/org/jboss/seam  Component.java
  Log:
  @Import
  more robust debug page
  
  Revision  Changes    Path
  1.272     +51 -1     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.271
  retrieving revision 1.272
  diff -u -b -r1.271 -r1.272
  --- Component.java	18 Jul 2007 14:37:29 -0000	1.271
  +++ Component.java	19 Jul 2007 07:32:27 -0000	1.272
  @@ -61,6 +61,7 @@
   import org.jboss.seam.annotations.DataSelectorClass;
   import org.jboss.seam.annotations.Destroy;
   import org.jboss.seam.annotations.End;
  +import org.jboss.seam.annotations.Import;
   import org.jboss.seam.annotations.In;
   import org.jboss.seam.annotations.JndiName;
   import org.jboss.seam.annotations.Observer;
  @@ -182,6 +183,8 @@
      private List<Field> logFields = new ArrayList<Field>();
      private List<org.jboss.seam.log.Log> logInstances = new ArrayList<org.jboss.seam.log.Log>();
   
  +   private Collection<Namespace> imports = new ArrayList<Namespace>();
  +
      private Class<ProxyObject> factory;
   
      //only used for tests
  @@ -221,6 +224,7 @@
         checkNonabstract();
         
         initNamespaces(componentName, applicationContext);
  +      initImports(applicationContext);
         initSynchronize();
         initStartup();
   
  @@ -344,10 +348,43 @@
                  String token = tokens.nextToken();
                  if ( tokens.hasMoreTokens() ) //we don't want to create a namespace for the name
                  {
  -                  namespace.getOrCreateChild(token);
  +                  namespace = namespace.getOrCreateChild(token);
  +               }
  +            }
  +         }
  +      }
  +   }
  +   
  +   private void initImports(Context applicationContext)
  +   {
  +      if (applicationContext!=null) //for unit tests!
  +      {
  +         Init init = (Init) applicationContext.get( Seam.getComponentName(Init.class) );
  +         if (init!=null)
  +         {
  +            if ( getBeanClass().isAnnotationPresent(Import.class) )
  +            {
  +               addImport( init, getBeanClass().getAnnotation(Import.class) );
  +            }
  +            if ( getBeanClass().getPackage().isAnnotationPresent(Import.class) )
  +            {
  +               addImport( init, getBeanClass().getPackage().getAnnotation(Import.class) );
  +            }
                  }
               }
            }
  +
  +   private void addImport(Init init, Import imp)
  +   {
  +      for ( String ns: imp.value() )
  +      {
  +         Namespace namespace = init.getRootNamespace();
  +         StringTokenizer tokens = new StringTokenizer(ns, ".");
  +         while ( tokens.hasMoreTokens() )
  +         {
  +            namespace = namespace.getOrCreateChild( tokens.nextToken() );
  +         }
  +         imports.add(namespace);
         }
      }
   
  @@ -2024,6 +2061,14 @@
            result = getInstance(name, create);
            if (result==null)
            {
  +            for ( Namespace namespace: getImports() )
  +            {
  +               result = namespace.getComponentInstance(name, create);
  +               if (result!=null) break; 
  +            }
  +         }
  +         if (result==null)
  +         {
               for ( Namespace namespace: Init.instance().getGlobalImports() )
               {
                  result = namespace.getComponentInstance(name, create);
  @@ -2447,4 +2492,9 @@
         return pcAttributes;
      }
      
  +   public Collection<Namespace> getImports()
  +   {
  +      return imports;
  +   }
  +   
   }
  
  
  



More information about the jboss-cvs-commits mailing list