public abstract class ServiceLayer extends Object
SimpleRequestProcessor
and the domain environment. The core service
logic can be decorated by extending an ServiceLayerDecorator
.
This API is subject to change in future releases.
Modifier and Type | Method and Description |
---|---|
static ServiceLayer |
create(ServiceLayerDecorator... decorators)
Create a RequestFactory ServiceLayer that is optionally modified by the
given decorators.
|
abstract <T> T |
createDomainObject(Class<T> clazz)
Create an instance of the requested domain type.
|
abstract <T extends Locator<?,?>> |
createLocator(Class<T> clazz)
Create an instance of the requested
Locator type. |
abstract Object |
createServiceInstance(Class<? extends RequestContext> requestContext)
Create an instance of a service object that can be used as the target for
the given method invocation.
|
abstract <T extends ServiceLocator> |
createServiceLocator(Class<T> clazz)
Create an instance of the requested
ServiceLocator type. |
abstract ClassLoader |
getDomainClassLoader()
Returns the ClassLoader that should be used when attempting to access
domain classes or resources.
|
abstract Method |
getGetter(Class<?> domainType,
String property)
Determine the method to invoke when retrieving the given property.
|
abstract Object |
getId(Object domainObject)
Return the persistent id for a domain object.
|
abstract Class<?> |
getIdType(Class<?> domainType)
Returns the type of object the domain type's
findFoo() or
Locator.getId() expects to receive. |
abstract Object |
getProperty(Object domainObject,
String property)
Retrieve the named property from the domain object.
|
abstract Type |
getRequestReturnType(Method contextMethod)
Compute the return type for a method declared in a RequestContext by
analyzing the generic method declaration.
|
abstract Method |
getSetter(Class<?> domainType,
String property)
Determine the method to invoke when setting the given property.
|
abstract Object |
getVersion(Object domainObject)
May return
null to indicate that the domain object has not been
persisted. |
abstract Object |
invoke(Method domainMethod,
Object... args)
Invoke a domain service method.
|
abstract boolean |
isLive(Object domainObject)
Returns
true if the given domain object is still live (i.e. |
abstract <T> T |
loadDomainObject(Class<T> clazz,
Object domainId)
Load an object from the backing store.
|
abstract List<Object> |
loadDomainObjects(List<Class<?>> classes,
List<Object> domainIds)
Load multiple objects from the backing store.
|
abstract boolean |
requiresServiceLocator(Method contextMethod,
Method domainMethod)
Determines if the invocation of a domain method requires a
ServiceLocator as the 0th parameter when passed into
invoke(Method, Object...) . |
abstract Class<? extends BaseProxy> |
resolveClass(String typeToken)
Given a type token previously returned from
resolveTypeToken(Class) , return the Class literal associated with
the token. |
abstract <T> Class<? extends T> |
resolveClientType(Class<?> domainClass,
Class<T> clientType,
boolean required)
Determine the type used by the client code to represent a given domain
type.
|
abstract Class<?> |
resolveDomainClass(Class<?> clientType)
Determine the domain (server-side) type that the given client type is
mapped to.
|
abstract Method |
resolveDomainMethod(String operation)
Return the domain service method associated with a RequestContext method
declaration.
|
abstract Class<? extends Locator<?,?>> |
resolveLocator(Class<?> domainType)
Return the type of
Locator that should be used to access the given
domain type. |
abstract Class<? extends RequestContext> |
resolveRequestContext(String operation)
Find a RequestContext that should be used to fulfill the requested
operation.
|
abstract Method |
resolveRequestContextMethod(String operation)
Find a RequestContext method declaration by name.
|
abstract Class<? extends RequestFactory> |
resolveRequestFactory(String token)
Loads and validates a RequestFactory interface.
|
abstract Class<?> |
resolveServiceClass(Class<? extends RequestContext> requestContextClass)
Given a
RequestContext method, find the service class referenced in
the Service or
ServiceName annotation. |
abstract Class<? extends ServiceLocator> |
resolveServiceLocator(Class<? extends RequestContext> requestContext)
Given a RequestContext method declaration, resolve the
ServiceLocator that should be used when invoking the domain method. |
abstract String |
resolveTypeToken(Class<? extends BaseProxy> proxyType)
Return a string used to represent the given type in the wire protocol.
|
abstract void |
setProperty(Object domainObject,
String property,
Class<?> expectedType,
Object value)
Sets a property on a domain object.
|
abstract <T> Set<javax.validation.ConstraintViolation<T>> |
validate(T domainObject)
Invoke a JSR 303 validator on the given domain object.
|
public static ServiceLayer create(ServiceLayerDecorator... decorators)
decorators
- the decorators that will modify the behavior of the core
service layer implementationpublic abstract <T> T createDomainObject(Class<T> clazz)
T
- the requested domain typeclazz
- the requested domain typepublic abstract <T extends Locator<?,?>> T createLocator(Class<T> clazz)
Locator
type.T
- the requested Locator typeclazz
- the requested Locator typepublic abstract Object createServiceInstance(Class<? extends RequestContext> requestContext)
requestContext
- the RequestContext type for which a service object
must be instantiated.public abstract <T extends ServiceLocator> T createServiceLocator(Class<T> clazz)
ServiceLocator
type.T
- the requested ServiceLocator typeclazz
- the requested ServiceLocator typepublic abstract ClassLoader getDomainClassLoader()
The default implementation returns
Thread.currentThread().getContextClassLoader()
.
public abstract Method getGetter(Class<?> domainType, String property)
domainType
- a domain entity typeproperty
- the name of the property to be retrievednull
if the method could not be locatedpublic abstract Object getId(Object domainObject)
null
to
indicate that the domain object has not been persisted. The value returned
from this method must be a simple type (e.g. Integer, String) or a domain
type for which a mapping to an EntityProxy or Value proxy exists.
The values returned from this method may be passed to
loadDomainObject(Class, Object)
in the future.
domainObject
- a domain objectnull
if the
object is not persistentpublic abstract Class<?> getIdType(Class<?> domainType)
findFoo()
or
Locator.getId()
expects to receive.domainType
- a domain entity typepublic abstract Object getProperty(Object domainObject, String property)
domainObject
- the domain object being examinedproperty
- the property namepublic abstract Type getRequestReturnType(Method contextMethod)
public abstract Method getSetter(Class<?> domainType, String property)
domainType
- a domain entity typeproperty
- the name of the property to be setnull
if the method could not be locatedpublic abstract Object getVersion(Object domainObject)
null
to indicate that the domain object has not been
persisted. The value returned from this method must be a simple type (e.g.
Integer, String) or a domain type for which a mapping to an EntityProxy or
Value proxy exists.domainObject
- a domain objectnull
if the object is
not persistentpublic abstract Object invoke(Method domainMethod, Object... args)
Method.invoke(Object, Object...)
.domainMethod
- the method to invokeargs
- the arguments to pass to the methodpublic abstract boolean isLive(Object domainObject)
true
if the given domain object is still live (i.e. not
deleted) in the backing store.domainObject
- a domain entitytrue
if domainObject
could be retrieved at a later
point in timepublic abstract <T> T loadDomainObject(Class<T> clazz, Object domainId)
null
to indicate that the requested object is no longer available.T
- the type of object to loadclazz
- the type of object to loaddomainId
- an id previously returned from getId(Object)
null
if it is irretrievablepublic abstract List<Object> loadDomainObjects(List<Class<?>> classes, List<Object> domainIds)
The default implementation of this method will delegate to
loadDomainObject(Class, Object)
.
classes
- type type of each object to loaddomainIds
- the ids previously returned from getId(Object)
null
if the
requested objects were irretrievablepublic abstract boolean requiresServiceLocator(Method contextMethod, Method domainMethod)
ServiceLocator
as the 0th parameter when passed into
invoke(Method, Object...)
.contextMethod
- a method defined in a RequestContextdomainMethod
- a domain methodtrue
if a ServiceLocator is requiredpublic abstract Class<? extends BaseProxy> resolveClass(String typeToken)
resolveTypeToken(Class)
, return the Class literal associated with
the token.typeToken
- a string tokenpublic abstract <T> Class<? extends T> resolveClientType(Class<?> domainClass, Class<T> clientType, boolean required)
clientType
parameter is used to ensure assignability.domainClass
- the server-side type to be transported to the clientclientType
- the type to which the returned type must be assignablerequired
- if true
and no mapping is available, throw an
exception, otherwise the method will return null
domainClass
on the client which is
assignable to clientType
public abstract Class<?> resolveDomainClass(Class<?> clientType)
clientType
- a client-side typeclientType
representspublic abstract Method resolveDomainMethod(String operation)
requestContextMethod
will have been previously
resolved by #resolveRequestContextMethod(String, String)
.requestContext
- the RequestContext requested by the clientrequestContextMethod
- a RequestContext method declaration. Note that
this Method may be defined in a supertype of
requestContext
public abstract Class<? extends Locator<?,?>> resolveLocator(Class<?> domainType)
Locator
that should be used to access the given
domain type.domainType
- a domain (server-side) typenull
if the type conforms to
the RequestFactory entity protocolpublic abstract Class<? extends RequestContext> resolveRequestContext(String operation)
operation
- the operationnull
if no RequestContext exists that
can fulfill the operationpublic abstract Method resolveRequestContextMethod(String operation)
operation
- the operation's namenull
if the method does not
existpublic abstract Class<? extends RequestFactory> resolveRequestFactory(String token)
token
- the RequestFactory's type token (usually the type's binary
name)public abstract Class<?> resolveServiceClass(Class<? extends RequestContext> requestContextClass)
RequestContext
method, find the service class referenced in
the Service
or
ServiceName
annotation.requestContextClass
- a RequestContext interfacepublic abstract Class<? extends ServiceLocator> resolveServiceLocator(Class<? extends RequestContext> requestContext)
ServiceLocator
that should be used when invoking the domain method.
This method will only be called if
requiresServiceLocator(Method, Method)
returned true
for
the associated domain method.requestContext
- the RequestContext for which a ServiceLocator must be
locatedpublic abstract String resolveTypeToken(Class<? extends BaseProxy> proxyType)
proxyType
- a client-side EntityProxy or ValueProxy typepublic abstract void setProperty(Object domainObject, String property, Class<?> expectedType, Object value)
domainObject
- the domain object to operate onproperty
- the name of the property to setexpectedType
- the type of the propertyvalue
- the new valuepublic abstract <T> Set<javax.validation.ConstraintViolation<T>> validate(T domainObject)
T
- the type of data being validateddomainObject
- the domain objcet to validateCopyright © 2016. All rights reserved.