abdera-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dan Diephouse" <...@envoisolutions.com>
Subject Re: Annotations
Date Tue, 07 Aug 2007 22:18:00 GMT
Very cool James.

One suggestion: conventions! I.e. the default ID should be getId(). The
default Author is getAuthor(). etc etc.

Along these lines I was wondering if it was possible to leverage existing
annotations from JAXB & JPA for those who have using those technologies. We
could automatically create workspaces/collections/entries based on the JPA
relationships. Then we could use JAXB to do the serialization. Not sure yet
if thats a stupid idea... Thoughts?

- Dan

On 8/6/07, James M Snell <jasnell@gmail.com> wrote:
>
> Ok, so I have a basic preliminary implementation of an annotation-driven
> Java-to-Atom converter.
>
> Here's how it works:
>
> Let's suppose that I have a java class.
>
>   class Foo {}
>
> I want to serialize this as an Atom Entry document
>
>   @AtomEntry class Foo {}
>
> I want to specify that the xml:lang for the feed is "en-US"
>
>   @AtomEntry @Lang("en-US") class Foo {}
>
> Now I want to add an atom:id, atom:title, atom:updated and atom:author
> to the entry
>
>   @AtomEntry @Lang("en-US") class Foo {
>
>     @AtomID String getId() { ... }
>
>     @AtomTitle ( Text.Type.TEXT ) String getTitle() { ... }
>
>     @AtomUpdated Date getUpdated() { ... }
>
>     @AtomAuthor FooPerson getAuthor() { ... }
>
>   }
>
> I want to have FooPerson automatically converted into an atom:author
> object, so I need to annotate it also.
>
>   @AtomPerson @AtomAuthor class FooPerson {
>
>     @Value String getName() { ... }
>
>     @Email String getEmail() { ... }
>
>   }
>
> Now I want to add a list of categories to Foo:
>
>   @AtomEntry @Lang("en-US") class Foo {
>
>     @AtomID String getId() { ... }
>
>     @AtomTitle ( Text.Type.TEXT ) String getTitle() { ... }
>
>     @AtomAuthor FooPerson getAuthor() { ... }
>
>     @List(AtomCategory.class) List<FooTag> getCategories() { ... }
>   }
>
> Each FooTag needs to be annotated
>
>   @AtomCategory (scheme="http://example.org/foo" ) class FooTag { ... }
>
> Now I want to add XHTML content to the entry and a single simple
> extension.
>
>   @AtomEntry @Lang("en-US") class Foo {
>
>     @AtomID String getId() { ... }
>
>     @AtomTitle ( Text.Type.TEXT ) String getTitle() { ... }
>
>     @AtomAuthor FooPerson getAuthor() { ... }
>
>     @List(AtomCategory.class) List<FooTag> getCategories() { ... }
>
>     @AtomContent ( Content.Type.XHTML ) String getContent() { ... }
>
>     @Extension (uri="http://example.org/foo",
>                 localname="foo", prefix="b") String getFoo() { ... }
>   }
>
> Now that I've annotated my classes, I can create an instance and convert
> those to Atom...
>
>     ConversionContext context = new ConversionContext();
>     DefaultConverter conv = new DefaultConverter();
>     Foo foo = new Foo();
>     // set foo properties
>     Entry entry = conv.convert(test,context);
>     System.out.println(entry);
>
> Now, suppose I want to have more control over how some object is
> converted.  I can use a CustomConverter annotation, either on the method
> or the class, e.g.,
>
>     @AtomAuthor @CustomConverter(MyConverter.class)
>     FooPerson getAuthor();
>
> Now, FooPerson will be passed to MyConverter rather than the
> DefaultConverter.
>
> The implementation is functional but is far from complete.  I'm also not
> happy with how complicated the internal implementation details are.  It
> seems way more complex that it really should be.  However, it does work
> reasonably well.
>
> I can drop this into the contrib module if folks want to play around
> with it, or I can just upload a zip to my personal site for folks to
> play around with.
>
> - James
>



-- 
Dan Diephouse
Envoi Solutions
http://envoisolutions.com | http://netzooid.com/blog

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message