Package org.restlet.ext.odata
Class Service
- java.lang.Object
-
- org.restlet.ext.odata.Service
-
public class Service extends java.lang.Object
Acts as a manager for a specific remote OData service. OData services are stateless, butService
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
Fields Modifier and Type Field Description static java.lang.String
WCF_DATASERVICES_METADATA_NAMESPACE
WCF data services metadata namespace.static java.lang.String
WCF_DATASERVICES_NAMESPACE
WCF data services namespace.static java.lang.String
WCF_DATASERVICES_SCHEME_NAMESPACE
WCF data services scheme namespace.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEntity(java.lang.String entitySetName, java.lang.Object entity)
Adds an entity to an entity set.void
addLink(java.lang.Object source, java.lang.String sourceProperty, java.lang.Object target)
Adds an association between the source and the target entity via the given property name.<T> Query<T>
createQuery(java.lang.String subpath, java.lang.Class<T> entityClass)
Creates a query to a specific entity hosted by this service.org.restlet.resource.ClientResource
createResource(java.lang.String relativePath)
Returns an instance ofClientResource
given a path (relative to the service reference).org.restlet.resource.ClientResource
createResource(org.restlet.data.Reference reference)
Returns an instance ofClientResource
given an absolute reference.void
deleteEntity(java.lang.Object entity)
Deletes an entity.void
deleteEntity(java.lang.String entitySubpath)
Deletes an entity.void
deleteLink(java.lang.Object source, java.lang.String sourceProperty, java.lang.Object target)
Removes the association between a source entity and a target entity via the given property name.java.lang.String
getClientVersion()
Returns the version of the OData protocol extensions defined in every request issued by this service.org.restlet.data.ChallengeResponse
getCredentials()
Returns the credentials used to authenticate requests.org.restlet.Request
getLatestRequest()
Returns the latest request sent to the service.org.restlet.Response
getLatestResponse()
Returns the response to the latest request.java.lang.String
getMaxClientVersion()
Returns the maximum version of the OData protocol extensions the client can accept in a response.protected java.lang.Object
getMetadata()
Returns the metadata document related to the current service.java.lang.String
getServerVersion()
Returns the version of the OData protocol extensions supported by the remote service.org.restlet.data.Reference
getServiceRef()
Returns the reference to the WCF service.org.restlet.representation.Representation
getValue(java.lang.Object entity)
Returns the binary representation of the given media resource.org.restlet.representation.Representation
getValue(java.lang.Object entity, java.util.List<org.restlet.data.Preference<org.restlet.data.MediaType>> acceptedMediaTypes)
Returns the binary representation of the given media resource.org.restlet.representation.Representation
getValue(java.lang.Object entity, org.restlet.data.MediaType mediaType)
Returns the binary representation of the given media resource.org.restlet.data.Reference
getValueRef(java.lang.Object entity)
Returns the reference of the binary representation of the given entity, if this is a media resource.org.restlet.representation.Representation
invokeComplex(java.lang.String service, org.restlet.util.Series<org.restlet.data.Parameter> parameters)
Invokes a service operation and return the raw representation sent back by the service.java.lang.String
invokeSimple(java.lang.String service, org.restlet.util.Series<org.restlet.data.Parameter> parameters)
Invokes a service operation and return the String value sent back by the service.void
loadProperty(java.lang.Object entity, java.lang.String propertyName)
Updates the given entity object with the value of the specified property.void
setClientVersion(java.lang.String clientVersion)
Sets the version of the OData protocol extensions defined in every request issued by this service.void
setCredentials(org.restlet.data.ChallengeResponse credentials)
Sets the credentials used to authenticate requests.void
setLatestRequest(org.restlet.Request latestRequest)
Sets the latest request sent to the service.void
setLatestResponse(org.restlet.Response latestResponse)
Sets the response to the latest request.void
setLink(java.lang.Object source, java.lang.String sourceProperty, java.lang.Object target)
Sets the association between the source and the target entity via the given property name.void
setMaxClientVersion(java.lang.String maxClientVersion)
Sets the maximum version of the OData protocol extensions the client can accept in a response.void
setValue(java.lang.Object entity, org.restlet.representation.Representation blob)
Sets the value of the given media entry link.Entry
toEntry(java.lang.Object entity)
Converts an entity to an Atom entry object.void
updateEntity(java.lang.Object entity)
Updates an entity.
-
-
-
Field Detail
-
WCF_DATASERVICES_METADATA_NAMESPACE
public static final java.lang.String WCF_DATASERVICES_METADATA_NAMESPACE
WCF data services metadata namespace.- See Also:
- Constant Field Values
-
WCF_DATASERVICES_NAMESPACE
public static final java.lang.String WCF_DATASERVICES_NAMESPACE
WCF data services namespace.- See Also:
- Constant Field Values
-
WCF_DATASERVICES_SCHEME_NAMESPACE
public static final java.lang.String WCF_DATASERVICES_SCHEME_NAMESPACE
WCF data services scheme namespace.- See Also:
- Constant Field Values
-
-
Method Detail
-
addEntity
public void addEntity(java.lang.String entitySetName, java.lang.Object entity) throws java.lang.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:
java.lang.Exception
-
addLink
public void addLink(java.lang.Object source, java.lang.String sourceProperty, java.lang.Object target) throws java.lang.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:
java.lang.Exception
-
createQuery
public <T> Query<T> createQuery(java.lang.String subpath, java.lang.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 org.restlet.resource.ClientResource createResource(org.restlet.data.Reference reference)
Returns an instance ofClientResource
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 org.restlet.resource.ClientResource createResource(java.lang.String relativePath)
Returns an instance ofClientResource
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(java.lang.Object entity) throws org.restlet.resource.ResourceException
Deletes an entity.- Parameters:
entity
- The entity to delete- Throws:
org.restlet.resource.ResourceException
-
deleteEntity
public void deleteEntity(java.lang.String entitySubpath) throws org.restlet.resource.ResourceException
Deletes an entity.- Parameters:
entitySubpath
- The path of the entity to delete- Throws:
org.restlet.resource.ResourceException
-
deleteLink
public void deleteLink(java.lang.Object source, java.lang.String sourceProperty, java.lang.Object target) throws org.restlet.resource.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:
org.restlet.resource.ResourceException
-
getClientVersion
public java.lang.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 org.restlet.data.ChallengeResponse getCredentials()
Returns the credentials used to authenticate requests.- Returns:
- The credentials used to authenticate requests.
-
getLatestRequest
public org.restlet.Request getLatestRequest()
Returns the latest request sent to the service.- Returns:
- The latest request sent to the service.
-
getLatestResponse
public org.restlet.Response getLatestResponse()
Returns the response to the latest request.- Returns:
- The response to the latest request.
-
getMaxClientVersion
public java.lang.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 java.lang.Object getMetadata()
Returns the metadata document related to the current service.- Returns:
- The metadata document related to the current service.
-
getServerVersion
public java.lang.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 org.restlet.data.Reference getServiceRef()
Returns the reference to the WCF service.- Returns:
- The reference to the WCF service.
-
getValue
public org.restlet.representation.Representation getValue(java.lang.Object entity) throws org.restlet.resource.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:
org.restlet.resource.ResourceException
-
getValue
public org.restlet.representation.Representation getValue(java.lang.Object entity, java.util.List<org.restlet.data.Preference<org.restlet.data.MediaType>> acceptedMediaTypes) throws org.restlet.resource.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:
org.restlet.resource.ResourceException
-
getValue
public org.restlet.representation.Representation getValue(java.lang.Object entity, org.restlet.data.MediaType mediaType) throws org.restlet.resource.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:
org.restlet.resource.ResourceException
-
getValueRef
public org.restlet.data.Reference getValueRef(java.lang.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 org.restlet.representation.Representation invokeComplex(java.lang.String service, org.restlet.util.Series<org.restlet.data.Parameter> parameters) throws org.restlet.resource.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:
org.restlet.resource.ResourceException
- Thrown when the service call is not successfull.- See Also:
- Service Operations
-
invokeSimple
public java.lang.String invokeSimple(java.lang.String service, org.restlet.util.Series<org.restlet.data.Parameter> parameters) throws org.restlet.resource.ResourceException, java.lang.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:
org.restlet.resource.ResourceException
- Thrown when the service call is not successfull.java.lang.Exception
- See Also:
- Service Operations
-
loadProperty
public void loadProperty(java.lang.Object entity, java.lang.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(java.lang.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(org.restlet.data.ChallengeResponse credentials)
Sets the credentials used to authenticate requests.- Parameters:
credentials
- The credentials used to authenticate requests.
-
setLatestRequest
public void setLatestRequest(org.restlet.Request latestRequest)
Sets the latest request sent to the service.- Parameters:
latestRequest
- The latest request sent to the service.
-
setLatestResponse
public void setLatestResponse(org.restlet.Response latestResponse)
Sets the response to the latest request.- Parameters:
latestResponse
- The response to the latest request.
-
setLink
public void setLink(java.lang.Object source, java.lang.String sourceProperty, java.lang.Object target) throws java.lang.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:
java.lang.Exception
-
setMaxClientVersion
public void setMaxClientVersion(java.lang.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(java.lang.Object entity, org.restlet.representation.Representation blob) throws org.restlet.resource.ResourceException
Sets the value of the given media entry link.- Parameters:
entity
- The media entry link which value is to be updatedblob
- The new representation.- Throws:
org.restlet.resource.ResourceException
-
toEntry
public Entry toEntry(java.lang.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(java.lang.Object entity) throws java.lang.Exception
Updates an entity.- Parameters:
entity
- The entity to put.- Throws:
java.lang.Exception
-
-