[seam-commits] Seam SVN: r14299 - branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/util.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri Feb 3 07:20:09 EST 2012
Author: manaRH
Date: 2012-02-03 07:20:08 -0500 (Fri, 03 Feb 2012)
New Revision: 14299
Modified:
branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/util/AnnotatedBeanProperty.java
Log:
JBPAPP-6924 backed port one-off patch
Modified: branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/util/AnnotatedBeanProperty.java
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/util/AnnotatedBeanProperty.java 2012-02-03 12:03:48 UTC (rev 14298)
+++ branches/enterprise/JBPAPP_5_0/src/main/org/jboss/seam/util/AnnotatedBeanProperty.java 2012-02-03 12:20:08 UTC (rev 14299)
@@ -15,10 +15,10 @@
*/
public class AnnotatedBeanProperty<T extends Annotation> implements Serializable
{
- private static final long serialVersionUID = 12345678456L;
- private Field propertyField;
- private Method propertyGetter;
- private Method propertySetter;
+ private static final long serialVersionUID = 2508430507136805635L;
+ private transient Field propertyField;
+ private transient Method propertyGetter;
+ private transient Method propertySetter;
private String name;
private Type propertyType;
private T annotation;
@@ -26,40 +26,50 @@
private boolean isFieldProperty;
private boolean set = false;
- public AnnotatedBeanProperty(Class<?> cls, Class<T> annotationClass)
+ private Class<?> cls;
+ private Class<? extends Annotation> annotationClass;
+
+ public AnnotatedBeanProperty(Class<?> cls, Class<? extends Annotation> annotationClass)
{
- // First check declared fields
- for (Field f : cls.getDeclaredFields())
- {
- if (f.isAnnotationPresent(annotationClass))
+ this.cls = cls;
+ this.annotationClass = annotationClass;
+ init();
+ }
+
+ private void init()
+ {
+ // First check declared fields
+ for (Field f : cls.getDeclaredFields())
{
- setupFieldProperty(f);
- this.annotation = f.getAnnotation(annotationClass);
- set = true;
- return;
- }
+ if (f.isAnnotationPresent(annotationClass))
+ {
+ setupFieldProperty(f);
+ this.annotation = (T) f.getAnnotation(annotationClass);
+ set = true;
+ return;
+ }
}
-
+
// Then check public fields, in case it's inherited
for (Field f : cls.getFields())
{
if (f.isAnnotationPresent(annotationClass))
{
- this.annotation = f.getAnnotation(annotationClass);
+ this.annotation = (T) f.getAnnotation(annotationClass);
setupFieldProperty(f);
set = true;
return;
}
}
-
+
// Then check public methods (we ignore private methods)
for (Method m : cls.getMethods())
{
if (m.isAnnotationPresent(annotationClass))
{
- this.annotation = m.getAnnotation(annotationClass);
+ this.annotation = (T) m.getAnnotation(annotationClass);
String methodName = m.getName();
-
+
if ( m.getName().startsWith("get") )
{
this.name = Introspector.decapitalize( m.getName().substring(3) );
@@ -68,7 +78,7 @@
{
this.name = Introspector.decapitalize( m.getName().substring(2) );
}
-
+
if (this.name != null)
{
this.propertyGetter = Reflections.getGetterMethod(cls, this.name);
@@ -83,29 +93,35 @@
"Method: " + m + " in class: " + cls);
}
}
- }
+ }
}
- public Field getPropertyField()
- {
- if (propertyField == null)
- init();
- return propertyField;
- }
+ public Field getPropertyField()
+ {
+ if (propertyField == null)
+ {
+ init();
+ }
+ return propertyField;
+ }
- public Method getPropertyGetter()
- {
- if (propertyGetter == null)
- init();
- return propertyGetter;
- }
+ public Method getPropertyGetter()
+ {
+ if (propertyGetter == null)
+ {
+ init();
+ }
+ return propertyGetter;
+ }
- public Method getPropertySetter()
- {
- if (propertySetter == null)
- init();
- return propertySetter;
- }
+ public Method getPropertySetter()
+ {
+ if (propertySetter == null)
+ {
+ init();
+ }
+ return propertySetter;
+ }
private void setupFieldProperty(Field propertyField)
{
@@ -146,7 +162,7 @@
public T getAnnotation()
{
- return annotation;
+ return (T) annotation;
}
public Type getPropertyType()
More information about the seam-commits
mailing list