public class ServiceLayerDecorator extends ServiceLayer
ServiceLayer.create(ServiceLayerDecorator...)
. The methods defined in
this type will automatically delegate to the next decorator or the root
service object after being processed bycreate()
.Constructor and Description |
---|
ServiceLayerDecorator() |
Modifier and Type | Method and Description |
---|---|
<T> T |
createDomainObject(Class<T> clazz)
Create an instance of the requested domain type.
|
<T extends Locator<?,?>> |
createLocator(Class<T> clazz)
Create an instance of the requested
Locator type. |
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.
|
<T extends ServiceLocator> |
createServiceLocator(Class<T> clazz)
Create an instance of the requested
ServiceLocator type. |
protected <T> T |
die(Throwable e,
String message,
Object... args)
Throw a fatal error up into the top-level processing code.
|
ClassLoader |
getDomainClassLoader()
Returns the ClassLoader that should be used when attempting to access
domain classes or resources.
|
Method |
getGetter(Class<?> domainType,
String property)
Determine the method to invoke when retrieving the given property.
|
Object |
getId(Object domainObject)
Return the persistent id for a domain object.
|
Class<?> |
getIdType(Class<?> domainType)
Returns the type of object the domain type's
findFoo() or
Locator.getId() expects to receive. |
Object |
getProperty(Object domainObject,
String property)
Retrieve the named property from the domain object.
|
Type |
getRequestReturnType(Method contextMethod)
Compute the return type for a method declared in a RequestContext by
analyzing the generic method declaration.
|
Method |
getSetter(Class<?> domainType,
String property)
Determine the method to invoke when setting the given property.
|
protected ServiceLayer |
getTop()
Returns the top-most service layer.
|
Object |
getVersion(Object domainObject)
May return
null to indicate that the domain object has not been
persisted. |
Object |
invoke(Method domainMethod,
Object... args)
Invoke a domain service method.
|
boolean |
isLive(Object domainObject)
Returns
true if the given domain object is still live (i.e. |
<T> T |
loadDomainObject(Class<T> clazz,
Object domainId)
Load an object from the backing store.
|
List<Object> |
loadDomainObjects(List<Class<?>> classes,
List<Object> domainIds)
Load multiple objects from the backing store.
|
protected <T> T |
report(InvocationTargetException userGeneratedException)
Report an exception thrown by code that is under the control of the
end-developer.
|
protected <T> T |
report(String msg,
Object... args)
Return a message to the client.
|
boolean |
requiresServiceLocator(Method contextMethod,
Method domainMethod)
Determines if the invocation of a domain method requires a
ServiceLocator as the 0th parameter when passed into
ServiceLayer.invoke(Method, Object...) . |
Class<? extends BaseProxy> |
resolveClass(String typeToken)
Given a type token previously returned from
ServiceLayer.resolveTypeToken(Class) , return the Class literal associated with
the token. |
<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.
|
Class<?> |
resolveDomainClass(Class<?> clazz)
Determine the domain (server-side) type that the given client type is
mapped to.
|
Method |
resolveDomainMethod(String operation)
Return the domain service method associated with a RequestContext method
declaration.
|
Class<? extends Locator<?,?>> |
resolveLocator(Class<?> domainType)
Return the type of
Locator that should be used to access the given
domain type. |
Class<? extends RequestContext> |
resolveRequestContext(String operation)
Find a RequestContext that should be used to fulfill the requested
operation.
|
Method |
resolveRequestContextMethod(String operation)
Find a RequestContext method declaration by name.
|
Class<? extends RequestFactory> |
resolveRequestFactory(String binaryName)
Loads and validates a RequestFactory interface.
|
Class<?> |
resolveServiceClass(Class<? extends RequestContext> requestContextClass)
Given a
RequestContext method, find the service class referenced in
the Service or
ServiceName annotation. |
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. |
String |
resolveTypeToken(Class<? extends BaseProxy> proxyType)
Return a string used to represent the given type in the wire protocol.
|
void |
setProperty(Object domainObject,
String property,
Class<?> expectedType,
Object value)
Sets a property on a domain object.
|
<T> Set<javax.validation.ConstraintViolation<T>> |
validate(T domainObject)
Invoke a JSR 303 validator on the given domain object.
|
create
public <T> T createDomainObject(Class<T> clazz)
ServiceLayer
createDomainObject
in class ServiceLayer
T
- the requested domain typeclazz
- the requested domain typepublic <T extends Locator<?,?>> T createLocator(Class<T> clazz)
ServiceLayer
Locator
type.createLocator
in class ServiceLayer
T
- the requested Locator typeclazz
- the requested Locator typepublic Object createServiceInstance(Class<? extends RequestContext> requestContext)
ServiceLayer
createServiceInstance
in class ServiceLayer
requestContext
- the RequestContext type for which a service object
must be instantiated.public <T extends ServiceLocator> T createServiceLocator(Class<T> clazz)
ServiceLayer
ServiceLocator
type.createServiceLocator
in class ServiceLayer
T
- the requested ServiceLocator typeclazz
- the requested ServiceLocator typepublic ClassLoader getDomainClassLoader()
ServiceLayer
The default implementation returns
Thread.currentThread().getContextClassLoader()
.
getDomainClassLoader
in class ServiceLayer
public Method getGetter(Class<?> domainType, String property)
ServiceLayer
getGetter
in class ServiceLayer
domainType
- a domain entity typeproperty
- the name of the property to be retrievednull
if the method could not be locatedpublic Object getId(Object domainObject)
ServiceLayer
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
ServiceLayer.loadDomainObject(Class, Object)
in the future.
getId
in class ServiceLayer
domainObject
- a domain objectnull
if the
object is not persistentpublic Class<?> getIdType(Class<?> domainType)
ServiceLayer
findFoo()
or
Locator.getId()
expects to receive.getIdType
in class ServiceLayer
domainType
- a domain entity typepublic Object getProperty(Object domainObject, String property)
ServiceLayer
getProperty
in class ServiceLayer
domainObject
- the domain object being examinedproperty
- the property namepublic Type getRequestReturnType(Method contextMethod)
ServiceLayer
getRequestReturnType
in class ServiceLayer
public Method getSetter(Class<?> domainType, String property)
ServiceLayer
getSetter
in class ServiceLayer
domainType
- a domain entity typeproperty
- the name of the property to be setnull
if the method could not be locatedpublic Object getVersion(Object domainObject)
ServiceLayer
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.getVersion
in class ServiceLayer
domainObject
- a domain objectnull
if the object is
not persistentpublic Object invoke(Method domainMethod, Object... args)
ServiceLayer
Method.invoke(Object, Object...)
.invoke
in class ServiceLayer
domainMethod
- the method to invokeargs
- the arguments to pass to the methodpublic boolean isLive(Object domainObject)
ServiceLayer
true
if the given domain object is still live (i.e. not
deleted) in the backing store.isLive
in class ServiceLayer
domainObject
- a domain entitytrue
if domainObject
could be retrieved at a later
point in timepublic <T> T loadDomainObject(Class<T> clazz, Object domainId)
ServiceLayer
null
to indicate that the requested object is no longer available.loadDomainObject
in class ServiceLayer
T
- the type of object to loadclazz
- the type of object to loaddomainId
- an id previously returned from ServiceLayer.getId(Object)
null
if it is irretrievablepublic List<Object> loadDomainObjects(List<Class<?>> classes, List<Object> domainIds)
ServiceLayer
The default implementation of this method will delegate to
ServiceLayer.loadDomainObject(Class, Object)
.
loadDomainObjects
in class ServiceLayer
classes
- type type of each object to loaddomainIds
- the ids previously returned from ServiceLayer.getId(Object)
null
if the
requested objects were irretrievablepublic boolean requiresServiceLocator(Method contextMethod, Method domainMethod)
ServiceLayer
ServiceLocator
as the 0th parameter when passed into
ServiceLayer.invoke(Method, Object...)
.requiresServiceLocator
in class ServiceLayer
contextMethod
- a method defined in a RequestContextdomainMethod
- a domain methodtrue
if a ServiceLocator is requiredpublic Class<? extends BaseProxy> resolveClass(String typeToken)
ServiceLayer
ServiceLayer.resolveTypeToken(Class)
, return the Class literal associated with
the token.resolveClass
in class ServiceLayer
typeToken
- a string tokenpublic <T> Class<? extends T> resolveClientType(Class<?> domainClass, Class<T> clientType, boolean required)
ServiceLayer
clientType
parameter is used to ensure assignability.resolveClientType
in class ServiceLayer
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 Class<?> resolveDomainClass(Class<?> clazz)
ServiceLayer
resolveDomainClass
in class ServiceLayer
clazz
- a client-side typeclientType
representspublic Method resolveDomainMethod(String operation)
ServiceLayer
requestContextMethod
will have been previously
resolved by #resolveRequestContextMethod(String, String)
.resolveDomainMethod
in class ServiceLayer
public Class<? extends Locator<?,?>> resolveLocator(Class<?> domainType)
ServiceLayer
Locator
that should be used to access the given
domain type.resolveLocator
in class ServiceLayer
domainType
- a domain (server-side) typenull
if the type conforms to
the RequestFactory entity protocolpublic Class<? extends RequestContext> resolveRequestContext(String operation)
ServiceLayer
resolveRequestContext
in class ServiceLayer
operation
- the operationnull
if no RequestContext exists that
can fulfill the operationpublic Method resolveRequestContextMethod(String operation)
ServiceLayer
resolveRequestContextMethod
in class ServiceLayer
operation
- the operation's namenull
if the method does not
existpublic Class<? extends RequestFactory> resolveRequestFactory(String binaryName)
ServiceLayer
resolveRequestFactory
in class ServiceLayer
binaryName
- the RequestFactory's type token (usually the type's binary
name)public Class<?> resolveServiceClass(Class<? extends RequestContext> requestContextClass)
ServiceLayer
RequestContext
method, find the service class referenced in
the Service
or
ServiceName
annotation.resolveServiceClass
in class ServiceLayer
requestContextClass
- a RequestContext interfacepublic Class<? extends ServiceLocator> resolveServiceLocator(Class<? extends RequestContext> requestContext)
ServiceLayer
ServiceLocator
that should be used when invoking the domain method.
This method will only be called if
ServiceLayer.requiresServiceLocator(Method, Method)
returned true
for
the associated domain method.resolveServiceLocator
in class ServiceLayer
requestContext
- the RequestContext for which a ServiceLocator must be
locatedpublic String resolveTypeToken(Class<? extends BaseProxy> proxyType)
ServiceLayer
resolveTypeToken
in class ServiceLayer
proxyType
- a client-side EntityProxy or ValueProxy typepublic void setProperty(Object domainObject, String property, Class<?> expectedType, Object value)
ServiceLayer
setProperty
in class ServiceLayer
domainObject
- the domain object to operate onproperty
- the name of the property to setexpectedType
- the type of the propertyvalue
- the new valuepublic <T> Set<javax.validation.ConstraintViolation<T>> validate(T domainObject)
ServiceLayer
validate
in class ServiceLayer
T
- the type of data being validateddomainObject
- the domain objcet to validateprotected final <T> T die(Throwable e, String message, Object... args) throws com.google.web.bindery.requestfactory.server.UnexpectedException
e
- a throwable with more data, may be null
message
- a printf-style format stringargs
- arguments for the messageUnexpectedException
- this method never returns normallyreport(String, Object...)
protected final ServiceLayer getTop()
getTop()
when calling public
methods on the ServiceLayer API to allow higher-level decorators to
override behaviors built into lower-level decorators.ServiceLayer.create(ServiceLayerDecorator...)
protected final <T> T report(InvocationTargetException userGeneratedException) throws com.google.web.bindery.requestfactory.server.ReportableException
userGeneratedException
- an InvocationTargetException
thrown
by an invocation of user-provided codeReportableException
- this method never returns normallyprotected final <T> T report(String msg, Object... args) throws com.google.web.bindery.requestfactory.server.ReportableException
msg
- a printf-style format stringargs
- arguments for the messageReportableException
- this method never returns normallydie(Throwable, String, Object...)
Copyright © 2016. All rights reserved.