Author: shane.bryzak(a)jboss.com
Date: 2010-06-02 18:18:50 -0400 (Wed, 02 Jun 2010)
New Revision: 6382
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Properties.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/Property.java
Log:
rollback a few changes
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
21:44:18 UTC (rev 6381)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/FieldProperty.java 2010-06-02
22:18:50 UTC (rev 6382)
@@ -14,7 +14,7 @@
* @author Shane Bryzak
*
*/
-class FieldProperty implements Property
+class FieldProperty<V> implements Property<V>
{
private static String buildGetFieldValueErrorMessage(Field field, Object obj)
{
@@ -28,7 +28,7 @@
private final Field field;
- public FieldProperty(Field field)
+ FieldProperty(Field field)
{
this.field = field;
}
@@ -48,17 +48,18 @@
return field.getAnnotation(annotationClass);
}
- public Class<?> getPropertyClass()
+ @SuppressWarnings("unchecked")
+ public Class<V> getJavaClass()
{
- return (Class<?>) field.getType();
+ return (Class<V>) field.getType();
}
- public Object getValue(Object instance)
+ public V getValue(Object instance)
{
field.setAccessible(true);
try
{
- return getPropertyClass().cast(field.get(instance));
+ return getJavaClass().cast(field.get(instance));
}
catch (IllegalAccessException e)
{
@@ -72,7 +73,7 @@
}
}
- public void setValue(Object instance, Object value)
+ public void setValue(Object instance, V value)
{
field.setAccessible(true);
try
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
21:44:18 UTC (rev 6381)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/MethodProperty.java 2010-06-02
22:18:50 UTC (rev 6382)
@@ -15,7 +15,7 @@
* @author Pete Muir
* @author Shane Bryzak
*/
-class MethodProperty implements Property
+class MethodProperty<V> implements Property<V>
{
private final Method getterMethod;
private final String propertyName;
@@ -44,9 +44,10 @@
return propertyName;
}
- public Class<?> getPropertyClass()
+ @SuppressWarnings("unchecked")
+ public Class<V> getJavaClass()
{
- return getterMethod.getReturnType();
+ return (Class<V>) getterMethod.getReturnType();
}
public Type getBaseType()
@@ -59,9 +60,9 @@
return getterMethod.getAnnotation(annotationClass);
}
- public Object getValue(Object instance)
+ public V getValue(Object instance)
{
- return getPropertyClass().cast(invokeMethod(getterMethod, instance));
+ return getJavaClass().cast(invokeMethod(getterMethod, instance));
}
public void setValue(Object instance, Object value)
Added:
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
(rev 0)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Properties.java 2010-06-02
22:18:50 UTC (rev 6382)
@@ -0,0 +1,41 @@
+package org.jboss.weld.extensions.util.properties;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * Utility class for working with JavaBean style properties
+ *
+ * @author pmuir
+ *
+ */
+public class Properties
+{
+
+ private Properties() {}
+
+ /**
+ * Create a JavaBean style property from the field
+ *
+ * @param <V>
+ * @param field
+ * @return
+ */
+ public static <V> Property<V> createProperty(Field field)
+ {
+ return new FieldProperty<V>(field);
+ }
+
+ /**
+ * Create a JavaBean style property from the specified method
+ *
+ * @param <V>
+ * @param method
+ * @return
+ * @throws IllegalArgumentException if the method does not match JavaBean conventions
+ */
+ public static <V> Property<V> createProperty(Method method)
+ {
+ return new MethodProperty<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
21:44:18 UTC (rev 6381)
+++
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/properties/Property.java 2010-06-02
22:18:50 UTC (rev 6382)
@@ -13,7 +13,7 @@
*
* @param <V>
*/
-public interface Property
+public interface Property<V>
{
/**
@@ -38,7 +38,7 @@
*
* @return The property type
*/
- Class<?> getPropertyClass();
+ Class<V> getJavaClass();
/**
* Returns the specified annotation, if it exists on the bean property
@@ -56,7 +56,7 @@
* @param bean The bean to read the property from
* @return The property value
*/
- Object getValue(Object instance);
+ V getValue(Object instance);
/**
* This method sets the property value for a specified bean to the specified
@@ -65,5 +65,5 @@
* @param bean The bean containing the property to set
* @param value The new property value
*/
- void setValue(Object instance, Object value);
+ void setValue(Object instance, V value);
}
\ No newline at end of file
Show replies by date