dev@jax-ws.java.net

Proposal for WebServiceFeature Extension

From: Rama Pulavarthi <Rama.Pulavarthi_at_Sun.COM>
Date: Thu, 19 Oct 2006 16:37:33 -0700

Spec defines two feature annotaions @Addressing and @MTOM. The feature
extensions are growing daily (@MemberSubmissionAddressing, @Stateful,
@OptimalEncoding....) How to deal with these growing annotations?

Currently, There is no easy way get a WebServiceFeature instance from a
feature annotation. The WebServiceFeatureAnnotation.bean() gives only
the associated class.
So, I propose all feature extensions to extend
com.sun.xml.ws.api.WebServiceFeatureEx. With this we can get an
WebServiceFeature Object easily.
This is extensible and we don't have deal with feature annotation
extensions in the future. RI already has provided extension points for
WSDL Generation, WSDL Parsing, Runtime through Pipes/Tubes.

If @Foo(param1="xyz",param2=true) is present on an impl class,
RI will get an instance of FooFeature from
@Foo(param1="xyz",param2=true) and sets it on WSBinding. Corresponding
FooTube or FooWSDLExtensions will handle this feature at runtime/wsdl
generation.
---------------
package com.sun.xml.ws.api;
import javax.xml.ws.WebServiceFeature;
import java.lang.annotation.Annotation;

public abstract class WebServiceFeatureEx extends WebServiceFeature {
   public abstract WebServiceFeatureEx getFeatureObject(Annotation ann);
}
---------------
package com.sun.xml.ws;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@WebServiceFeatureAnnotation(id=FooFeature.ID,bean=FooFeature.class)
public @interface Foo {
   /**
    * Specifies param2 option
    */
   boolean param2() default true;

   /**
    * Specifies param1 option
    */
   String param1() default "";
}
-----------------
import java.lang.annotation.Annotation;

public class FooFeature extends WebServiceFeatureEx {
   public static final String ID = "foo";
   boolean param2 = false;
   String param1= null;

   public FooFeature(String param1, boolean param2){
       this.param1 = param1;
       this.param2 = param2;
   }

   public WebServiceFeatureEx getFeatureObject(Annotation ann) {
       if(!(ann instanceof Foo))
           return null;// or throw Exception
       Foo foo = (Foo)ann;
       // Each feature knows how to deal with its annotation
       return new FooFeature(foo.param1(),foo.param2());
   }

   public String getParam1() {
       return param1;
   }
   public boolean getParam2() {
       return param2;
   }
   public String getID() {
       return ID;
   }
----------------------------

thanks,
Rama Pulavarthi