org.restlet.ext.odata
Class Service

java.lang.Object
  extended by org.restlet.ext.odata.Service

public class Service
extends Object

Acts as a manager for a specific remote OData service. OData services are stateless, but Service instances are not. State on the client is maintained between interactions in order to support features such as update management.

This Java class is more or less equivalent to the WCF DataServiceContext class.

Author:
Jerome Louvel
See Also:
DataServiceContext Class on MSDN

Field Summary
static String WCF_DATASERVICES_METADATA_NAMESPACE
          WCF data services metadata namespace.
static String WCF_DATASERVICES_NAMESPACE
          WCF data services namespace.
static String WCF_DATASERVICES_SCHEME_NAMESPACE
          WCF data services scheme namespace.
 
Constructor Summary
Service(Reference serviceRef)
          Constructor.
Service(String serviceUri)
          Constructor.
 
Method Summary
 void addEntity(String entitySetName, Object entity)
          Adds an entity to an entity set.
 void addLink(Object source, String sourceProperty, Object target)
          Adds an association between the source and the target entity via the given property name.
<T> Query<T>
createQuery(String subpath, Class<T> entityClass)
          Creates a query to a specific entity hosted by this service.
 ClientResource createResource(Reference reference)
          Returns an instance of ClientResource given an absolute reference.
 ClientResource createResource(String relativePath)
          Returns an instance of ClientResource given a path (relative to the service reference).
 void deleteEntity(Object entity)
          Deletes an entity.
 void deleteEntity(String entitySubpath)
          Deletes an entity.
 void deleteLink(Object source, String sourceProperty, Object target)
          Removes the association between a source entity and a target entity via the given property name.
 String getClientVersion()
          Returns the version of the OData protocol extensions defined in every request issued by this service.
 ChallengeResponse getCredentials()
          Returns the credentials used to authenticate requests.
 Request getLatestRequest()
          Returns the latest request sent to the service.
 Response getLatestResponse()
          Returns the response to the latest request.
 String getMaxClientVersion()
          Returns the maximum version of the OData protocol extensions the client can accept in a response.
protected  Object getMetadata()
          Returns the metadata document related to the current service.
 String getServerVersion()
          Returns the version of the OData protocol extensions supported by the remote service.
 Reference getServiceRef()
          Returns the reference to the WCF service.
 Representation getValue(Object entity)
          Returns the binary representation of the given media resource.
 Representation getValue(Object entity, List<Preference<MediaType>> acceptedMediaTypes)
          Returns the binary representation of the given media resource.
 Representation getValue(Object entity, MediaType mediaType)
          Returns the binary representation of the given media resource.
 Reference getValueRef(Object entity)
          Returns the reference of the binary representation of the given entity, if this is a media resource.
 Representation invokeComplex(String service, Series<Parameter> parameters)
          Invokes a service operation and return the raw representation sent back by the service.
 String invokeSimple(String service, Series<Parameter> parameters)
          Invokes a service operation and return the String value sent back by the service.
 void loadProperty(Object entity, String propertyName)
          Updates the given entity object with the value of the specified property.
 void setClientVersion(String clientVersion)
          Sets the version of the OData protocol extensions defined in every request issued by this service.
 void setCredentials(ChallengeResponse credentials)
          Sets the credentials used to authenticate requests.
 void setLatestRequest(Request latestRequest)
          Sets the latest request sent to the service.
 void setLatestResponse(Response latestResponse)
          Sets the response to the latest request.
 void setLink(Object source, String sourceProperty, Object target)
          Sets the association between the source and the target entity via the given property name.
 void setMaxClientVersion(String maxClientVersion)
          Sets the maximum version of the OData protocol extensions the client can accept in a response.
 void setValue(Object entity, Representation blob)
          Sets the value of the given media entry link.
 Entry toEntry(Object entity)
          Converts an entity to an Atom entry object.
 void updateEntity(Object entity)
          Updates an entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WCF_DATASERVICES_METADATA_NAMESPACE

public static final String WCF_DATASERVICES_METADATA_NAMESPACE
WCF data services metadata namespace.

See Also:
Constant Field Values

WCF_DATASERVICES_NAMESPACE

public static final String WCF_DATASERVICES_NAMESPACE
WCF data services namespace.

See Also:
Constant Field Values

WCF_DATASERVICES_SCHEME_NAMESPACE

public static final String WCF_DATASERVICES_SCHEME_NAMESPACE
WCF data services scheme namespace.

See Also:
Constant Field Values
Constructor Detail

Service

public Service(Reference serviceRef)
Constructor.

Parameters:
serviceRef - The reference to the WCF service.

Service

public Service(String serviceUri)
Constructor.

Parameters:
serviceUri - The URI of the WCF service.
Method Detail

addEntity

public void addEntity(String entitySetName,
                      Object entity)
               throws Exception
Adds an entity to an entity set.

Parameters:
entitySetName - The path of the entity set relatively to the service URI.
entity - The entity to put.
Throws:
Exception

addLink

public void addLink(Object source,
                    String sourceProperty,
                    Object target)
             throws Exception
Adds an association between the source and the target entity via the given property name.

Parameters:
source - The source entity to update.
sourceProperty - The name of the property of the source entity.
target - The entity to add to the source entity.
Throws:
Exception

createQuery

public <T> Query<T> createQuery(String subpath,
                                Class<T> entityClass)
Creates a query to a specific entity hosted by this service.

Type Parameters:
T - The class of the target entity.
Parameters:
subpath - The path to this entity relatively to the service URI.
entityClass - The target class of the entity.
Returns:
A query object.

createResource

public ClientResource createResource(Reference reference)
Returns an instance of ClientResource given an absolute reference. This resource is completed with the service credentials. This method can be overriden in order to complete the sent requests.

Parameters:
reference - The reference of the target resource.
Returns:
An instance of ClientResource.

createResource

public ClientResource createResource(String relativePath)
Returns an instance of ClientResource given a path (relative to the service reference). This resource is completed with the service credentials. This method can be overriden in order to complete the sent requests.

Parameters:
relativePath - The relative reference of the target resource.
Returns:
An instance of ClientResource given a path (relative to the service reference).

deleteEntity

public void deleteEntity(Object entity)
                  throws ResourceException
Deletes an entity.

Parameters:
entity - The entity to delete
Throws:
ResourceException

deleteEntity

public void deleteEntity(String entitySubpath)
                  throws ResourceException
Deletes an entity.

Parameters:
entitySubpath - The path of the entity to delete
Throws:
ResourceException

deleteLink

public void deleteLink(Object source,
                       String sourceProperty,
                       Object target)
                throws ResourceException
Removes the association between a source entity and a target entity via the given property name.

Parameters:
source - The source entity to update.
sourceProperty - The name of the property of the source entity.
target - The entity to delete from the source entity.
Throws:
ResourceException

getClientVersion

public String getClientVersion()
Returns the version of the OData protocol extensions defined in every request issued by this service.

Returns:
The version of the OData protocol extensions defined in every request issued by this service.

getCredentials

public ChallengeResponse getCredentials()
Returns the credentials used to authenticate requests.

Returns:
The credentials used to authenticate requests.

getLatestRequest

public Request getLatestRequest()
Returns the latest request sent to the service.

Returns:
The latest request sent to the service.

getLatestResponse

public Response getLatestResponse()
Returns the response to the latest request.

Returns:
The response to the latest request.

getMaxClientVersion

public String getMaxClientVersion()
Returns the maximum version of the OData protocol extensions the client can accept in a response.

Returns:
The maximum version of the OData protocol extensions the client can accept in a response.

getMetadata

protected Object getMetadata()
Returns the metadata document related to the current service.

Returns:
The metadata document related to the current service.

getServerVersion

public String getServerVersion()
Returns the version of the OData protocol extensions supported by the remote service.

Returns:
The version of the OData protocol extensions supported by the remote service.

getServiceRef

public Reference getServiceRef()
Returns the reference to the WCF service.

Returns:
The reference to the WCF service.

getValue

public Representation getValue(Object entity)
                        throws ResourceException
Returns the binary representation of the given media resource. If the entity is not a media resource, it returns null.

Parameters:
entity - The given media resource.
Returns:
The binary representation of the given media resource.
Throws:
ResourceException

getValue

public Representation getValue(Object entity,
                               List<Preference<MediaType>> acceptedMediaTypes)
                        throws ResourceException
Returns the binary representation of the given media resource. If the entity is not a media resource, it returns null.

Parameters:
entity - The given media resource.
acceptedMediaTypes - The requested media types of the representation.
Returns:
The given media resource.
Throws:
ResourceException

getValue

public Representation getValue(Object entity,
                               MediaType mediaType)
                        throws ResourceException
Returns the binary representation of the given media resource. If the entity is not a media resource, it returns null.

Parameters:
entity - The given media resource.
mediaType - The requested media type of the representation
Returns:
The given media resource.
Throws:
ResourceException

getValueRef

public Reference getValueRef(Object entity)
Returns the reference of the binary representation of the given entity, if this is a media resource. It returns null otherwise.

Parameters:
entity - The media resource.
Returns:
The reference of the binary representation of the given entity, if this is a media resource. It returns null otherwise.

invokeComplex

public Representation invokeComplex(String service,
                                    Series<Parameter> parameters)
                             throws ResourceException
Invokes a service operation and return the raw representation sent back by the service.

Parameters:
service - The name of the service.
parameters - The list of required parameters.
Returns:
The representation returned by the invocation of the service.
Throws:
ResourceException - Thrown when the service call is not successfull.
See Also:
Service Operations

invokeSimple

public String invokeSimple(String service,
                           Series<Parameter> parameters)
                    throws ResourceException,
                           Exception
Invokes a service operation and return the String value sent back by the service.

Parameters:
service - The name of the service.
parameters - The list of required parameters.
Returns:
The value returned by the invocation of the service as a String.
Throws:
ResourceException - Thrown when the service call is not successfull.
Exception - Thrown when the value cannot be parsed.
See Also:
Service Operations

loadProperty

public void loadProperty(Object entity,
                         String propertyName)
Updates the given entity object with the value of the specified property.

Parameters:
entity - The entity to update.
propertyName - The name of the property.

setClientVersion

public void setClientVersion(String clientVersion)
Sets the version of the OData protocol extensions defined in every request issued by this service.

Parameters:
clientVersion - The version of the OData protocol extensions defined in every request issued by this service.

setCredentials

public void setCredentials(ChallengeResponse credentials)
Sets the credentials used to authenticate requests.

Parameters:
credentials - The credentials used to authenticate requests.

setLatestRequest

public void setLatestRequest(Request latestRequest)
Sets the latest request sent to the service.

Parameters:
latestRequest - The latest request sent to the service.

setLatestResponse

public void setLatestResponse(Response latestResponse)
Sets the response to the latest request.

Parameters:
latestResponse - The response to the latest request.

setLink

public void setLink(Object source,
                    String sourceProperty,
                    Object target)
             throws Exception
Sets the association between the source and the target entity via the given property name. If target is set to null, the call represents a delete link operation.

Parameters:
source - The source entity to update.
sourceProperty - The name of the property of the source entity.
target - The entity to add to the source entity.
Throws:
Exception

setMaxClientVersion

public void setMaxClientVersion(String maxClientVersion)
Sets the maximum version of the OData protocol extensions the client can accept in a response.

Parameters:
maxClientVersion - The maximum version of the OData protocol extensions the client can accept in a response.

setValue

public void setValue(Object entity,
                     Representation blob)
              throws ResourceException
Sets the value of the given media entry link.

Parameters:
entity - The media entry link which value is to be updated
blob - The new representation.
Throws:
ResourceException

toEntry

public Entry toEntry(Object entity)
Converts an entity to an Atom entry object.

Parameters:
entity - The entity to wrap.
Returns:
The Atom entry object that corresponds to the given entity.

updateEntity

public void updateEntity(Object entity)
                  throws Exception
Updates an entity.

Parameters:
entity - The entity to put.
Throws:
Exception


Copyright © 2005-2013 Restlet.