You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by "David Blevins (JIRA)" <ji...@apache.org> on 2013/11/24 22:53:37 UTC

[jira] [Resolved] (TOMEE-1040) Abstract Dynamic Beans

     [ https://issues.apache.org/jira/browse/TOMEE-1040?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

David Blevins resolved TOMEE-1040.
----------------------------------

    Resolution: Fixed

> Abstract Dynamic Beans
> ----------------------
>
>                 Key: TOMEE-1040
>                 URL: https://issues.apache.org/jira/browse/TOMEE-1040
>             Project: TomEE
>          Issue Type: New Feature
>            Reporter: David Blevins
>             Fix For: 1.6.0
>
>
> If the bean class is abstract and implements java.lang.reflect.InvocationHandler, then the abstract methods will delegate to the bean's java.lang.reflect.InvocationHandler.invoke(..) method.
> This allows for sort of a hybrid approach where some methods can be abstract and handled in a reflection-like manner, while others can be implemented regularly.
> An interesting difference is the code takes extreme care to implement all the constructors of the parent class as well as the annotations of the parent class and any method annotations and method param annotations of abstract methods.
> This should allow the dynamically created class to replace the parent class in every way, including usage in annotation heavy APIs like JAX-RS, JAX-WS or CDI.  I tested JAX-RS and it seems to work perfectly.
> For example see this RESTful service:
> {code}
>    @Stateless
>    @Path("/ejb")
>    public abstract class RESTIsVeryCool implements InvocationHandler {
>        @EJB
>        private SimpleEJB simpleEJB;
>        @javax.ws.rs.core.Context
>        Request request;
>        @Path("/normal")
>        @GET
>        public abstract String normal();
>        @Path("/rest")
>        @GET
>        public abstract String rest();
>        @Path("/param")
>        @GET
>        public String param(@QueryParam("arg") @DefaultValue("true") String p) {
>            return p;
>        }
>        @Path("/field")
>        @GET
>        public boolean field() {
>            return "GET".equals(request.getMethod());
>        }
>        @Override
>        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
>            return simpleEJB.ok();
>        }
>    }
> {code}



--
This message was sent by Atlassian JIRA
(v6.1#6144)