1 Reply Latest reply on May 10, 2011 9:22 AM by tfennelly

    Adding a @Transform annotation

    kcbabo

      Take the following transformer implementation which already extends BaseTransformer so that it contains less boilerplate code:

       

      public class OrderTransform extends BaseTransformer<Order, OtherOrder> {
      
          public OrderTransform() {
              super(new QName("java:org.foo.Order"),        // from
                    new QName("java:org.bar.OtherOrder"));  // to
          }
      
          @Override
          public OtherOrder transform(Order from) {
              // ... doesn't matter
          }
      

       

      Wouldn't it be nicer if it looked like this?  We can derive the same configuration based on the declared types for the method.

       

      public class OrderTransform {
      
          @Transform
          public OtherOrder transform(Order from) {
              // ... doesn't matter
          }
      

       

      The prior example was a bit of a cheat because it's just going between java type names.  Let's go with an XML -> Java example:

       

      public class OrderTransform {
      
          @Transform(to="{urn:examples:feedback:1.0}submitFeedback")
          public Element transform(Order from) {
              // ... doesn't matter
          }
      

       

      I think the following rules would apply for this annotation:

      • A transformer class can have one more annotated methods.  It would probably be easiest to create a BaseTransfomer for each annotated method that would delegate to the appropriate method. This should keep the registry search logic simple and consistent.
      • A method annotated with @Transform must have a single parameter and a return type.
      • If the @Transform annotation has no elements, then the java type names are used for the from and to names.
      • A 'from' and/or 'to' value can be supplied in the annotation to override/specify the from and to names.  These values follow the QName string syntax.

       

      Thoughts?  As usual, Tom was way ahead of me and had a prototype that was close (maybe identical) to what I described above some time ago.  Good news is that it should only take him 15 minutes to resolve the JIRA now. :-)