[jboss-cvs] aop-mc-int/src/main/org/jboss/aop/microcontainer/integration ...

Kabir Khan kkhan at jboss.com
Wed Jul 19 14:22:16 EDT 2006


  User: kkhan   
  Date: 06/07/19 14:22:16

  Modified:    src/main/org/jboss/aop/microcontainer/integration 
                        AOPMetaDataContext.java
  Log:
  [JBMICROCONT-98] Make the annotation metadata more free format
  
  Revision  Changes    Path
  1.6       +15 -86    aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPMetaDataContext.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AOPMetaDataContext.java
  ===================================================================
  RCS file: /cvsroot/jboss/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPMetaDataContext.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- AOPMetaDataContext.java	13 Jul 2006 21:29:33 -0000	1.5
  +++ AOPMetaDataContext.java	19 Jul 2006 18:22:16 -0000	1.6
  @@ -21,6 +21,7 @@
   */ 
   package org.jboss.aop.microcontainer.integration;
   
  +import java.lang.annotation.Annotation;
   import java.lang.reflect.Method;
   import java.util.ArrayList;
   import java.util.HashMap;
  @@ -31,12 +32,11 @@
   
   import org.jboss.aop.Advised;
   import org.jboss.aop.Advisor;
  -import org.jboss.aop.annotation.AnnotationCreator;
   import org.jboss.aop.proxy.container.AspectManaged;
   import org.jboss.beans.info.spi.PropertyInfo;
  -import org.jboss.beans.metadata.spi.AnnotationAttributeMetaData;
   import org.jboss.beans.metadata.spi.AnnotationMetaData;
   import org.jboss.reflect.spi.MethodInfo;
  +
   import org.jboss.repository.spi.BasicMetaData;
   import org.jboss.repository.spi.CommonNames;
   import org.jboss.repository.spi.KernelRepository;
  @@ -48,7 +48,7 @@
   /**
    * 
    * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public class AOPMetaDataContext implements MetaDataContext
   {
  @@ -192,7 +192,7 @@
         for (Iterator i = annotations.iterator(); i.hasNext();)
         {
            AnnotationMetaData annotation = (AnnotationMetaData) i.next();
  -         Key key = new Key(annotation.getName(), scope);            
  +         Key key = new Key(getName(annotation), scope);            
            
            final MetaData metadata = createMetaData(annotation);
            repository.addMetaData(key, metadata);
  @@ -219,12 +219,12 @@
                     MetaData data = createMetaData(annotation);
                     if (getter != null)
                     {
  -                     Key key = createMethodKey(annotation.getName(), getter.getName());
  +                     Key key = createMethodKey(getName(annotation), getter.getName());
                        repository.addMetaData(key, data);
                     }
                     if (setter != null)
                     {
  -                     Key key = createMethodKey(annotation.getName(), setter.getName());
  +                     Key key = createMethodKey(getName(annotation), setter.getName());
                        repository.addMetaData(key, data);
                     }
                  }
  @@ -240,93 +240,23 @@
      
      private MetaData createMetaData(AnnotationMetaData metadata)
      {
  -      String iface = metadata.getName();
  -      
  -      final Object annotation = createAnnotationProxy(iface, metadata);
  -      return new BasicMetaData(0, annotation);
  -   }
  -   
  -   private Object createAnnotationProxy(String iface, AnnotationMetaData metadata)
  -   {
  -      try
  -      {
  -         ClassLoader loader = Thread.currentThread().getContextClassLoader();
  -         Class ifaceClass = loader.loadClass(iface);
  -         String annString = createAnnotationString(ifaceClass, metadata);
  -         return AnnotationCreator.createAnnotation(annString, ifaceClass);
  -      }
  -      catch (Exception e)
  -      {
  -         // AutoGenerated
  -         throw new RuntimeException(e);
  -      }
  -   }
  -   
  -   //FIXME JBAOP-275 use annotation metadata directly to create the annotations
  -   private String createAnnotationString(Class iface, AnnotationMetaData metadata)
  -   {
  -      String name = metadata.getName().trim();
  -      JBossStringBuilder ann = new JBossStringBuilder();
  -      
  -      if (name.charAt(0) != '@')
  -      {
  -         ann.append("@");
  +      return new BasicMetaData(0, metadata.getAnnotationInstance());
         }
            
  -      ann.append(name);
  -      ann.append(" (");
  -      
  -      Set attributes = metadata.getAttributes();
  -      if (attributes != null && attributes.size() > 0)
  -      {
  -         boolean first = true;
  -         for (Iterator i = attributes.iterator(); i.hasNext();)
  -         {
  -            AnnotationAttributeMetaData attribute = (AnnotationAttributeMetaData) i.next();
               
  -            if (first)
  -            {
  -               first = false;
  -            }
  -            else
  +   private String getName(Annotation annotation)
               {
  -               ann.append(", ");
  +      return annotation.annotationType().getName();
               }
               
  -            boolean isString = isString(iface, attribute);
  -            ann.append(attribute.getName());
  -            ann.append("=");
  -            
  -            if (isString)
  +   private String getName(MetaData metadata)
               {
  -               ann.append("\"");
  -            }
  -            ann.append(attribute.getValue());
  -            if (isString)
  -            {
  -               ann.append("\"");
  -            }
  -         }
  +      return getName((Annotation)metadata.getData());
         }
         
  -      ann.append(")");
  -      return ann.toString();
  -   }
  -   
  -   private boolean isString(Class iface, AnnotationAttributeMetaData attribute)
  -   {
  -      try
  -      {
  -         String name = attribute.getName();
  -         Method method = iface.getDeclaredMethod(name, EMPTY_CLASS_ARRAY);
  -         Class ret = method.getReturnType();
  -         return ret.equals(String.class);
  -      }
  -      catch (Exception e)
  +   private String getName(AnnotationMetaData annotation)
         {
  -         throw new RuntimeException(e);
  -      }
  -      
  +      return getName(annotation.getAnnotationInstance());
      }
     
      public void setTarget(Object tgt)
  @@ -360,5 +290,4 @@
            }
         }
      }
  -
   }   
  
  
  



More information about the jboss-cvs-commits mailing list