public class

ServiceLayerDecorator

extends ServiceLayer
java.lang.Object
   ↳ com.google.gwt.requestfactory.server.ServiceLayer
     ↳ com.google.gwt.requestfactory.server.ServiceLayerDecorator

Class Overview

Users that intend to alter how RequestFactory interacts with the domain environment can extend this type and provide it to create(ServiceLayerDecorator). The methods defined in this type will automatically delegate to the next decorator or the root service object after being processed bycreate().

Summary

Public Constructors
ServiceLayerDecorator()
Public Methods
<T> T createDomainObject(Class<T> clazz)
Create an instance of the requested domain type.
<T extends Locator<?, ?>> T createLocator(Class<T> clazz)
Create an instance of the requested Locator type.
Object createServiceInstance(Method contextMethod, Method domainMethod)
Create an instance of a service object that can be used as the target for the given method invocation.
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.
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.
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...).
Class<? extends BaseProxy> resolveClass(String typeToken)
Given a type token previously returned from 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(Method requestContextMethod)
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.
Method resolveRequestContextMethod(String requestContextClass, String methodName)
Find a RequestContext method declaration by name.
Class<? extends ServiceLocator> resolveServiceLocator(Method contextMethod, Method domainMethod)
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<> validate(T domainObject)
Invoke a JSR 303 validator on the given domain object.
Protected Methods
final <T> T die(Throwable e, String message, Object... args)
Throw a fatal error up into the top-level processing code.
ServiceLayer getTop()
Returns the top-most service layer.
final <T> T report(InvocationTargetException userGeneratedException)
Report an exception thrown by code that is under the control of the end-developer.
final <T> T report(String msg, Object... args)
Return a message to the client.
[Expand]
Inherited Methods
From class com.google.gwt.requestfactory.server.ServiceLayer
From class java.lang.Object

Public Constructors

public ServiceLayerDecorator ()

Public Methods

public T createDomainObject (Class<T> clazz)

Create an instance of the requested domain type.

Parameters
clazz the requested domain type
Returns
  • an instance of the requested domain type

public T createLocator (Class<T> clazz)

Create an instance of the requested Locator type.

Parameters
clazz the requested Locator type
Returns
  • an instance of the requested Locator type

public Object createServiceInstance (Method contextMethod, Method domainMethod)

Create an instance of a service object that can be used as the target for the given method invocation.

Parameters
contextMethod a method defined in a RequestContext
domainMethod the method that the service object must implement
Returns
  • an instance of the requested service object

public Object getId (Object domainObject)

Return the persistent id for a domain object. May return 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.

Parameters
domainObject a domain object
Returns
  • the persistent id of the domain object or null if the object is not persistent

public Class<?> getIdType (Class<?> domainType)

Returns the type of object the domain type's findFoo() or Locator.getId() expects to receive.

Parameters
domainType a domain entity type
Returns
  • the type of the persistent id value used to represent the domain type

public Object getProperty (Object domainObject, String property)

Retrieve the named property from the domain object.

Parameters
domainObject the domain object being examined
property the property name
Returns
  • the value of the property

public Type getRequestReturnType (Method contextMethod)

Compute the return type for a method declared in a RequestContext by analyzing the generic method declaration.

public Object getVersion (Object domainObject)

May return 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.

Parameters
domainObject a domain object
Returns
  • the version of the domain object or null if the object is not persistent

public Object invoke (Method domainMethod, Object... args)

Invoke a domain service method. The underlying eventually calls Method#invoke(Object, Object...).

Parameters
domainMethod the method to invoke
args the arguments to pass to the method
Returns
  • the value returned from the method invocation

public boolean isLive (Object domainObject)

Returns true if the given domain object is still live (i.e. not deleted) in the backing store.

Parameters
domainObject a domain entity
Returns
  • true if domainObject could be retrieved at a later point in time

public T loadDomainObject (Class<T> clazz, Object domainId)

Load an object from the backing store. This method may return null to indicate that the requested object is no longer available.

Parameters
clazz the type of object to load
domainId an id previously returned from getId(Object)
Returns
  • the requested object or null if it is irretrievable

public List<Object> loadDomainObjects (List<Class<?>> classes, List<Object> domainIds)

Load multiple objects from the backing store. This method is intended to allow more efficient access to the backing store by providing all objects referenced in an incoming payload.

The default implementation of this method will delegate to loadDomainObject(Class, Object).

Parameters
classes type type of each object to load
domainIds the ids previously returned from getId(Object)
Returns
  • the requested objects, elements of which may be null if the requested objects were irretrievable

public 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...).

Parameters
contextMethod a method defined in a RequestContext
domainMethod a domain method
Returns
  • true if a ServiceLocator is required

public Class<? extends BaseProxy> resolveClass (String typeToken)

Given a type token previously returned from resolveTypeToken(Class), return the Class literal associated with the token.

Parameters
typeToken a string token
Returns
  • the type represented by the token

public 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. If multiple proxy types have been mapped to the same domain type, the clientType parameter is used to ensure assignability.

Parameters
domainClass the server-side type to be transported to the client
clientType the type to which the returned type must be assignable
required if true and no mapping is available, throw an UnexpectedException, othrewise the method will return null
Returns
  • a class that represents domainClass on the client which is assignable to clientType

public Class<?> resolveDomainClass (Class<?> clazz)

Determine the domain (server-side) type that the given client type is mapped to.

Parameters
clazz a client-side type
Returns
  • the domain type that clientType represents

public Method resolveDomainMethod (Method requestContextMethod)

Return the domain service method associated with a RequestContext method declaration. The requestContextMethod will have been previously resolved by resolveRequestContextMethod(String, String).

Parameters
requestContextMethod a RequestContext method declaration.
Returns
  • the domain service method that should be invoked

public Class<? extends Locator<?, ?>> resolveLocator (Class<?> domainType)

Return the type of Locator that should be used to access the given domain type.

Parameters
domainType a domain (server-side) type
Returns
  • the type of Locator to use, or null if the type conforms to the RequestFactory entity protocol

public Method resolveRequestContextMethod (String requestContextClass, String methodName)

Find a RequestContext method declaration by name.

Parameters
requestContextClass the fully-qualified binary name of the RequestContext
methodName the name of the service method declared within the RequestContext
Returns
  • the method declaration, or null if the method does not exist

public Class<? extends ServiceLocator> resolveServiceLocator (Method contextMethod, Method domainMethod)

Given a RequestContext method declaration, resolve the ServiceLocator that should be used when invoking the domain method. This method will only be called if #requiresServiceLocator(Method) returned true for the associated domain method.

Parameters
contextMethod a RequestContext method declaration
domainMethod the domain method that will be invoked
Returns
  • the type of ServiceLocator to use

public String resolveTypeToken (Class<? extends BaseProxy> proxyType)

Return a string used to represent the given type in the wire protocol.

Parameters
proxyType a client-side EntityProxy or ValueProxy type
Returns
  • the type token used to represent the proxy type

public void setProperty (Object domainObject, String property, Class<?> expectedType, Object value)

Sets a property on a domain object.

Parameters
domainObject the domain object to operate on
property the name of the property to set
expectedType the type of the property
value the new value

public Set<> validate (T domainObject)

Invoke a JSR 303 validator on the given domain object. If no validator is available, this method is a no-op.

Parameters
domainObject the domain objcet to validate
Returns
  • the violations associated with the domain object

Protected Methods

protected final T die (Throwable e, String message, Object... args)

Throw a fatal error up into the top-level processing code. This method should be used to provide diagnostic information that will help the end-developer track down problems when that data would expose implementation details of the server to the client.

Parameters
e a throwable with more data, may be null
message a printf-style format string
args arguments for the message
Throws
this method never returns normally
UnexpectedException
See Also
  • #report(String, Object...)

protected ServiceLayer getTop ()

Returns the top-most service layer. General-purpose ServiceLayer decorators should use the instance provided by getTop() when calling public methods on the ServiceLayer API to allow higher-level decorators to override behaviors built into lower-level decorators.

Returns

protected final T report (InvocationTargetException userGeneratedException)

Report an exception thrown by code that is under the control of the end-developer.

Throws
this method never returns normally
ReportableException

protected final T report (String msg, Object... args)

Return a message to the client. This method should not include any data that was not sent to the server by the client to avoid leaking data.

Parameters
msg a printf-style format string
args arguments for the message
Throws
this method never returns normally
ReportableException
See Also
  • #die(Throwable, String, Object...)