com.cedarsoft.rest
Class JaxbMapping<T,J extends JaxbObject,S extends JaxbStub<J>>

java.lang.Object
  extended by com.cedarsoft.rest.JaxbMapping<T,J,S>
Type Parameters:
T - the type
J - the Jaxb type
S - the Jaxb stub type

public abstract class JaxbMapping<T,J extends JaxbObject,S extends JaxbStub<J>>
extends Object


Constructor Summary
JaxbMapping()
           
 
Method Summary
protected abstract  void copyFieldsToJaxbObject(T source, J target, UriContext context)
          Copies the fields from the source to the target.
protected abstract  void copyFieldsToStub(T source, S target, UriContext context)
           
protected abstract  J createJaxbObject(T object)
          Creates the basic JaxbObject.
protected  J createJaxbObject(T object, UriContext context)
          Creates the jaxb object
protected  S createJaxbObjectStub(T object, UriContext context)
          Creates the JaxbObjectStub.
protected abstract  S createJaxbStub(T object)
          Creates the basic stub.
protected  UriContext createLocalContext(UriContext context, JaxbObject jaxbObject)
          Creates the local context.
protected
<T,J extends JaxbObject>
List<J>
get(Class<J> jaxbType, Iterable<? extends T> objects, UriContext context)
           
protected
<T,J extends JaxbObject>
J
get(Class<J> jaxbType, T object, UriContext context)
           
 DelegateJaxbMappings getDelegatesMapping()
           
 J getJaxbObject(T object, UriContext context)
           
 List<J> getJaxbObjects(Iterable<? extends T> objects, UriContext context)
           
 S getJaxbObjectStub(T object, UriContext context)
           
 List<S> getJaxbStubs(Iterable<? extends T> objects, UriContext context)
           
protected
<T,J extends JaxbObject,S extends JaxbStub<J>>
List<S>
getStub(Class<S> jaxbSubType, Iterable<? extends T> objects, UriContext context)
           
protected
<T,J extends JaxbObject,S extends JaxbStub<J>>
S
getStub(Class<S> jaxbStubType, T object, UriContext context)
           
protected abstract  javax.ws.rs.core.UriBuilder getUri(JaxbObject object, UriContext context)
          Returns the local URI for the object
protected  void setHref(JaxbObject jaxbObject, UriContext context)
          Sets the URI to the jaxb object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JaxbMapping

public JaxbMapping()
Method Detail

getDelegatesMapping

@NotNull
public DelegateJaxbMappings getDelegatesMapping()

getJaxbObjectStub

@NotNull
public S getJaxbObjectStub(@NotNull
                                   T object,
                                   @NotNull
                                   UriContext context)

getJaxbObject

@NotNull
public J getJaxbObject(@NotNull
                               T object,
                               @NotNull
                               UriContext context)

get

@Nullable
protected <T,J extends JaxbObject> J get(@NotNull
                                                  Class<J> jaxbType,
                                                  @Nullable
                                                  T object,
                                                  @NotNull
                                                  UriContext context)

get

@Nullable
protected <T,J extends JaxbObject> List<J> get(@NotNull
                                                        Class<J> jaxbType,
                                                        @NotNull
                                                        Iterable<? extends T> objects,
                                                        @NotNull
                                                        UriContext context)

getStub

@Nullable
protected <T,J extends JaxbObject,S extends JaxbStub<J>> S getStub(@NotNull
                                                                            Class<S> jaxbStubType,
                                                                            @Nullable
                                                                            T object,
                                                                            @NotNull
                                                                            UriContext context)

getStub

@Nullable
protected <T,J extends JaxbObject,S extends JaxbStub<J>> List<S> getStub(@NotNull
                                                                                  Class<S> jaxbSubType,
                                                                                  @NotNull
                                                                                  Iterable<? extends T> objects,
                                                                                  @NotNull
                                                                                  UriContext context)

getJaxbObjects

@NotNull
public List<J> getJaxbObjects(@NotNull
                                      Iterable<? extends T> objects,
                                      @NotNull
                                      UriContext context)

getJaxbStubs

@NotNull
public List<S> getJaxbStubs(@NotNull
                                    Iterable<? extends T> objects,
                                    @NotNull
                                    UriContext context)

createLocalContext

@Nullable
protected UriContext createLocalContext(@NotNull
                                                 UriContext context,
                                                 @NotNull
                                                 JaxbObject jaxbObject)
Creates the local context. The local context has an updated URI context.

Parameters:
context - the base context (not local!)
jaxbObject - the jaxb object
Returns:
the local context (with updated URI builder) - or null if no local context is available

createJaxbObject

@NotNull
protected final J createJaxbObject(@NotNull
                                           T object,
                                           @NotNull
                                           UriContext context)
Creates the jaxb object

Parameters:
object - the object
context - the context
Returns:
the jaxb object

createJaxbObjectStub

protected final S createJaxbObjectStub(@NotNull
                                       T object,
                                       @NotNull
                                       UriContext context)
Creates the JaxbObjectStub.

A stub only contains the very basic informations off the object. It is used in collections and when referenced from other objects.

It has to contain a href to fetch the missing details later.

Parameters:
object - the object
context - the context
Returns:
the stub

setHref

protected void setHref(@NotNull
                       JaxbObject jaxbObject,
                       @NotNull
                       UriContext context)
Sets the URI to the jaxb object. Override this method for custom behaviour (e.g. no href set)

Parameters:
jaxbObject - the jaxb object
context - the context

getUri

@Nullable
protected abstract javax.ws.rs.core.UriBuilder getUri(@NotNull
                                                               JaxbObject object,
                                                               @NotNull
                                                               UriContext context)
Returns the local URI for the object

Parameters:
object - the object (may be used to fetch the ID)
context - the context
Returns:
the updated uri builder or null of no URI is available

createJaxbObject

@NotNull
protected abstract J createJaxbObject(@NotNull
                                              T object)
Creates the basic JaxbObject. This method also *must* set the ID

Parameters:
object - the object
Returns:
the jaxb object (with the ID set)

createJaxbStub

@NotNull
protected abstract S createJaxbStub(@NotNull
                                            T object)
Creates the basic stub. This method also *must* set the ID

Parameters:
object - the object
Returns:
the stub object (with the ID set)

copyFieldsToJaxbObject

protected abstract void copyFieldsToJaxbObject(@NotNull
                                               T source,
                                               @NotNull
                                               J target,
                                               @NotNull
                                               UriContext context)
Copies the fields from the source to the target.

Context: This is the local context that has been created using the URI returned by getUri(JaxbObject, UriContext). If that method returns null, there is no local context available and the given parameter is the context of the parent.

Parameters:
source - the source object
target - the target jaxb object
context - the (local) context.

copyFieldsToStub

protected abstract void copyFieldsToStub(@NotNull
                                         T source,
                                         @NotNull
                                         S target,
                                         @NotNull
                                         UriContext context)


Copyright © 2011 cedarsoft GmbH. All Rights Reserved.