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

Gavin King gavin.king at jboss.com
Sun Nov 19 13:13:06 EST 2006


  User: gavin   
  Date: 06/11/19 13:13:06

  Modified:    src/main/org/jboss/seam/init  Initialization.java
  Log:
  introduce genericDependencies
  
  Revision  Changes    Path
  1.120     +357 -359  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.119
  retrieving revision 1.120
  diff -u -b -r1.119 -r1.120
  --- Initialization.java	18 Nov 2006 00:38:23 -0000	1.119
  +++ Initialization.java	19 Nov 2006 18:13:06 -0000	1.120
  @@ -1,8 +1,7 @@
   /*
    * JBoss, Home of Professional Open Source
    *
  - * Distributable under LGPL license.
  - * See terms of license at gnu.org.
  + * Distributable under LGPL license. See terms of license at gnu.org.
    */
   package org.jboss.seam.init;
   
  @@ -37,72 +36,15 @@
   import org.jboss.seam.contexts.Context;
   import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.contexts.Lifecycle;
  -import org.jboss.seam.core.Actor;
  -import org.jboss.seam.core.ApplicationContext;
  -import org.jboss.seam.core.BusinessProcess;
  -import org.jboss.seam.core.BusinessProcessContext;
  -import org.jboss.seam.core.Conversation;
  -import org.jboss.seam.core.ConversationContext;
  -import org.jboss.seam.core.ConversationEntries;
  -import org.jboss.seam.core.ConversationList;
  -import org.jboss.seam.core.ConversationStack;
  -import org.jboss.seam.core.EventContext;
  -import org.jboss.seam.core.Events;
  -import org.jboss.seam.core.Exceptions;
  -import org.jboss.seam.core.Expressions;
  -import org.jboss.seam.core.FacesContext;
  -import org.jboss.seam.core.FacesMessages;
  -import org.jboss.seam.core.FacesPage;
  -import org.jboss.seam.core.HttpError;
   import org.jboss.seam.core.Init;
  -import org.jboss.seam.core.Interpolator;
  -import org.jboss.seam.core.IsUserInRole;
   import org.jboss.seam.core.Jbpm;
  -import org.jboss.seam.core.Locale;
  -import org.jboss.seam.core.LocaleSelector;
  -import org.jboss.seam.core.ManagedJbpmContext;
   import org.jboss.seam.core.ManagedPersistenceContext;
  -import org.jboss.seam.core.Manager;
  -import org.jboss.seam.core.Messages;
  -import org.jboss.seam.core.PageContext;
  -import org.jboss.seam.core.Pageflow;
  -import org.jboss.seam.core.Pages;
  -import org.jboss.seam.core.PersistenceContexts;
   import org.jboss.seam.core.PojoCache;
  -import org.jboss.seam.core.PooledTask;
  -import org.jboss.seam.core.PooledTaskInstanceList;
  -import org.jboss.seam.core.ProcessInstance;
  -import org.jboss.seam.core.Redirect;
  -import org.jboss.seam.core.ResourceBundle;
  -import org.jboss.seam.core.SafeActions;
  -import org.jboss.seam.core.SessionContext;
  -import org.jboss.seam.core.Switcher;
  -import org.jboss.seam.core.TaskInstance;
  -import org.jboss.seam.core.TaskInstanceList;
  -import org.jboss.seam.core.TaskInstanceListForType;
  -import org.jboss.seam.core.Transition;
  -import org.jboss.seam.core.UiComponent;
  -import org.jboss.seam.core.UserPrincipal;
  -import org.jboss.seam.core.Validation;
   import org.jboss.seam.debug.Introspector;
   import org.jboss.seam.deployment.ComponentScanner;
   import org.jboss.seam.deployment.NamespaceScanner;
  -import org.jboss.seam.framework.CurrentDate;
  -import org.jboss.seam.framework.CurrentDatetime;
  -import org.jboss.seam.framework.CurrentTime;
  -import org.jboss.seam.jms.ManagedQueueSender;
  -import org.jboss.seam.jms.ManagedTopicPublisher;
  -import org.jboss.seam.jms.QueueConnection;
  -import org.jboss.seam.jms.QueueSession;
  -import org.jboss.seam.jms.TopicConnection;
  -import org.jboss.seam.jms.TopicSession;
   import org.jboss.seam.persistence.HibernatePersistenceProvider;
   import org.jboss.seam.persistence.PersistenceProvider;
  -import org.jboss.seam.remoting.RemotingConfig;
  -import org.jboss.seam.remoting.messaging.SubscriptionRegistry;
  -import org.jboss.seam.security.SeamSecurityManager;
  -import org.jboss.seam.theme.Theme;
  -import org.jboss.seam.theme.ThemeSelector;
   import org.jboss.seam.util.Conversions;
   import org.jboss.seam.util.DTDEntityResolver;
   import org.jboss.seam.util.Naming;
  @@ -112,23 +54,20 @@
   /**
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.119 $
  + * @version $Revision: 1.120 $
    */
   public class Initialization
   {
      public static final String COMPONENT_SUFFIX = ".component";
  -
      private static final Log log = LogFactory.getLog(Initialization.class);
   
  -   private Map<String, Conversions.PropertyValue> properties = new HashMap<String, Conversions.PropertyValue>();
      private ServletContext servletContext;
  +   private Map<String, Conversions.PropertyValue> properties = new HashMap<String, Conversions.PropertyValue>();
      private List<ComponentDescriptor> componentDescriptors = new ArrayList<ComponentDescriptor>();
      private List<FactoryDescriptor> factoryDescriptors = new ArrayList<FactoryDescriptor>();
      private Set<Class> installedComponents = new HashSet<Class>();
      private Set<String> importedPackages = new HashSet<String>();
  -
  -
  -   private Map<String,NamespaceInfo> namespaceMap = new HashMap<String, NamespaceInfo>();
  +   private Map<String, NamespaceInfo> namespaceMap = new HashMap<String, NamespaceInfo>();
   
      public Initialization(ServletContext servletContext)
      {
  @@ -147,7 +86,8 @@
         Enumeration<URL> resources;
         try
         {
  -         resources = Thread.currentThread().getContextClassLoader().getResources("META-INF/components.xml");
  +         resources = Thread.currentThread().getContextClassLoader().getResources(
  +                  "META-INF/components.xml");
         }
         catch (IOException ioe)
         {
  @@ -155,13 +95,13 @@
         }
         
         Properties replacements = getReplacements();
  -      while ( resources.hasMoreElements() )
  +      while (resources.hasMoreElements())
         {
            URL url = resources.nextElement();
            try
            {
               log.info("reading " + url);
  -            installComponentsFromXmlElements( getDocument( url.openStream() ), replacements );
  +            installComponentsFromXmlElements(getDocument(url.openStream()), replacements);
            }
            catch (Exception e)
            {
  @@ -174,7 +114,7 @@
      private void initComponentsFromXmlDocument()
      {
         InputStream stream = Resources.getResourceAsStream("/WEB-INF/components.xml", servletContext);
  -      if (stream==null)
  +      if (stream == null)
         {
            log.info("no /WEB-INF/components.xml file found");
         }
  @@ -183,7 +123,7 @@
            log.info("reading /WEB-INF/components.xml");
            try
            {
  -            installComponentsFromXmlElements( getDocument(stream), getReplacements() );
  +            installComponentsFromXmlElements(getDocument(stream), getReplacements());
            }
            catch (Exception e)
            {
  @@ -198,7 +138,7 @@
         {
            Properties replacements = new Properties();
            InputStream replaceStream = Resources.getResourceAsStream("components.properties");
  -         if (replaceStream!=null) replacements.load( replaceStream );
  +         if (replaceStream != null) replacements.load(replaceStream);
            return replacements;
         }
         catch (IOException ioe)
  @@ -207,10 +147,11 @@
         }
      }
   
  -   private void installComponentsFromXmlElements(Document doc, Properties replacements) throws DocumentException, ClassNotFoundException
  +   private void installComponentsFromXmlElements(Document doc, Properties replacements)
  +            throws DocumentException, ClassNotFoundException
      {
         List<Element> importElements = doc.getRootElement().elements("import-java-package");
  -      for (Element importElement: importElements)
  +      for (Element importElement : importElements)
         {
             String pkgName = importElement.getTextTrim();
             importedPackages.add(pkgName);
  @@ -218,56 +159,61 @@
         }
   
         List<Element> componentElements = doc.getRootElement().elements("component");
  -      for (Element component: componentElements)
  +      for (Element component : componentElements)
         {
  -            installComponentFromXmlElement(component, 
  -                                           component.attributeValue("name"), 
  -                                           component.attributeValue("class"), 
  -                                           replacements);
  +         installComponentFromXmlElement(component, component.attributeValue("name"), component
  +                  .attributeValue("class"), replacements);
         }
   
         List<Element> factoryElements = doc.getRootElement().elements("factory");
  -      for (Element factory: factoryElements)
  +      for (Element factory : factoryElements)
         {
            installFactoryFromXmlElement(factory);
         }
   
         // assume anything with a namespace is a component
         // ok for now - might need to change later
  -      for (Element elem: (List<Element>) doc.getRootElement().elements()) {
  +      for (Element elem : (List<Element>) doc.getRootElement().elements())
  +      {
             String ns = elem.getNamespace().getURI();
             NamespaceInfo nsInfo = namespaceMap.get(ns);
  -          if (nsInfo != null) {
  +         if (nsInfo != null)
  +         {
                     String name = elem.attributeValue("name");
   
                     String className = nsInfo.getPackage().getName() + "." + elem.getName();
  -                  try {
  +            try
  +            {
                         Class<Object> clazz = Reflections.classForName(className);
  -                      if (name == null) {
  +               if (name == null)
  +               {
                             Name  anno = clazz.getAnnotation(Name.class);
  -                          if (anno != null) {
  +                  if (anno != null)
  +                  {
                                 name = anno.value();
                             }
                         }
  -                  } catch (ClassNotFoundException e) {
  +            }
  +            catch (ClassNotFoundException e)
  +            {
                         // if it isn't a classname, set 
                         className = null; 
                     }
                     
  -                  if (name == null) {
  +            if (name == null)
  +            {
                         String prefix = nsInfo.getNamespace().prefix();
  -                      if ((prefix==null) || (prefix.length()==0)) {
  +               if ((prefix == null) || (prefix.length() == 0))
  +               {
                             name = elem.getName();
  -                      } else { 
  +               }
  +               else
  +               {
                             name = prefix + "." + elem.getName();
                         }
                     }
   
  -                  installComponentFromXmlElement(elem, 
  -                                                 name,
  -                                                 className, 
  -                                                 replacements);
  -//               }
  +            installComponentFromXmlElement(elem, name, className, replacements);
             }
         }
      }
  @@ -276,30 +222,28 @@
      {
         String scopeName = factory.attributeValue("scope");
         String name = factory.attributeValue("name");
  -      if (name==null)
  +      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)
  +      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() );
  -      boolean autoCreate = "true".equals( factory.attributeValue("auto-create") );
  -      factoryDescriptors.add( new FactoryDescriptor(name, scope, method, value, autoCreate) );
  +                  "must specify either method or value in <factory/> declaration for variable: "
  +                           + name);
  +      }
  +      ScopeType scope = scopeName == null ? ScopeType.UNSPECIFIED : ScopeType.valueOf(scopeName
  +               .toUpperCase());
  +      boolean autoCreate = "true".equals(factory.attributeValue("auto-create"));
  +      factoryDescriptors.add(new FactoryDescriptor(name, scope, method, value, autoCreate));
      }
   
      private Document getDocument(InputStream stream) throws DocumentException
      {
         SAXReader saxReader = new SAXReader();
  -      saxReader.setEntityResolver( new DTDEntityResolver() );
  +      saxReader.setEntityResolver(new DTDEntityResolver());
         saxReader.setMergeAdjacentText(true);
         Document doc = saxReader.read(stream);
         return doc;
  @@ -307,30 +251,28 @@
   
      private String replace(String value, Properties replacements)
      {
  -      if ( value.startsWith("@") )
  +      if (value.startsWith("@"))
         {
  -         value = replacements.getProperty( value.substring(1, value.length()-1) );
  +         value = replacements.getProperty(value.substring(1, value.length() - 1));
         }
         return value;
      }
   
  -   private void installComponentFromXmlElement(Element component, 
  -                                               String name, 
  -                                               String className, 
  -                                               Properties replacements) 
  -       throws ClassNotFoundException
  +   private void installComponentFromXmlElement(Element component, String name, String className,
  +            Properties replacements) throws ClassNotFoundException
      {
         String installText = component.attributeValue("installed");
         boolean installed = false;
  -      if (installText == null || "true".equals(replace(installText, replacements))) {
  +      if (installText == null || "true".equals(replace(installText, replacements)))
  +      {
             installed = true;
         }
   
         String scopeName = component.attributeValue("scope");
         String jndiName = component.attributeValue("jndi-name");
  -      ScopeType scope = scopeName==null ? null : ScopeType.valueOf(scopeName.toUpperCase());
  -      boolean autoCreate = "true".equals( component.attributeValue("auto-create") );
  -      if (className!=null)
  +      ScopeType scope = scopeName == null ? null : ScopeType.valueOf(scopeName.toUpperCase());
  +      boolean autoCreate = "true".equals(component.attributeValue("auto-create"));
  +      if (className != null)
         {
            Class<?> clazz = null;
            try
  @@ -339,74 +281,83 @@
            }
            catch (ClassNotFoundException cnfe)
            {
  -            for (String pkg: importedPackages)
  +            for (String pkg : importedPackages)
               {
                  try
                  {
                     clazz = Reflections.classForName(pkg + '.' + className);
                     break;
                  }
  -               catch (Exception e) {}
  +               catch (Exception e)
  +               {
  +               }
               }
  -            if (clazz==null) throw cnfe;
  +            if (clazz == null) throw cnfe;
            }
   
  -         if (name==null)
  +         if (name == null)
            {
               name = clazz.getAnnotation(Name.class).value();
            }
   
  -         componentDescriptors.add( new ComponentDescriptor(name, clazz, scope, autoCreate, jndiName, installed) );
  +         ComponentDescriptor descriptor = new ComponentDescriptor(name, clazz, scope, autoCreate, jndiName, installed);
  +         componentDescriptors.add(descriptor);
            installedComponents.add(clazz);
         }
  -      else if (name==null)
  +      else if (name == null)
         {
  -         throw new IllegalArgumentException("must specify either class or name in <component/> declaration");
  +         throw new IllegalArgumentException(
  +                  "must specify either class or name in <component/> declaration");
         }
   
  -      for (Element prop: (List<Element>) component.elements()) {
  +      for (Element prop : (List<Element>) component.elements())
  +      {
             String propName = prop.attributeValue("name");
  -          if (propName==null) {
  +         if (propName == null)
  +         {
                 propName = prop.getQName().getName();
             }
             String qualifiedPropName = name + '.' + propName;
  -          properties.put( qualifiedPropName, getPropertyValue(prop, qualifiedPropName, replacements) );
  +         properties.put(qualifiedPropName, getPropertyValue(prop, qualifiedPropName, replacements));
         }
      }
   
  -   private Conversions.PropertyValue getPropertyValue(Element prop, String propName, Properties replacements)
  +   private Conversions.PropertyValue getPropertyValue(Element prop, String propName,
  +            Properties replacements)
      {
         List<Element> keyElements = prop.elements("key");
         List<Element> valueElements = prop.elements("value");
   
         Conversions.PropertyValue propertyValue;
  -      if ( valueElements.isEmpty() && keyElements.isEmpty() )
  +      if (valueElements.isEmpty() && keyElements.isEmpty())
         {
  -         propertyValue = new Conversions.FlatPropertyValue( trimmedText(prop, propName, replacements) );
  +         propertyValue = new Conversions.FlatPropertyValue(
  +                  trimmedText(prop, propName, replacements));
         }
  -      else if ( keyElements.isEmpty() )
  +      else if (keyElements.isEmpty())
         {
  -         //a list-like structure
  +         // a list-like structure
            int len = valueElements.size();
            String[] values = new String[len];
  -         for (int i=0; i<len; i++)
  +         for (int i = 0; i < len; i++)
            {
  -            values[i] = trimmedText( valueElements.get(i), propName, replacements );
  +            values[i] = trimmedText(valueElements.get(i), propName, replacements);
            }
            propertyValue = new Conversions.MultiPropertyValue(values);
         }
         else
         {
  -         //a map-like structure
  -         if ( valueElements.size()!=keyElements.size() )
  +         // a map-like structure
  +         if (valueElements.size() != keyElements.size())
            {
  -            throw new IllegalArgumentException("value elements must match key elements: " + propName);
  +            throw new IllegalArgumentException("value elements must match key elements: "
  +                     + propName);
            }
            Map<String, String> keyedValues = new HashMap<String, String>();
  -         for (int i=0; i<keyElements.size(); i++)
  +         for (int i = 0; i < keyElements.size(); i++)
            {
  -            String key = trimmedText( keyElements.get(i), propName, replacements );
  -            String value = trimmedText( valueElements.get(i), propName, replacements );
  +            String key = trimmedText(keyElements.get(i), propName, replacements);
  +            String value = trimmedText(valueElements.get(i), propName, replacements);
               keyedValues.put(key, value);
            }
            propertyValue = new Conversions.AssociativePropertyValue(keyedValues);
  @@ -418,9 +369,10 @@
      private String trimmedText(Element element, String propName, Properties replacements)
      {
         String text = element.getTextTrim();
  -      if (text==null)
  +      if (text == null)
         {
  -         throw new IllegalArgumentException("property value must be specified in element body: " + propName);
  +         throw new IllegalArgumentException("property value must be specified in element body: "
  +                  + propName);
         }
         return replace(text, replacements);
      }
  @@ -446,10 +398,13 @@
      private void scanForComponents()
      {
         Set<Package> scannedPackages = new HashSet<Package>();
  -      for (Class<Object> scannedClass: new ComponentScanner("seam.properties").getClasses()) {
  +      for (Class<Object> scannedClass : new ComponentScanner("seam.properties").getClasses())
  +      {
             installScannedClass(scannedPackages, scannedClass);
         }
  -      for (Class<Object> scannedClass: new ComponentScanner("META-INF/components.xml").getClasses()) {
  +      for (Class<Object> scannedClass : new ComponentScanner("META-INF/components.xml")
  +               .getClasses())
  +      {
             installScannedClass(scannedPackages, scannedClass);
         }
      }
  @@ -457,11 +412,11 @@
      private void installScannedClass(Set<Package> scannedPackages, Class<Object> scannedClass)
      {
         installScannedComponentAndRoles(scannedClass);
  -      installComponentsFromDescriptor( classDescriptorFilename(scannedClass), scannedClass );
  +      installComponentsFromDescriptor(classDescriptorFilename(scannedClass), scannedClass);
         Package pkg = scannedClass.getPackage();
  -      if ( pkg!=null && scannedPackages.add(pkg) )
  +      if (pkg != null && scannedPackages.add(pkg))
         {
  -         installComponentsFromDescriptor( packageDescriptorFilename(pkg), scannedClass );
  +         installComponentsFromDescriptor(packageDescriptorFilename(pkg), scannedClass);
         }
      }
   
  @@ -477,23 +432,22 @@
   
      private void installComponentsFromDescriptor(String fileName, Class clazz)
      {
  -      InputStream stream = clazz.getClassLoader().getResourceAsStream(fileName); //note: this is correct, we do not need to scan other classloaders!
  -      if (stream!=null)
  +      //note: this is correct, we do not need to scan other classloaders!
  +      InputStream stream = clazz.getClassLoader().getResourceAsStream(fileName); 
  +      if (stream != null)
         {
            try
            {
               Properties replacements = getReplacements();
               Document doc = getDocument(stream);
  -            if ( doc.getRootElement().getName().equals("components") )
  +            if (doc.getRootElement().getName().equals("components"))
               {
  -               installComponentsFromXmlElements( doc, replacements );
  +               installComponentsFromXmlElements(doc, replacements);
               }
               else
               {
  -               installComponentFromXmlElement(doc.getRootElement(), 
  -                                              doc.getRootElement().attributeValue("name"),
  -                                              clazz.getName(), 
  -                                              replacements );
  +               installComponentFromXmlElement(doc.getRootElement(), doc.getRootElement()
  +                        .attributeValue("name"), clazz.getName(), replacements);
               }
            }
            catch (Exception e)
  @@ -505,18 +459,18 @@
   
      private void installScannedComponentAndRoles(Class<Object> scannedClass)
      {
  -      if ( scannedClass.isAnnotationPresent(Name.class) )
  +      if (scannedClass.isAnnotationPresent(Name.class))
         {
  -         componentDescriptors.add( new ComponentDescriptor(scannedClass) );
  +         componentDescriptors.add(new ComponentDescriptor(scannedClass));
         }
  -      if ( scannedClass.isAnnotationPresent(Role.class) )
  +      if (scannedClass.isAnnotationPresent(Role.class))
         {
  -         installRole( scannedClass, scannedClass.getAnnotation(Role.class) );
  +         installRole(scannedClass, scannedClass.getAnnotation(Role.class));
         }
  -      if ( scannedClass.isAnnotationPresent(Roles.class) )
  +      if (scannedClass.isAnnotationPresent(Roles.class))
         {
            Role[] roles = scannedClass.getAnnotation(Roles.class).value();
  -         for (Role role: roles)
  +         for (Role role : roles)
            {
               installRole(scannedClass, role);
            }
  @@ -526,21 +480,26 @@
      private void installRole(Class<Object> scannedClass, Role role)
      {
         ScopeType scope = Seam.getComponentRoleScope(scannedClass, role);
  -      componentDescriptors.add( new ComponentDescriptor( role.name(), scannedClass, scope, false, null, null ) );
  +      componentDescriptors.add(new ComponentDescriptor(role.name(), scannedClass, scope, false,
  +               null, null));
      }
   
  -    private void addNamespace(Package pkg) {
  -        if (pkg != null) {
  +   private void addNamespace(Package pkg)
  +   {
  +      if (pkg != null)
  +      {
               Namespace ns = pkg.getAnnotation(Namespace.class);
  -            if (ns != null) {
  -                log.info("Mapping namespace " + ns.value() + "  to package " + 
  -                         pkg.getName() + " with prefix=" + ns.prefix());
  +         if (ns != null)
  +         {
  +            log.info("Mapping namespace " + ns.value() + "  to package " + pkg.getName()
  +                     + " with prefix=" + ns.prefix());
                   namespaceMap.put(ns.value(), new NamespaceInfo(ns, pkg));
               }
           }
       }
   
  -    private void addNamespaces() {
  +   private void addNamespaces()
  +   {
           addNamespace(Init.class.getPackage());
           // need to solve the problem of forcing a package to load
           addNamespace(org.jboss.seam.framework.Home.class.getPackage());
  @@ -548,39 +507,42 @@
           addNamespace(org.jboss.seam.remoting.RequestContext.class.getPackage());
           addNamespace(org.jboss.seam.theme.Theme.class.getPackage());
   
  -        for (Package pkg: new NamespaceScanner("seam.properties").getPackages()) { 
  +      for (Package pkg : new NamespaceScanner("seam.properties").getPackages())
  +      {
               addNamespace(pkg);
           }
  -        for (Package pkg: new NamespaceScanner("META-INF/components.xml").getPackages()) {
  +      for (Package pkg : new NamespaceScanner("META-INF/components.xml").getPackages())
  +      {
               addNamespace(pkg);
           }
       }
   
  -
      private void initPropertiesFromServletContext()
      {
         Enumeration params = servletContext.getInitParameterNames();
         while (params.hasMoreElements())
         {
            String name = (String) params.nextElement();
  -         properties.put( name, new Conversions.FlatPropertyValue( servletContext.getInitParameter(name) ) );
  +         properties.put(name, new Conversions.FlatPropertyValue(servletContext
  +                  .getInitParameter(name)));
        }
      }
   
      private void initPropertiesFromResource()
      {
         Properties props = loadFromResource("/seam.properties");
  -      for (Map.Entry me: props.entrySet())
  +      for (Map.Entry me : props.entrySet())
         {
  -         properties.put( (String) me.getKey(), new Conversions.FlatPropertyValue( (String) me.getValue() ) );
  +         properties.put((String) me.getKey(), new Conversions.FlatPropertyValue((String) me
  +                  .getValue()));
         }
      }
   
      private void initJndiProperties()
      {
         Properties jndiProperties = new Properties();
  -      jndiProperties.putAll( loadFromResource("/jndi.properties") );
  -      jndiProperties.putAll( loadFromResource("/seam-jndi.properties") );
  +      jndiProperties.putAll(loadFromResource("/jndi.properties"));
  +      jndiProperties.putAll(loadFromResource("/seam-jndi.properties"));
         Naming.setInitialContextProperties(jndiProperties);
      }
      
  @@ -588,7 +550,7 @@
      {
         Properties props = new Properties();
         InputStream stream = Resources.getResourceAsStream(resource, servletContext);
  -      if (stream!=null)
  +      if (stream != null)
         {
            log.info("reading properties from: " + resource);
            try
  @@ -607,136 +569,148 @@
         return props;
      }
   
  -   protected ComponentDescriptor findDescriptor(Class<?> componentClass) {
  -       for (ComponentDescriptor component: componentDescriptors) {
  -           if (component.getComponentClass().equals(componentClass)) {
  +   protected ComponentDescriptor findDescriptor(Class<?> componentClass)
  +   {
  +      for (ComponentDescriptor component : componentDescriptors)
  +      {
  +         if (component.getComponentClass().equals(componentClass))
  +         {
                  return component;
              }
          }
          return null;
      }
   
  -
      protected void addComponents()
      {
         Context context = Contexts.getApplicationContext();
   
  -      //force instantiation of Init
  +      // force instantiation of Init
         addComponent(new ComponentDescriptor(Init.class), context);
         Init init = (Init) Component.getInstance(Init.class, ScopeType.APPLICATION);
   
         ComponentDescriptor desc = findDescriptor(Jbpm.class);
  -      if (desc != null && desc.isInstalled()) {
  +      if (desc != null && desc.isInstalled())
  +      {
             init.setJbpmInstalled(true);
         }
   
  -//       addComponentIfPossible( SeamSecurityManager.class, context );
  -//       addComponentIfPossible( RemotingConfig.class, context );
  -//       addComponentIfPossible( SubscriptionRegistry.class, context );
  +      // addComponentIfPossible( SeamSecurityManager.class, context );
  +      // addComponentIfPossible( RemotingConfig.class, context );
  +      // addComponentIfPossible( SubscriptionRegistry.class, context );
   
  -      try {
  +      try
  +      {
             Reflections.classForName("org.jboss.cache.aop.PojoCache");
  -          componentDescriptors.add(new ComponentDescriptor(PojoCache.class, true));
  -      } catch (ClassNotFoundException e) {
  +         componentDescriptors.add( new ComponentDescriptor(PojoCache.class, true) );
         }
  +      catch (ClassNotFoundException e) {}
   
  -      if (installedComponents.contains(ManagedPersistenceContext.class)) {
  -          try {
  +      if (installedComponents.contains(ManagedPersistenceContext.class))
  +      {
  +         try
  +         {
                 Reflections.classForName("org.hibernate.Session");
  -              componentDescriptors.add(new ComponentDescriptor(HibernatePersistenceProvider.class, true));
  -          } catch (ClassNotFoundException cnfe) {
  -              componentDescriptors.add(new ComponentDescriptor(PersistenceProvider.class, true));
  -          }
  +            componentDescriptors.add( new ComponentDescriptor(HibernatePersistenceProvider.class, true) );
          }
  -
  -      if (init.isDebug()) {
  -          componentDescriptors.add(new ComponentDescriptor(Introspector.class, true));
  -          componentDescriptors.add(new ComponentDescriptor(org.jboss.seam.debug.Contexts.class, true));
  +         catch (ClassNotFoundException cnfe)
  +         {
  +            componentDescriptors.add( new ComponentDescriptor(PersistenceProvider.class, true) );
         }
  -
  -      if (installedComponents.contains(ManagedTopicPublisher.class)) {
  -          componentDescriptors.add(new ComponentDescriptor(TopicConnection.class, true));
  -          componentDescriptors.add(new ComponentDescriptor(TopicSession.class, true));
         }
   
  -      if (installedComponents.contains(ManagedQueueSender.class)) {
  -          componentDescriptors.add(new ComponentDescriptor(QueueConnection.class, true));
  -          componentDescriptors.add(new ComponentDescriptor(QueueSession.class, true));
  +      if (init.isDebug())
  +      {
  +         componentDescriptors.add( new ComponentDescriptor(Introspector.class, true) );
  +         componentDescriptors.add( new ComponentDescriptor(org.jboss.seam.debug.Contexts.class, true) );
         }
   
  -
  +      log.info("Installing components...");
         boolean installedSomething = false;
  -      do {
  +      do
  +      {
             installedSomething = false;
  -          log.info("Instantiating components...");
  -          for (ComponentDescriptor componentDescriptor: componentDescriptors) {
  +         for (ComponentDescriptor componentDescriptor : componentDescriptors)
  +         {
                 String compName = componentDescriptor.getName() + COMPONENT_SUFFIX;
  -              if (!context.isSet(compName)) {
  -                  if (componentDescriptor.isInstalled() &&
  -                      dependenciesMet(context, componentDescriptor.getDependencies())) 
  +            if ( !context.isSet(compName) && dependenciesMet(context, componentDescriptor) )
                     {
                         addComponent(componentDescriptor, context);
  -                      if (componentDescriptor.isAutoCreate()) {
  +               if (componentDescriptor.isAutoCreate())
  +               {
                             init.addAutocreateVariable(componentDescriptor.getName());
                         }
                         installedSomething = true;
                     } 
                 }
  -          }
   
  -      } while (installedSomething);
  +      }
  +      while (installedSomething);
   
  -      for (FactoryDescriptor factoryDescriptor: factoryDescriptors)
  +      for (FactoryDescriptor factoryDescriptor : factoryDescriptors)
         {
  -         if ( factoryDescriptor.isValueBinding() )
  +         if (factoryDescriptor.isValueBinding())
            {
  -            init.addFactoryValueBinding(factoryDescriptor.getName(), factoryDescriptor.getValue(), factoryDescriptor.getScope());
  +            init.addFactoryValueBinding(factoryDescriptor.getName(), factoryDescriptor.getValue(),
  +                     factoryDescriptor.getScope());
            }
            else
            {
  -            init.addFactoryMethodBinding(factoryDescriptor.getName(), factoryDescriptor.getMethod(), factoryDescriptor.getScope());
  +            init.addFactoryMethodBinding(factoryDescriptor.getName(),
  +                     factoryDescriptor.getMethod(), factoryDescriptor.getScope());
            }
  -         if ( factoryDescriptor.isAutoCreate() )
  +         if (factoryDescriptor.isAutoCreate())
            {
               init.addAutocreateVariable(factoryDescriptor.getName());
            }
         }
      }
   
  -   protected boolean dependenciesMet(Context context, String[] dependencies) {
  -       if (dependencies == null) {
  -           return true;
  -       }
  +   protected boolean dependenciesMet(Context context, ComponentDescriptor descriptor)
  +   {
  +      if ( !descriptor.isInstalled() ) return false;
   
  -       for (String dependency: dependencies) {
  -           if (!context.isSet(dependency + COMPONENT_SUFFIX)) {
  +      String[] dependencies = descriptor.getDependencies();
  +      if (dependencies!=null)
  +      {
  +         for (String dependency: dependencies)
  +         {
  +            if ( !context.isSet(dependency + COMPONENT_SUFFIX) )
  +            {
                  return false;
              }
          }
  -
  +      }
  +      Class[] genericDependencies = descriptor.getGenericDependencies();
  +      if (genericDependencies!=null)
  +      {
  +         for (Class genericDependency: genericDependencies)
  +         {
  +            if ( !installedComponents.contains(genericDependency) )
  +            {
  +               return false;
  +            }
  +         }
  +      }
          return true;
      }
   
       /** 
  -     * This actually creates a propert component and should only be called
  -     * when we want to install a component
  +    * This actually creates a propert component and should only be called when
  +    * we want to install a component
        */
      protected void addComponent(ComponentDescriptor descriptor, Context context)
      {
         String name = descriptor.getName();
         String componentName = name + COMPONENT_SUFFIX;
   
  -      if ( log.isWarnEnabled() && context.isSet(componentName) )
  +      if (log.isWarnEnabled() && context.isSet(componentName))
         {
            log.warn("Component has been previously installed and is being redefined: " + name);
         }
   
  -      Component component = new Component(
  -            descriptor.getComponentClass(),
  -            name,
  -            descriptor.getScope(),
  -            descriptor.getJndiName()
  -         );
  +      Component component = new Component(descriptor.getComponentClass(), name, descriptor
  +               .getScope(), descriptor.getJndiName());
         context.set(componentName, component);
      }
   
  @@ -748,7 +722,8 @@
         private String value;
         private boolean autoCreate;
   
  -      public FactoryDescriptor(String name, ScopeType scope, String method, String value, boolean autoCreate)
  +      public FactoryDescriptor(String name, ScopeType scope, String method, String value,
  +               boolean autoCreate)
         {
            super();
            this.name = name;
  @@ -780,7 +755,7 @@
   
         public boolean isValueBinding()
         {
  -         return method==null;
  +         return method == null;
         }
         
         public boolean isAutoCreate()
  @@ -795,18 +770,24 @@
         }
      }
   
  -    private static class NamespaceInfo {
  +   private static class NamespaceInfo
  +   {
           private Namespace namespace;
           private Package pkg;
   
  -        public NamespaceInfo(Namespace namespace, Package pkg) {
  +      public NamespaceInfo(Namespace namespace, Package pkg)
  +      {
               this.namespace = namespace;
               this.pkg = pkg;
           }
  -        public Namespace getNamespace() {
  +
  +      public Namespace getNamespace()
  +      {
               return namespace;
           }
  -        public Package getPackage() {
  +
  +      public Package getPackage()
  +      {
               return pkg;
           }
   
  @@ -821,12 +802,8 @@
         private Boolean installed;
         private boolean autoCreate;
   
  -      public ComponentDescriptor(String name, 
  -                                 Class<?> componentClass, 
  -                                 ScopeType scope, 
  -                                 boolean autoCreate,
  -                                 String jndiName, 
  -                                 Boolean installed)
  +      public ComponentDescriptor(String name, Class<?> componentClass, ScopeType scope,
  +               boolean autoCreate, String jndiName, Boolean installed)
         {
            this.name = name;
            this.componentClass = componentClass;
  @@ -835,10 +812,12 @@
            this.installed = installed;
            this.autoCreate = autoCreate;
         }
  +
         public ComponentDescriptor(Class componentClass)
         {
            this.componentClass = componentClass;
         }
  +
         public ComponentDescriptor(Class componentClass, Boolean installed)
         {
             this.componentClass = componentClass;
  @@ -848,39 +827,58 @@
   
         public String getName()
         {
  -         return name==null ? Seam.getComponentName(componentClass) : name;
  +         return name == null ? Seam.getComponentName(componentClass) : name;
         }
  +
         public ScopeType getScope()
         {
  -         return scope==null ? Seam.getComponentScope(componentClass) : scope;
  +         return scope == null ? Seam.getComponentScope(componentClass) : scope;
         }
  +
         public Class getComponentClass()
         {
            return componentClass;
         }       
  +
         public String getJndiName() 
         {
            return jndiName;
         }
  +
         public boolean isAutoCreate()
         {
            return autoCreate;
         }
   
  -      public String[] getDependencies() {
  -          Install anno = componentClass.getAnnotation(Install.class);
  -          if (anno == null) {
  +      public String[] getDependencies()
  +      {
  +         Install install = componentClass.getAnnotation(Install.class);
  +         if (install == null)
  +         {
  +            return null;
  +         }
  +         return install.dependencies();
  +      }
  +
  +      public Class[] getGenericDependencies()
  +      {
  +         Install install = componentClass.getAnnotation(Install.class);
  +         if (install == null)
  +         {
                 return null;
             }
  -          return anno.depends();
  +         return install.genericDependencies();
         }
   
  -      public boolean isInstalled() {
  -          if (installed != null) {
  +      public boolean isInstalled()
  +      {
  +         if (installed != null)
  +         {
                 return installed;
             }
             Install anno = componentClass.getAnnotation(Install.class);
  -          if (anno == null) {
  +         if (anno == null)
  +         {
                 return true;
             }
             return anno.value();
  
  
  



More information about the jboss-cvs-commits mailing list