Skip navigation.
Downloads | Product Documentation | Support

Beehive Integration in WebLogic Server 9.1

# Code Samples for Annotation Overrides

This appendix contains the complete code for the files used or referred to in Annotation Overrides.

# MyControl.java

>     package controls;

>     import java.lang.annotation.Retention;
>     import java.lang.annotation.RetentionPolicy;
>     import org.apache.beehive.controls.api.bean.AnnotationMemberTypes;
>     import org.apache.beehive.controls.api.bean.ControlInterface;

>     import org.apache.beehive.controls.api.bean.AnnotationMemberTypes.Date;
>     import org.apache.beehive.controls.api.bean.AnnotationMemberTypes.Decimal;
>     import org.apache.beehive.controls.api.bean.AnnotationMemberTypes.Optional;

>     import org.apache.beehive.controls.api.properties.PropertySet;
>     import weblogic.controls.annotations.RequiresEncryption;

>     @ControlInterface
>     public interface MyControl
>     {
>       public String getAnnotationValue();
>     }

# MyControlImp.java

>     package controls;

>     import java.lang.reflect.Method;
>     import java.io.Serializable;
>     import org.apache.beehive.controls.api.bean.ControlImplementation;

>     import org.apache.beehive.controls.api.bean.Extensible;
>     import org.apache.beehive.controls.api.bean.ControlBean;
>     import org.apache.beehive.controls.api.context.Context;
>     import org.apache.beehive.controls.api.context.ControlBeanContext;

>     @ControlImplementation
>     public class MyControlImpl implements MyControl, Extensible, Serializable
>     {
>         @Context
>         ControlBeanContext ctx;

>         public String getAnnotationValue() {

>             // This is a key part. The control framework will make sure
>             // that the precendence is followed when look up annotation
>             // values for MyAnnotation
>             MyAnnotation myAnnotation =
>                 ctx.getControlPropertySet(MyAnnotation.class);

>             return myAnnotation.value();
>         }

>         public Object invoke(Method method, Object[] args) throws Throwable
>         {
>             // Control Extension not defined for simplicity
>             return null;
>         }
>     }

# MyAnnotation.java

>     package controls;

>     import java.lang.annotation.Inherited;
>     import java.lang.annotation.Retention;
>     import java.lang.annotation.RetentionPolicy;
>     import org.apache.beehive.controls.api.properties.PropertySet;
>     import org.apache.beehive.controls.api.bean.AnnotationConstraints.AllowExternalOverride;

>     @PropertySet(externalConfig=true)
>     @AllowExternalOverride
>     @Retention(RetentionPolicy.RUNTIME)
>     public @interface MyAnnotation
>     {
>         String value() default "DEFAULT";
>     }

# MyJcx.java

>     package controls;

>     import org.apache.beehive.controls.api.bean.ControlExtension;

>     @ControlExtension
>     @MyAnnotation("OnClassDecl")
>     public interface MyJcx extends MyControl
>     {
>     }

# HelloService.java

>     /**
>      * This class demonstrates the use of an override-able annotation
>      * on a control instance. The field "_jcxBean" was declared with
>      * MyAnnotation, which has an initial value of "Overriden@Field".
>      * During runtime, the sayHello() method will actually return a
>      * value that has been externally overriden via a deployment plan.
>      *
>      * There is no code change required for this class in order to
>      * obtain a new externally-configured value.
>      */
>     package service;

>     import javax.jws.WebService;
>     import javax.jws.WebMethod;
>     import javax.jws.soap.SOAPBinding;

>     import weblogic.jws.WLHttpTransport;
>     import org.apache.beehive.controls.api.bean.Control;
>     import controls.*;

>     @WebService(name="Hello")
>     @SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.ENCODED)
>     @WLHttpTransport(contextPath="helloJWS", serviceUri="HelloService")
>     public class HelloService
>     {
>         @Control()
>         @MyAnnotation("Overriden@Field")
>         protected MyJcxBean _jcxBean;

>         @WebMethod
>         public String sayHello()
>         {
>             return _jcxBean.getAnnotationValue();
>         }
>     }