users@jersey.java.net

Re: Injection of message body readers/writers now supported in latest builds

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 28 Jan 2008 15:03:30 +0100

Paul Sandoz wrote:
> After that: support a JAXB context resolver, one or more of which may be
> implemented by the application, and an aggregation can be injected onto
> a reader/writer or resource class. This will enable the application to
> declare JAXB contexts.
>

Done, in latest build. See the StorageService example for more details.
This example has the following class:

   @Provider
   public final class JAXBContextResolver implements
       ContextResolver<JAXBContext> {

     private final JAXBContext context;

     private final Set<Class> types;

     private final Class[] cTypes = {Containers.class, Container.class,
                 Item.class};

     public JAXBContextResolver() throws Exception {
         this.types = new HashSet(Arrays.asList(cTypes));
         this.context = JAXBContext.newInstance(cTypes);
     }

     public JAXBContext getContext(Class<?> objectType) {
         return (types.contains(objectType)) ? context : null;
     }
   }

Which is picked up automatically, instantiated and then injected onto
the JAXB message body readers/writers. If there are no JAXB context
resolvers present, or there is no match for the type, the JAXB message
body readers/writers will defer to the same behavior as before and
create a context from the type. If there is more than one JAXB context
resolver present then they will be aggregated (order is not determined)
by the runtime.

The principle is generic so it is possible to declare any type of
context resolver and inject it.


It is now possible to inject the:

   com.sun.ws.rest.spi.container.MessageBodyContext

on a root resource or message body readers/writers. This can enable
modular reuse, for example for high-level form-based reading/writing.


It is also possible to inject the:

  com.sun.ws.rest.api.core.ResourceConfig

Currently it is mutable, but i am thinking that this should really be an
immutable version. This has the potential to simplify the
ResourceProvider and related interfaces and IoC integration work.

Paul.

> And after that: enable deferring instantiation of readers/writers/jaxb
> resolvers/resource config etc to an IoC framework.
>
> Paul.

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109