[weld-commits] Weld SVN: r6386 - in extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties: query and 1 other directory.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Wed Jun 2 18:32:25 EDT 2010


Author: pete.muir at jboss.org
Date: 2010-06-02 18:32:24 -0400 (Wed, 02 Jun 2010)
New Revision: 6386

Added:
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldPropertyImpl.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodPropertyImpl.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java
Removed:
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/AnnotatedPropertyCriteria.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyCriteria.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyQuery.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/NamedPropertyCriteria.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/TypedPropertyCriteria.java
Modified:
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Properties.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java
Log:
extract interfaces for MethodProperty, FieldProperty

Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/AnnotatedPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/AnnotatedPropertyCriteria.java	2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/AnnotatedPropertyCriteria.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,31 +0,0 @@
-package org.jboss.weld.extensions.util.properties;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-/**
- * A criteria that matches a property based on its annotations
- * 
- * @author Shane Bryzak
- */
-public class AnnotatedPropertyCriteria implements BeanPropertyCriteria
-{
-   private Class<? extends Annotation> annotationClass;
-   
-   public AnnotatedPropertyCriteria(Class<? extends Annotation> annotationClass)
-   {
-      this.annotationClass = annotationClass;
-   }
-   
-   public boolean fieldMatches(Field f)
-   {
-      return f.isAnnotationPresent(annotationClass);
-   }
-
-   public boolean methodMatches(Method m)
-   {
-      return m.isAnnotationPresent(annotationClass);
-   }
-
-}

Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyCriteria.java	2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyCriteria.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,28 +0,0 @@
-package org.jboss.weld.extensions.util.properties;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-/**
- * Base interface for criteria used to locate bean properties
- * 
- * @author Shane Bryzak
- */
-public interface BeanPropertyCriteria
-{
-   /**
-    * Tests whether the specified field matches the criteria
-    * 
-    * @param f
-    * @return true if the field matches
-    */
-   boolean fieldMatches(Field f);
-   
-   /**
-    * Tests whether the specified method matches the criteria
-    * 
-    * @param m
-    * @return true if the method matches
-    */
-   boolean methodMatches(Method m);
-}

Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyQuery.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyQuery.java	2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyQuery.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,65 +0,0 @@
-package org.jboss.weld.extensions.util.properties;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Queries a target class for properties that match certain criteria
- * 
- * @author Shane Bryzak
- */
-public class BeanPropertyQuery
-{
-   private Class<?> targetClass;
-   private List<BeanPropertyCriteria> criteria = new ArrayList<BeanPropertyCriteria>();
-   
-   public BeanPropertyQuery(Class<?> targetClass)
-   {
-      this.targetClass = targetClass;
-   }
-   
-   public BeanPropertyQuery addCriteria(BeanPropertyCriteria criteria)
-   {
-      this.criteria.add(criteria);
-      return this;
-   }
-   
-   public List<Property<?>> getResultList()
-   {
-      List<Property<?>> results = new ArrayList<Property<?>>();
-
-      Class<?> cls = targetClass;
-      while (!cls.equals(Object.class))
-      {
-         // First check declared fields
-         for (Field field : cls.getDeclaredFields())
-         {
-            for (BeanPropertyCriteria c : criteria)
-            {                     
-               if (c.fieldMatches(field))
-               {
-                  results.add(Properties.createProperty(field));
-               }
-            }
-         }
-         
-         cls = cls.getSuperclass();
-      }
-
-      // Then check public methods (we ignore private methods)
-      for (Method method : targetClass.getMethods())
-      {
-         for (BeanPropertyCriteria c : criteria)
-         {
-            if (c.methodMatches(method))
-            {
-               results.add(Properties.createProperty(method));
-            }
-         }
-      }      
-      
-      return results;
-   }
-}

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java	2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,95 +1,11 @@
-/**
- * 
- */
 package org.jboss.weld.extensions.util.properties;
 
-import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Field;
-import java.lang.reflect.Type;
 
-/**
- * A bean property based on the value contained in a field
- * 
- * @author Pete Muir
- * @author Shane Bryzak
- *
- */
-class FieldProperty<V> implements Property<V>
+
+public interface FieldProperty<V> extends Property<V>
 {
-   private static String buildGetFieldValueErrorMessage(Field field, Object obj)
-   {
-      return String.format("Exception reading [%s] field from object [%s].", field.getName(), obj);
-   }
-   
-   private static String buildSetFieldValueErrorMessage(Field field, Object obj, Object value)
-   {
-      return String.format("Exception setting [%s] field on object [%s] to value [%s]", field.getName(), obj, value);
-   }
-   
-   private final Field field;
 
-   FieldProperty(Field field)
-   {
-      this.field = field;
-   }
-   
-   public String getName()
-   {
-      return field.getName();
-   }
-   
-   public Type getBaseType()
-   {
-      return field.getGenericType();
-   }
-   
-   public AnnotatedElement getAnnotatedElement()
-   {
-      return field;
-   }
-   
-   @SuppressWarnings("unchecked")
-   public Class<V> getJavaClass()
-   {
-      return (Class<V>) field.getType();
-   }
-   
-   public V getValue(Object instance)
-   {
-      field.setAccessible(true);
-      try
-      {
-         return getJavaClass().cast(field.get(instance));
-      }
-      catch (IllegalAccessException e)
-      {
-         throw new RuntimeException(buildGetFieldValueErrorMessage(field, instance), e);
-      }
-      catch (NullPointerException ex)
-      {
-         NullPointerException ex2 = new NullPointerException(buildGetFieldValueErrorMessage(field, instance));
-         ex2.initCause(ex.getCause());
-         throw ex2;
-      }
-   }
-   
-   public void setValue(Object instance, V value) 
-   {
-      field.setAccessible(true);
-      try
-      {
-         field.set(instance, value);
-      }
-      catch (IllegalAccessException e)
-      {
-         throw new RuntimeException(buildSetFieldValueErrorMessage(field, instance, value), e);
-      }
-      catch (NullPointerException ex)
-      {
-         NullPointerException ex2 = new NullPointerException(buildSetFieldValueErrorMessage(field, instance, value));
-         ex2.initCause(ex.getCause());
-         throw ex2;
-      }
-   }
-   
+   public Field getAnnotatedElement();
+
 }
\ No newline at end of file

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldPropertyImpl.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldPropertyImpl.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldPropertyImpl.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,94 @@
+/**
+ * 
+ */
+package org.jboss.weld.extensions.util.properties;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Type;
+
+/**
+ * A bean property based on the value contained in a field
+ * 
+ * @author Pete Muir
+ * @author Shane Bryzak
+ * 
+ */
+class FieldPropertyImpl<V> implements FieldProperty<V>
+{
+   private static String buildGetFieldValueErrorMessage(Field field, Object obj)
+   {
+      return String.format("Exception reading [%s] field from object [%s].", field.getName(), obj);
+   }
+
+   private static String buildSetFieldValueErrorMessage(Field field, Object obj, Object value)
+   {
+      return String.format("Exception setting [%s] field on object [%s] to value [%s]", field.getName(), obj, value);
+   }
+
+   private final Field field;
+
+   FieldPropertyImpl(Field field)
+   {
+      this.field = field;
+   }
+
+   public String getName()
+   {
+      return field.getName();
+   }
+
+   public Type getBaseType()
+   {
+      return field.getGenericType();
+   }
+
+   public Field getAnnotatedElement()
+   {
+      return field;
+   }
+
+   @SuppressWarnings("unchecked")
+   public Class<V> getJavaClass()
+   {
+      return (Class<V>) field.getType();
+   }
+
+   public V getValue(Object instance)
+   {
+      field.setAccessible(true);
+      try
+      {
+         return getJavaClass().cast(field.get(instance));
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(buildGetFieldValueErrorMessage(field, instance), e);
+      }
+      catch (NullPointerException ex)
+      {
+         NullPointerException ex2 = new NullPointerException(buildGetFieldValueErrorMessage(field, instance));
+         ex2.initCause(ex.getCause());
+         throw ex2;
+      }
+   }
+
+   public void setValue(Object instance, V value)
+   {
+      field.setAccessible(true);
+      try
+      {
+         field.set(instance, value);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RuntimeException(buildSetFieldValueErrorMessage(field, instance, value), e);
+      }
+      catch (NullPointerException ex)
+      {
+         NullPointerException ex2 = new NullPointerException(buildSetFieldValueErrorMessage(field, instance, value));
+         ex2.initCause(ex.getCause());
+         throw ex2;
+      }
+   }
+
+}
\ No newline at end of file

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java	2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,152 +1,11 @@
 package org.jboss.weld.extensions.util.properties;
 
-import java.beans.Introspector;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.lang.reflect.Type;
 
-/**
- * A bean property based on the value represented by a getter/setter method pair
- * 
- * @author Pete Muir
- * @author Shane Bryzak
- */
-class MethodProperty<V> implements Property<V>
-{   
-   private final Method getterMethod;
-   private final String propertyName;
-   private final Method setterMethod;
 
-   public MethodProperty(Method method)
-   {
-      if (method.getName().startsWith("get"))
-      {
-         this.propertyName = Introspector.decapitalize(method.getName().substring(3));
-      }
-      else if (method.getName().startsWith("is"))
-      {
-         this.propertyName = Introspector.decapitalize(method.getName().substring(2));
-      }
-      else
-      {
-         throw new IllegalArgumentException("Invalid accessor method, must start with 'get' or 'is'.  " + "Method: " + method);
-      }
-      this.getterMethod = getGetterMethod(method.getDeclaringClass(), propertyName);
-      this.setterMethod = getSetterMethod(method.getDeclaringClass(), propertyName);      
-   }
-   
-   public String getName()
-   {
-      return propertyName;
-   }
-   
-   @SuppressWarnings("unchecked")
-   public Class<V> getJavaClass()
-   {
-      return (Class<V>) getterMethod.getReturnType();
-   }
-   
-   public Type getBaseType()
-   {
-      return getterMethod.getGenericReturnType();
-   }
-   
-   public AnnotatedElement getAnnotatedElement()
-   {
-      return getterMethod;
-   }
-   
-   public V getValue(Object instance)
-   {
-      return getJavaClass().cast(invokeMethod(getterMethod, instance));
-   }
-   
-   public void setValue(Object instance, Object value) 
-   {
-      invokeMethod(setterMethod, instance, value);
-   }
-   
-   private static String buildInvokeMethodErrorMessage(Method method, Object obj, Object... args)
-   {
-      StringBuilder message = new StringBuilder(String.format("Exception invoking method [%s] on object [%s], using arguments [", method.getName(), obj));
-      if (args != null)
-         for (int i = 0; i < args.length; i++)
-            message.append((i > 0 ? "," : "") + args[i]);
-      message.append("]");
-      return message.toString();
-   }
-   
-   private static Object invokeMethod(Method method, Object obj, Object... args)
-   {
-      try
-      {
-         return method.invoke(obj, args);
-      }
-      catch (IllegalAccessException ex)
-      {
-         throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
-      }
-      catch (IllegalArgumentException ex)
-      {
-         throw new IllegalArgumentException(buildInvokeMethodErrorMessage(method, obj, args), ex.getCause());
-      }
-      catch (InvocationTargetException ex)
-      {
-         throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
-      }
-      catch (NullPointerException ex)
-      {
-         NullPointerException ex2 = new NullPointerException(buildInvokeMethodErrorMessage(method, obj, args));
-         ex2.initCause(ex.getCause());
-         throw ex2;
-      }
-      catch (ExceptionInInitializerError e)
-      {
-         throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), e);
-      }
-   }
-   
-   private static Method getSetterMethod(Class<?> clazz, String name)
-   {
-      Method[] methods = clazz.getMethods();
-      for (Method method : methods)
-      {
-         String methodName = method.getName();
-         if (methodName.startsWith("set") && method.getParameterTypes().length == 1)
-         {
-            if (Introspector.decapitalize(methodName.substring(3)).equals(name))
-            {
-               return method;
-            }
-         }
-      }
-      throw new IllegalArgumentException("no such setter method: " + clazz.getName() + '.' + name);
-   }
+public interface MethodProperty<V> extends Property<V>
+{
 
-   private static Method getGetterMethod(Class<?> clazz, String name)
-   {
-      for (Method method : clazz.getDeclaredMethods())
-      {
-         String methodName = method.getName();
-         if (method.getParameterTypes().length == 0)
-         {
-            if (methodName.startsWith("get"))
-            {
-               if (Introspector.decapitalize(methodName.substring(3)).equals(name))
-               {
-                  return method;
-               }
-            }
-            else if (methodName.startsWith("is"))
-            {
-               if (Introspector.decapitalize(methodName.substring(2)).equals(name))
-               {
-                  return method;
-               }
-            }
-         }
-      }
-      throw new IllegalArgumentException("no such getter method: " + clazz.getName() + '.' + name);
-   }   
+   public Method getAnnotatedElement();
+
 }
\ No newline at end of file

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodPropertyImpl.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodPropertyImpl.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodPropertyImpl.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,154 @@
+/**
+ * 
+ */
+package org.jboss.weld.extensions.util.properties;
+
+import java.beans.Introspector;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+
+/**
+ * A bean property based on the value represented by a getter/setter method pair
+ * 
+ * @author Pete Muir
+ * @author Shane Bryzak
+ */
+class MethodPropertyImpl<V> implements MethodProperty<V>
+{   
+   private final Method getterMethod;
+   private final String propertyName;
+   private final Method setterMethod;
+
+   public MethodPropertyImpl(Method method)
+   {
+      if (method.getName().startsWith("get"))
+      {
+         this.propertyName = Introspector.decapitalize(method.getName().substring(3));
+      }
+      else if (method.getName().startsWith("is"))
+      {
+         this.propertyName = Introspector.decapitalize(method.getName().substring(2));
+      }
+      else
+      {
+         throw new IllegalArgumentException("Invalid accessor method, must start with 'get' or 'is'.  " + "Method: " + method);
+      }
+      this.getterMethod = getGetterMethod(method.getDeclaringClass(), propertyName);
+      this.setterMethod = getSetterMethod(method.getDeclaringClass(), propertyName);      
+   }
+   
+   public String getName()
+   {
+      return propertyName;
+   }
+   
+   @SuppressWarnings("unchecked")
+   public Class<V> getJavaClass()
+   {
+      return (Class<V>) getterMethod.getReturnType();
+   }
+   
+   public Type getBaseType()
+   {
+      return getterMethod.getGenericReturnType();
+   }
+   
+   public Method getAnnotatedElement()
+   {
+      return getterMethod;
+   }
+   
+   public V getValue(Object instance)
+   {
+      return getJavaClass().cast(invokeMethod(getterMethod, instance));
+   }
+   
+   public void setValue(Object instance, Object value) 
+   {
+      invokeMethod(setterMethod, instance, value);
+   }
+   
+   private static String buildInvokeMethodErrorMessage(Method method, Object obj, Object... args)
+   {
+      StringBuilder message = new StringBuilder(String.format("Exception invoking method [%s] on object [%s], using arguments [", method.getName(), obj));
+      if (args != null)
+         for (int i = 0; i < args.length; i++)
+            message.append((i > 0 ? "," : "") + args[i]);
+      message.append("]");
+      return message.toString();
+   }
+   
+   private static Object invokeMethod(Method method, Object obj, Object... args)
+   {
+      try
+      {
+         return method.invoke(obj, args);
+      }
+      catch (IllegalAccessException ex)
+      {
+         throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
+      }
+      catch (IllegalArgumentException ex)
+      {
+         throw new IllegalArgumentException(buildInvokeMethodErrorMessage(method, obj, args), ex.getCause());
+      }
+      catch (InvocationTargetException ex)
+      {
+         throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), ex);
+      }
+      catch (NullPointerException ex)
+      {
+         NullPointerException ex2 = new NullPointerException(buildInvokeMethodErrorMessage(method, obj, args));
+         ex2.initCause(ex.getCause());
+         throw ex2;
+      }
+      catch (ExceptionInInitializerError e)
+      {
+         throw new RuntimeException(buildInvokeMethodErrorMessage(method, obj, args), e);
+      }
+   }
+   
+   private static Method getSetterMethod(Class<?> clazz, String name)
+   {
+      Method[] methods = clazz.getMethods();
+      for (Method method : methods)
+      {
+         String methodName = method.getName();
+         if (methodName.startsWith("set") && method.getParameterTypes().length == 1)
+         {
+            if (Introspector.decapitalize(methodName.substring(3)).equals(name))
+            {
+               return method;
+            }
+         }
+      }
+      throw new IllegalArgumentException("no such setter method: " + clazz.getName() + '.' + name);
+   }
+
+   private static Method getGetterMethod(Class<?> clazz, String name)
+   {
+      for (Method method : clazz.getDeclaredMethods())
+      {
+         String methodName = method.getName();
+         if (method.getParameterTypes().length == 0)
+         {
+            if (methodName.startsWith("get"))
+            {
+               if (Introspector.decapitalize(methodName.substring(3)).equals(name))
+               {
+                  return method;
+               }
+            }
+            else if (methodName.startsWith("is"))
+            {
+               if (Introspector.decapitalize(methodName.substring(2)).equals(name))
+               {
+                  return method;
+               }
+            }
+         }
+      }
+      throw new IllegalArgumentException("no such getter method: " + clazz.getName() + '.' + name);
+   }   
+}
\ No newline at end of file

Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/NamedPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/NamedPropertyCriteria.java	2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/NamedPropertyCriteria.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,31 +0,0 @@
-package org.jboss.weld.extensions.util.properties;
-
-import java.beans.Introspector;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-/**
- * A criteria that matches a property based on name
- * 
- * @author Shane Bryzak
- */
-public class NamedPropertyCriteria implements BeanPropertyCriteria
-{
-   private String propertyName;
-   
-   public NamedPropertyCriteria(String propertyName)
-   {
-      this.propertyName = propertyName;
-   }
-   
-   public boolean fieldMatches(Field f)
-   {
-      return propertyName.equals(f.getName());
-   }
-
-   public boolean methodMatches(Method m)
-   {
-      return m.getName().startsWith("get") && 
-         Introspector.decapitalize(m.getName().substring(3)).equals(propertyName);
-   }
-}

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Properties.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Properties.java	2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Properties.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -21,9 +21,9 @@
     * @param field
     * @return
     */
-   public static <V> Property<V> createProperty(Field field)
+   public static <V> FieldProperty<V> createProperty(Field field)
    {
-      return new FieldProperty<V>(field);
+      return new FieldPropertyImpl<V>(field);
    }
    
    /**
@@ -34,8 +34,8 @@
     * @return
     * @throws IllegalArgumentException if the method does not match JavaBean conventions
     */
-   public static <V> Property<V> createProperty(Method method)
+   public static <V> MethodProperty<V> createProperty(Method method)
    {
-      return new MethodProperty<V>(method);
+      return new MethodPropertyImpl<V>(method);
    }
 }

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java	2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -24,32 +24,37 @@
     * 
     * @return The name of the property
     */
-   String getName();
+   public String getName();
    
    /**
     * Returns the property type
     * 
     * @return The property type
     */
-   Type getBaseType();
+   public Type getBaseType();
    
    /**
     * Returns the property type
     * 
     * @return The property type
     */
-   Class<V> getJavaClass();   
-      
-   AnnotatedElement getAnnotatedElement();
+   public Class<V> getJavaClass();   
    
    /**
+    * Get the element backing the property
+    * 
+    * @return
+    */
+   public AnnotatedElement getAnnotatedElement();
+   
+   /**
     * Returns the property value for the specified bean. The property to be
     * returned is either a field or getter method.
     * 
     * @param bean The bean to read the property from
     * @return The property value
     */
-    V getValue(Object instance);
+   public V getValue(Object instance);
    
    /**
     * This method sets the property value for a specified bean to the specified
@@ -58,5 +63,5 @@
     * @param bean The bean containing the property to set
     * @param value The new property value
     */
-   void setValue(Object instance, V value);   
+   public void setValue(Object instance, V value);   
 }
\ No newline at end of file

Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/TypedPropertyCriteria.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/TypedPropertyCriteria.java	2010-06-02 22:23:35 UTC (rev 6385)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/TypedPropertyCriteria.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -1,29 +0,0 @@
-package org.jboss.weld.extensions.util.properties;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-/**
- * A criteria that matches a property based on its type
- * 
- * @author Shane Bryzak
- */
-public class TypedPropertyCriteria implements BeanPropertyCriteria
-{
-   private Class<?> propertyClass;
-   
-   public TypedPropertyCriteria(Class<?> propertyClass)
-   {
-      this.propertyClass = propertyClass;
-   }
-
-   public boolean fieldMatches(Field f)
-   {
-      return propertyClass.equals(f.getType());
-   }
-
-   public boolean methodMatches(Method m)
-   {
-      return propertyClass.equals(m.getReturnType());
-   }
-}

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/AnnotatedPropertyCriteria.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/AnnotatedPropertyCriteria.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,31 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * A criteria that matches a property based on its annotations
+ * 
+ * @author Shane Bryzak
+ */
+public class AnnotatedPropertyCriteria implements BeanPropertyCriteria
+{
+   private Class<? extends Annotation> annotationClass;
+   
+   public AnnotatedPropertyCriteria(Class<? extends Annotation> annotationClass)
+   {
+      this.annotationClass = annotationClass;
+   }
+   
+   public boolean fieldMatches(Field f)
+   {
+      return f.isAnnotationPresent(annotationClass);
+   }
+
+   public boolean methodMatches(Method m)
+   {
+      return m.isAnnotationPresent(annotationClass);
+   }
+
+}

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyCriteria.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyCriteria.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,28 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * Base interface for criteria used to locate bean properties
+ * 
+ * @author Shane Bryzak
+ */
+public interface BeanPropertyCriteria
+{
+   /**
+    * Tests whether the specified field matches the criteria
+    * 
+    * @param f
+    * @return true if the field matches
+    */
+   boolean fieldMatches(Field f);
+   
+   /**
+    * Tests whether the specified method matches the criteria
+    * 
+    * @param m
+    * @return true if the method matches
+    */
+   boolean methodMatches(Method m);
+}

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/BeanPropertyQuery.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/BeanPropertyQuery.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,68 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.weld.extensions.util.properties.Properties;
+import org.jboss.weld.extensions.util.properties.Property;
+
+/**
+ * Queries a target class for properties that match certain criteria
+ * 
+ * @author Shane Bryzak
+ */
+public class BeanPropertyQuery
+{
+   private Class<?> targetClass;
+   private List<BeanPropertyCriteria> criteria = new ArrayList<BeanPropertyCriteria>();
+   
+   public BeanPropertyQuery(Class<?> targetClass)
+   {
+      this.targetClass = targetClass;
+   }
+   
+   public BeanPropertyQuery addCriteria(BeanPropertyCriteria criteria)
+   {
+      this.criteria.add(criteria);
+      return this;
+   }
+   
+   public List<Property<?>> getResultList()
+   {
+      List<Property<?>> results = new ArrayList<Property<?>>();
+
+      Class<?> cls = targetClass;
+      while (!cls.equals(Object.class))
+      {
+         // First check declared fields
+         for (Field field : cls.getDeclaredFields())
+         {
+            for (BeanPropertyCriteria c : criteria)
+            {                     
+               if (c.fieldMatches(field))
+               {
+                  results.add(Properties.createProperty(field));
+               }
+            }
+         }
+         
+         cls = cls.getSuperclass();
+      }
+
+      // Then check public methods (we ignore private methods)
+      for (Method method : targetClass.getMethods())
+      {
+         for (BeanPropertyCriteria c : criteria)
+         {
+            if (c.methodMatches(method))
+            {
+               results.add(Properties.createProperty(method));
+            }
+         }
+      }      
+      
+      return results;
+   }
+}

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/NamedPropertyCriteria.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/NamedPropertyCriteria.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,31 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.beans.Introspector;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * A criteria that matches a property based on name
+ * 
+ * @author Shane Bryzak
+ */
+public class NamedPropertyCriteria implements BeanPropertyCriteria
+{
+   private String propertyName;
+   
+   public NamedPropertyCriteria(String propertyName)
+   {
+      this.propertyName = propertyName;
+   }
+   
+   public boolean fieldMatches(Field f)
+   {
+      return propertyName.equals(f.getName());
+   }
+
+   public boolean methodMatches(Method m)
+   {
+      return m.getName().startsWith("get") && 
+         Introspector.decapitalize(m.getName().substring(3)).equals(propertyName);
+   }
+}

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java (from rev 6384, extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/TypedPropertyCriteria.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/query/TypedPropertyCriteria.java	2010-06-02 22:32:24 UTC (rev 6386)
@@ -0,0 +1,29 @@
+package org.jboss.weld.extensions.util.properties.query;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * A criteria that matches a property based on its type
+ * 
+ * @author Shane Bryzak
+ */
+public class TypedPropertyCriteria implements BeanPropertyCriteria
+{
+   private Class<?> propertyClass;
+   
+   public TypedPropertyCriteria(Class<?> propertyClass)
+   {
+      this.propertyClass = propertyClass;
+   }
+
+   public boolean fieldMatches(Field f)
+   {
+      return propertyClass.equals(f.getType());
+   }
+
+   public boolean methodMatches(Method m)
+   {
+      return propertyClass.equals(m.getReturnType());
+   }
+}



More information about the weld-commits mailing list