abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r575443 - in /incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter: AbstractConversionContext.java ConversionContext.java ObjectContext.java annotation/Converter.java
Date Thu, 13 Sep 2007 20:42:51 GMT
Author: jmsnell
Date: Thu Sep 13 13:42:51 2007
New Revision: 575443

URL: http://svn.apache.org/viewvc?rev=575443&view=rev
Log:
Updates needed for the annotation converter impl

Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/AbstractConversionContext.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/ConversionContext.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/ObjectContext.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/annotation/Converter.java

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/AbstractConversionContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/AbstractConversionContext.java?rev=575443&r1=575442&r2=575443&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/AbstractConversionContext.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/AbstractConversionContext.java
Thu Sep 13 13:42:51 2007
@@ -19,6 +19,8 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -94,6 +96,15 @@
     }
     return false;
   }
+  
+  public boolean hasConverter(AccessibleObject accessor) {
+    Class<? extends Object> returnType = getReturnType(accessor);
+    org.apache.abdera.converter.annotation.Converter converter = 
+      accessor.getAnnotation(org.apache.abdera.converter.annotation.Converter.class);
+    if (converter != null && hasConverter(converter.value())) return true;
+    if (returnType != null && hasConverter(returnType)) return true;
+    return false;
+  }
 
   public void setConverter(Class<?> type, Converter<?> converter) {
     converters.put(type, converter);
@@ -145,4 +156,14 @@
   protected Object copy() {
     return new RuntimeException(new CloneNotSupportedException());
   }
+  
+  public static Class<? extends Object> getReturnType(
+    AccessibleObject accessor) {
+      if (accessor instanceof Field)
+        return ((Field)accessor).getType();
+      else if (accessor instanceof Method) 
+        return ((Method)accessor).getReturnType();
+      else return null;
+  }
+
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/ConversionContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/ConversionContext.java?rev=575443&r1=575442&r2=575443&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/ConversionContext.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/ConversionContext.java
Thu Sep 13 13:42:51 2007
@@ -78,5 +78,10 @@
    */
   boolean hasConverter(Class<?> type);
   
+  /**
+   * True if a converter for the specified accessor is available
+   */
+  boolean hasConverter(AccessibleObject accessor);
+  
   Object clone();
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/ObjectContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/ObjectContext.java?rev=575443&r1=575442&r2=575443&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/ObjectContext.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/ObjectContext.java
Thu Sep 13 13:42:51 2007
@@ -46,7 +46,12 @@
     Object object, 
     Object parent, 
     AccessibleObject accessor) {
-      this.objectType = object != null ? object.getClass() : null;
+      this.objectType = 
+        object != null ? 
+          object.getClass() : 
+        accessor != null ? 
+          AbstractConversionContext.getReturnType(accessor) : 
+          null;
       this.parent = parent;
       this.accessor = accessor;
       this.annotations = initAnnotations();

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/annotation/Converter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/annotation/Converter.java?rev=575443&r1=575442&r2=575443&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/annotation/Converter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/converter/annotation/Converter.java
Thu Sep 13 13:42:51 2007
@@ -21,12 +21,13 @@
 import static java.lang.annotation.ElementType.METHOD;
 import static java.lang.annotation.ElementType.FIELD;
 import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
 @Retention(RUNTIME)
-@Target({TYPE,METHOD,FIELD})
+@Target({TYPE,METHOD,FIELD,ANNOTATION_TYPE})
 public @interface Converter {
   Class<? extends org.apache.abdera.converter.Converter<?>> value();
 }



Mime
View raw message