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

Gavin King gavin.king at jboss.com
Sun Nov 19 14:44:27 EST 2006


  User: gavin   
  Date: 06/11/19 14:44:27

  Modified:    src/main/org/jboss/seam/init  Initialization.java
  Log:
  hyphenated element names
  
  Revision  Changes    Path
  1.122     +26 -20    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.121
  retrieving revision 1.122
  diff -u -b -r1.121 -r1.122
  --- Initialization.java	19 Nov 2006 18:14:30 -0000	1.121
  +++ Initialization.java	19 Nov 2006 19:44:27 -0000	1.122
  @@ -16,6 +16,7 @@
   import java.util.Map;
   import java.util.Properties;
   import java.util.Set;
  +import java.util.StringTokenizer;
   
   import javax.servlet.ServletContext;
   
  @@ -50,11 +51,12 @@
   import org.jboss.seam.util.Naming;
   import org.jboss.seam.util.Reflections;
   import org.jboss.seam.util.Resources;
  +import org.jboss.seam.util.Strings;
   
   /**
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.121 $
  + * @version $Revision: 1.122 $
    */
   public class Initialization
   {
  @@ -171,8 +173,6 @@
            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())
         {
            String ns = elem.getNamespace().getURI();
  @@ -180,21 +180,18 @@
            if (nsInfo != null)
            {
               String name = elem.attributeValue("name");
  -
  -            String className = nsInfo.getPackage().getName() + "." + elem.getName();
  +            String elemName = toCamelCase( elem.getName() );
  +            String className = nsInfo.getPackage().getName() + '.' + elemName;
               try
               {
                  Class<Object> clazz = Reflections.classForName(className);
                  if (name == null)
                  {
  -                  Name anno = clazz.getAnnotation(Name.class);
  -                  if (anno != null)
  -                  {
  -                     name = anno.value();
  +                  Name nameAnnotation = clazz.getAnnotation(Name.class);
  +                  if (nameAnnotation!=null) name = nameAnnotation.value();
                     }
                  }
  -            }
  -            catch (ClassNotFoundException e)
  +            catch (ClassNotFoundException cnfe)
               {
                  // if it isn't a classname, set
                  className = null;
  @@ -203,14 +200,8 @@
               if (name == null)
               {
                  String prefix = nsInfo.getNamespace().prefix();
  -               if ((prefix == null) || (prefix.length() == 0))
  -               {
  -                  name = elem.getName();
  -               }
  -               else
  -               {
  -                  name = prefix + "." + elem.getName();
  -               }
  +               name = Strings.isEmpty(prefix) ? 
  +                     elemName : prefix + '.' + elemName;
               }
   
               installComponentFromXmlElement(elem, name, className, replacements);
  @@ -317,7 +308,7 @@
            {
               propName = prop.getQName().getName();
            }
  -         String qualifiedPropName = name + '.' + propName;
  +         String qualifiedPropName = name + '.' + toCamelCase(propName);
            properties.put(qualifiedPropName, getPropertyValue(prop, qualifiedPropName, replacements));
         }
      }
  @@ -446,6 +437,7 @@
               }
               else
               {
  +               //TODO: namespaced components!!!
                  installComponentFromXmlElement(doc.getRootElement(), doc.getRootElement()
                           .attributeValue("name"), clazz.getName(), replacements);
               }
  @@ -710,6 +702,20 @@
         context.set(componentName, component);
      }
   
  +   private static String toCamelCase(String hyphenated)
  +   {
  +      StringTokenizer tokens = new StringTokenizer(hyphenated, "-");
  +      StringBuilder result = new StringBuilder( hyphenated.length() )
  +            .append( tokens.nextToken() );
  +      while ( tokens.hasMoreTokens() )
  +      {
  +         String token = tokens.nextToken();
  +         result.append( Character.toUpperCase( token.charAt(0) ) )
  +               .append( token.substring(1) );
  +      }
  +      return result.toString();
  +   }
  +
      private static class FactoryDescriptor
      {
         private String name;
  
  
  



More information about the jboss-cvs-commits mailing list