abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r575452 - in /incubator/abdera/java/trunk/extensions/converters/src: main/java/org/apache/abdera/converter/ main/java/org/apache/abdera/converter/annotation/ test/java/org/apache/abdera/test/converter/
Date Thu, 13 Sep 2007 21:08:29 GMT
Author: jmsnell
Date: Thu Sep 13 14:08:28 2007
New Revision: 575452

URL: http://svn.apache.org/viewvc?rev=575452&view=rev
Log:
More work on the annotation converter

Removed:
    incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Direction.java
Modified:
    incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/BaseConverter.java
    incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/ConventionConversionContext.java
    incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/DefaultConventions.java
    incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Entry.java
    incubator/abdera/java/trunk/extensions/converters/src/test/java/org/apache/abdera/test/converter/ConverterTest.java

Modified: incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/BaseConverter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/BaseConverter.java?rev=575452&r1=575451&r2=575452&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/BaseConverter.java
(original)
+++ incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/BaseConverter.java
Thu Sep 13 14:08:28 2007
@@ -74,6 +74,20 @@
     T dest,
     AccessibleObject accessor) {}
   
+  private Document getDocument(T obj) {
+    if (obj == null) return null;
+    Document doc = null;
+    if (obj instanceof Document) {
+      doc = (Document) obj;
+    } else if (obj instanceof Element) {
+      Element element = (Element) obj;
+      Document parent = element.getDocument();
+      Element root = parent.getRoot();
+      if (root.equals(element)) doc = parent;
+    }
+    return doc;
+  }
+  
   @Override 
   public T convert(
     Object source, 
@@ -122,54 +136,57 @@
             if (dest instanceof Document) ((Document)dest).setBaseUri(iri);
             else if (dest instanceof Element) ((Element)dest).setBaseUri(iri);
           }
-        } else if (dest instanceof Document && 
-          accessor.isAnnotationPresent(Slug.class) || 
+        } else if (accessor.isAnnotationPresent(Slug.class) || 
           Slug.class.equals(conventions.matchConvention(accessor))) {
             Object value = eval(accessor,source);
             ObjectContext valueContext = new ObjectContext(value,source,accessor);
             StringConverter c = new StringConverter();
             StringBuffer buf = c.convert(value, valueContext, context);
-            if (buf != null) ((Document)dest).setSlug(buf.toString());
-        } else if (dest instanceof Document && 
-            accessor.isAnnotationPresent(LastModified.class) || 
+            Document doc = getDocument(dest);
+            if (doc != null && buf != null) doc.setSlug(buf.toString());
+        } else if (accessor.isAnnotationPresent(LastModified.class) || 
             LastModified.class.equals(conventions.matchConvention(accessor))) {
           Object value = eval(accessor,source);
-          Document doc = (Document)dest;
-          if (value instanceof Date) {
-            doc.setLastModified((Date)value);
-          } else if (value instanceof Calendar) {
-            Calendar cal = (Calendar)value;
-            doc.setLastModified(cal.getTime());
-          } else if (value instanceof Long) {
-            Long l = (Long) value;
-            doc.setLastModified(new Date(l.longValue()));
-          } else if (value instanceof String) {
-            doc.setLastModified(AtomDate.parse((String)value));
-          } else {
-            StringConverter s = new StringConverter();
-            StringBuffer v = s.convert(source, objectContext, context);
-            if (v != null) doc.setLastModified(AtomDate.parse(v.toString()));
+          Document doc = getDocument(dest);
+          if (doc != null) {
+            if (value instanceof Date) {
+              doc.setLastModified((Date)value);
+            } else if (value instanceof Calendar) {
+              Calendar cal = (Calendar)value;
+              doc.setLastModified(cal.getTime());
+            } else if (value instanceof Long) {
+              Long l = (Long) value;
+              doc.setLastModified(new Date(l.longValue()));
+            } else if (value instanceof String) {
+              doc.setLastModified(AtomDate.parse((String)value));
+            } else {
+              StringConverter s = new StringConverter();
+              StringBuffer v = s.convert(source, objectContext, context);
+              if (v != null) doc.setLastModified(AtomDate.parse(v.toString()));
+            }
           }
-        } else if (dest instanceof Document && 
-            accessor.isAnnotationPresent(Charset.class) || 
+        } else if (accessor.isAnnotationPresent(Charset.class) || 
             Charset.class.equals(conventions.matchConvention(accessor))) {
           Object value = eval(accessor,source);
           ObjectContext valueContext = new ObjectContext(value,source,accessor);
           StringConverter c = new StringConverter();
           StringBuffer buf = c.convert(value, valueContext, context);
-          if (buf != null) ((Document)dest).setCharset(buf.toString());
-        } else if (dest instanceof Document && 
-            accessor.isAnnotationPresent(EntityTag.class) || 
+          Document doc = getDocument(dest);
+          if (doc != null && buf != null) doc.setCharset(buf.toString());
+        } else if (accessor.isAnnotationPresent(EntityTag.class) || 
             EntityTag.class.equals(conventions.matchConvention(accessor))) {
-              Object value = eval(accessor,source);
-              if (value instanceof org.apache.abdera.util.EntityTag) {
-                ((Document)dest).setEntityTag((org.apache.abdera.util.EntityTag)value);
-              } else {
-                ObjectContext valueContext = new ObjectContext(value,source,accessor);
-                StringConverter c = new StringConverter();
-                StringBuffer buf = c.convert(value, valueContext, context);
-                if (buf != null) ((Document)dest).setEntityTag(buf.toString());
-              }
+          Document doc = getDocument(dest);
+          if (doc != null) {
+            Object value = eval(accessor,source);
+            if (value instanceof org.apache.abdera.util.EntityTag) {
+              doc.setEntityTag((org.apache.abdera.util.EntityTag)value);
+            } else {
+              ObjectContext valueContext = new ObjectContext(value,source,accessor);
+              StringConverter c = new StringConverter();
+              StringBuffer buf = c.convert(value, valueContext, context);
+              if (buf != null) doc.setEntityTag(buf.toString());
+            }
+          }
         } else {
           process(source, objectContext, context, conventions, dest, accessor);
         }

Modified: incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/ConventionConversionContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/ConventionConversionContext.java?rev=575452&r1=575451&r2=575452&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/ConventionConversionContext.java
(original)
+++ incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/ConventionConversionContext.java
Thu Sep 13 14:08:28 2007
@@ -22,6 +22,7 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.converter.annotation.Feed;
+import org.apache.abdera.converter.annotation.Entry;
 
 public class ConventionConversionContext 
   extends DefaultConversionContext {
@@ -86,6 +87,5 @@
   }
   
   @SuppressWarnings("unchecked") private static final Class[] annotations = 
-  {Feed.class, 
-  };
+  {Feed.class, Entry.class};
 }

Modified: incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/DefaultConventions.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/DefaultConventions.java?rev=575452&r1=575451&r2=575452&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/DefaultConventions.java
(original)
+++ incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/DefaultConventions.java
Thu Sep 13 14:08:28 2007
@@ -30,7 +30,6 @@
 import org.apache.abdera.converter.annotation.ContentType;
 import org.apache.abdera.converter.annotation.Contributor;
 import org.apache.abdera.converter.annotation.Control;
-import org.apache.abdera.converter.annotation.Direction;
 import org.apache.abdera.converter.annotation.Draft;
 import org.apache.abdera.converter.annotation.Edited;
 import org.apache.abdera.converter.annotation.Email;
@@ -83,7 +82,6 @@
     ContentType.class, 
     Contributor.class, 
     Control.class, 
-    Direction.class, 
     Draft.class, 
     Edited.class, 
     Email.class, 

Modified: incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Entry.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Entry.java?rev=575452&r1=575451&r2=575452&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Entry.java
(original)
+++ incubator/abdera/java/trunk/extensions/converters/src/main/java/org/apache/abdera/converter/annotation/Entry.java
Thu Sep 13 14:08:28 2007
@@ -17,15 +17,18 @@
 */
 package org.apache.abdera.converter.annotation;
 
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.METHOD;
 import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
 import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
+import org.apache.abdera.converter.impl.EntryConverter;
+
 @Retention(RUNTIME)
 @Target({TYPE,METHOD,FIELD})
 @Convention(".*entry|.*entries")
+@Converter(EntryConverter.class)
 public @interface Entry {}

Modified: incubator/abdera/java/trunk/extensions/converters/src/test/java/org/apache/abdera/test/converter/ConverterTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/converters/src/test/java/org/apache/abdera/test/converter/ConverterTest.java?rev=575452&r1=575451&r2=575452&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/converters/src/test/java/org/apache/abdera/test/converter/ConverterTest.java
(original)
+++ incubator/abdera/java/trunk/extensions/converters/src/test/java/org/apache/abdera/test/converter/ConverterTest.java
Thu Sep 13 14:08:28 2007
@@ -29,12 +29,14 @@
 import org.apache.abdera.converter.ConventionConversionContext;
 import org.apache.abdera.converter.ConversionContext;
 import org.apache.abdera.converter.annotation.Category;
+import org.apache.abdera.converter.annotation.Entry;
 import org.apache.abdera.converter.annotation.Feed;
 import org.apache.abdera.converter.annotation.Generator;
 import org.apache.abdera.converter.annotation.Link;
 import org.apache.abdera.converter.annotation.Rel;
 import org.apache.abdera.converter.annotation.Scheme;
 import org.apache.abdera.converter.annotation.TextType;
+import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Text;
 
 public class ConverterTest extends TestCase {
@@ -46,10 +48,16 @@
     
     FooFeed fooFeed = new FooFeed();
     
-    Object object = context.convert(fooFeed);
+    org.apache.abdera.model.Feed feed = context.convert(fooFeed);
     
-    System.out.println(object);
+    System.out.println(feed);
     
+    Document<org.apache.abdera.model.Feed> doc = feed.getDocument();
+    System.out.println(doc.getSlug());
+    
+    FooEntry fooEntry = new FooEntry();
+    org.apache.abdera.model.Entry entry = context.convert(fooEntry);
+    System.out.println(entry);
   }
   
   @Feed
@@ -66,8 +74,12 @@
     @Generator(version="1.0",uri="http://example.org") public String generator = "Bob";
     
     public FooEntry[] entries = new FooEntry[] { new FooEntry() };
+    
+    public String slug = "slug";
+    public Date lastmodified = new Date();
   }
   
+  @Entry
   public static class FooEntry {
     public String id = "http://example.org/1/1";
     @TextType(Text.Type.XHTML) public String title = "The title";



Mime
View raw message