org.universAAL.support.utils.service.low
Class Request

Package class diagram package Request
java.lang.Object
  extended by org.universAAL.middleware.rdf.Resource
      extended by org.universAAL.middleware.rdf.FinalizedResource
          extended by org.universAAL.middleware.service.ServiceRequest
              extended by org.universAAL.support.utils.service.low.Request
All Implemented Interfaces:
Matchable, Request, Requirement

public class Request
extends ServiceRequest

A helper class that extends ServiceRequest and adds utility methods to build requests. You can still use this class like ServiceRequest. It just adds some more methods that allow you to create requests in a simple argument-oriented way.

Example: Calling a Lighting service that controls LightSources of type ElectricLight, find the light with URI "desiredURI" and turn it off (set to brightness 0)

Request req=new Request(new Lighting(null));

req.put(new String[]{Lighting.PROP_CONTROLS,LightSource.PROP_HAS_TYPE}, new Typematch(ElectricLight.MY_URI));

req.put(new String[]{Lighting.PROP_CONTROLS}, new Variable(new LightSource(desiredURI)));

req.put(new String[]{Lighting.PROP_CONTROLS,LightSource.PROP_SOURCE_BRIGHTNESS }, new Change(new Integer(0)));

caller.call(req);

This is not necessarily faster nor better than the usual way of doing it with ServiceRequest. It's just an alternative way that might help those less familiarized with universAAL.

Author:
alfiva

Field Summary
static String MY_NAMESPACE
          Default namespace.
 
Fields inherited from class org.universAAL.middleware.service.ServiceRequest
MY_URI, PROP_AGGREGATING_FILTER, PROP_REQUESTED_SERVICE, PROP_REQUIRED_PROCESS_RESULT, PROP_uAAL_SERVICE_CALLER
 
Fields inherited from class org.universAAL.middleware.rdf.Resource
ANON_URI_PREFIX, blockAddingTypes, isXMLLiteral, ns_delim_index, PROP_RDF_FIRST, PROP_RDF_REST, PROP_RDF_TYPE, PROP_RDFS_COMMENT, PROP_RDFS_LABEL, PROP_SERIALIZATION_FULL, PROP_SERIALIZATION_OPTIONAL, PROP_SERIALIZATION_REDUCED, PROP_SERIALIZATION_UNDEFINED, PROP_uAAL_INVOLVED_HUMAN_USER, props, RDF_EMPTY_LIST, RDF_NAMESPACE, RDFS_NAMESPACE, TYPE_RDF_LIST, TYPE_RDFS_CLASS, uAAL_NAMESPACE_PREFIX, uAAL_SERVICE_NAMESPACE, uAAL_VOCABULARY_NAMESPACE, uri
 
Constructor Summary
Request(Service requestedServiceRoot)
          Use this helper class to create a ServiceRequest that is easy to use.
 
Method Summary
protected  Hashtable getInput()
          I have to put this because of all service refactoring stuff.
 void put(Path branch, Add leaf)
          Equivalent to put(String[] branch, Add leaf).
 void put(Path branch, Change leaf)
          Equivalent to put(String[] branch, Change leaf).
 void put(Path branch, Output leaf)
          Equivalent to put(String[] branch, Output leaf).
 void put(Path branch, Remove leaf)
          Equivalent to put(String[] branch, Remove leaf).
 void put(Path branch, Typematch leaf)
          Equivalent to put(String[] branch, Typematch leaf).
 void put(Path branch, Variable leaf)
          Equivalent to put(Path branch, Variable leaf).
 void put(String[] branch, Add leaf)
          Use this helper method to declare an argument over a Request, specifying that you want to add, in the given branch of properties, the value instance expressed with Add argument.
 void put(String[] branch, Change leaf)
          Use this helper method to declare an argument over a Request, specifying that you want to change, at the given branch of properties, an old value with a new one, an instance expressed with Change argument.
 void put(String[] branch, Output leaf)
          Use this helper method to declare an argument over a Request, specifying that you want the kind of output specified by the given branch of properties, and you want it to be put in the ServiceResponse under the ID specified with the Output argument.
 void put(String[] branch, Remove leaf)
          Use this helper method to declare an argument over a Request, specifying that you want to remove, from the given branch of properties, the value instance expressed with Remove argument.
 void put(String[] branch, Typematch leaf)
          Use this helper method to declare an argument over a Request, specifying that the requested service must have, in the given branch of properties, an instance of the same type expressed with Typematch argument.
 void put(String[] branch, Variable leaf)
          Use this helper method to declare an argument over a Request, specifying that the requested service will receive as variable input, in the given branch of properties, the instance expressed with Variable argument.
static Object[] recoverOutputs(ServiceResponse sr, Output output)
          Equivalent to recoverOutputs(ServiceResponse sr, String outputURI).
static Object[] recoverOutputs(ServiceResponse sr, String outputURI)
          Use this helper method when you have called a ServiceRequest (or a Request) and you want to get an array containing all the outputs returned.
 
Methods inherited from class org.universAAL.middleware.service.ServiceRequest
acceptsRandomSelection, addAddEffect, addAggregatingFilter, addAggregatingOutputBinding, addChangeEffect, addRemoveEffect, addRequiredOutput, addSimpleOutputBinding, addTypeFilter, addValueFilter, getFilters, getOutputAggregations, getPropSerializationType, getRequestedService, getRequiredEffects, getRequiredOutputs, isWellFormed, matches, setProperty
 
Methods inherited from class org.universAAL.middleware.rdf.FinalizedResource
addType, getLocalName, getNamespace, getProperty, getPropertyURIs, getType, getTypes, getURI, hasQualifiedName, isAnon, numberOfProperties
 
Methods inherited from class org.universAAL.middleware.rdf.Resource
addMultiLangProp, asList, asList, asRDFList, changeProperty, copy, deepCopy, equals, generateAnonURI, getDefaultLang, getFilename, getMultiLangProp, getOrConstructLabel, getResource, getResourceComment, getResourceLabel, getStaticFieldValue, hashCode, hasProperty, isAnon, isBlockingAddingTypes, isClosedCollection, isQualifiedName, literal, representsQualifiedURI, serializesAsXMLLiteral, setPropertyPath, setPropertyPath, setPropertyPathFromOffset, setResourceComment, setResourceLabel, toString, toStringRecursive, toStringRecursive, unliteral
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MY_NAMESPACE

public static final String MY_NAMESPACE
Default namespace.

See Also:
Constant Field Values
Constructor Detail

Request

public Request(Service requestedServiceRoot)
Use this helper class to create a ServiceRequest that is easy to use. You can use this Request also as you could use a normal ServiceRequest.

Example: Request req=new Request(new Lighting(null));

Parameters:
requestedServiceRoot - An instance of the Service class that you want to call, created with null URI.
Method Detail

put

public void put(String[] branch,
                Typematch leaf)
Use this helper method to declare an argument over a Request, specifying that the requested service must have, in the given branch of properties, an instance of the same type expressed with Typematch argument.

Example: req.put(new String[]{Lighting.PROP_CONTROLS,LightSource.PROP_HAS_TYPE}, new Typematch(ElectricLight.MY_URI));

Parameters:
branch - The path of properties from the Service root class to the value to be restricted
leaf - The Typematch describing the type of instance expected at the end of the branch

put

public void put(Path branch,
                Typematch leaf)
Equivalent to put(String[] branch, Typematch leaf).

Parameters:
branch - The path of properties from the Service root class to the value to be restricted
leaf - The Typematch describing the type of instance expected at the end of the branch

put

public void put(String[] branch,
                Variable leaf)
Use this helper method to declare an argument over a Request, specifying that the requested service will receive as variable input, in the given branch of properties, the instance expressed with Variable argument.

Example: req.put(new String[]{Lighting.PROP_CONTROLS}, new Variable(new LightSource(exactURI)));

Parameters:
branch - The path of properties from the Service root class to the value to be received as input by the service
leaf - The Variable describing the value that you want to pass as variable input to the service

put

public void put(Path branch,
                Variable leaf)
Equivalent to put(Path branch, Variable leaf).

Parameters:
branch - The path of properties from the Service root class to the value to be received as input by the service
leaf - The Variable describing the value that you want to pass as variable input to the service

put

public void put(String[] branch,
                Output leaf)
Use this helper method to declare an argument over a Request, specifying that you want the kind of output specified by the given branch of properties, and you want it to be put in the ServiceResponse under the ID specified with the Output argument.

Example: req.put(new String[]{Lighting.PROP_CONTROLS}, new Output("http://ontology.igd.fhg.de/LightingConsumer.owl#listOfLamps"));

Parameters:
branch - The path of properties from the Service root class to the output that you want
leaf - The Output describing the URI (the ID) that you will use when dealing with the ServiceResponse

put

public void put(Path branch,
                Output leaf)
Equivalent to put(String[] branch, Output leaf).

Parameters:
branch - The path of properties from the Service root class to the output that you want
leaf - The Output describing the URI (the ID) that you will use when dealing with the ServiceResponse

put

public void put(String[] branch,
                Add leaf)
Use this helper method to declare an argument over a Request, specifying that you want to add, in the given branch of properties, the value instance expressed with Add argument.

Example: req.put(new String[]{Lighting.PROP_CONTROLS}, new Add(new LightSource(addURI)));

Parameters:
branch - The path of properties from the Service root class to the value to be added
leaf - The Add describing the instance to be added at the end of the branch

put

public void put(Path branch,
                Add leaf)
Equivalent to put(String[] branch, Add leaf).

Parameters:
branch - The path of properties from the Service root class to the value to be added
leaf - The Add describing the instance to be added at the end of the branch

put

public void put(String[] branch,
                Remove leaf)
Use this helper method to declare an argument over a Request, specifying that you want to remove, from the given branch of properties, the value instance expressed with Remove argument.

Example: req.put(new String[]{Lighting.PROP_CONTROLS}, new Remove(new LightSource(quitURI)));

Parameters:
branch - The path of properties from the Service root class to the value to be removed
leaf - The Remove describing the instance to be removed at the end of the branch

put

public void put(Path branch,
                Remove leaf)
Equivalent to put(String[] branch, Remove leaf).

Parameters:
branch - The path of properties from the Service root class to the value to be removed
leaf - The Remove describing the instance to be removed at the end of the branch

put

public void put(String[] branch,
                Change leaf)
Use this helper method to declare an argument over a Request, specifying that you want to change, at the given branch of properties, an old value with a new one, an instance expressed with Change argument.

Example: req.put(new String[]{Lighting.PROP_CONTROLS,LightSource.PROP_SOURCE_BRIGHTNESS }, new Change(new Integer(0)));

Parameters:
branch - The path of properties from the Service root class to the value to be changed
leaf - The Change describing the new instance to be put at the end of the branch

put

public void put(Path branch,
                Change leaf)
Equivalent to put(String[] branch, Change leaf).

Parameters:
branch - The path of properties from the Service root class to the value to be changed
leaf - The Change describing the new instance to be put at the end of the branch

recoverOutputs

public static Object[] recoverOutputs(ServiceResponse sr,
                                      Output output)
Equivalent to recoverOutputs(ServiceResponse sr, String outputURI).

Parameters:
sr - The ServiceResponse returned by the .call method
output - The Output you used when building the request
Returns:
An array of Objects that contain all the returned values stored at the given Output URI (the ID). You will have to cast them to the appropriate class yourself, which you know in advance, as you have built the request... Returns null in all other cases (Service errors, no outputs,...)

recoverOutputs

public static Object[] recoverOutputs(ServiceResponse sr,
                                      String outputURI)
Use this helper method when you have called a ServiceRequest (or a Request) and you want to get an array containing all the outputs returned.

Parameters:
sr - The ServiceResponse returned by the .call method
outputURI - The URI (the ID) you used to refer to the output when building the request
Returns:
An array of Objects that contain all the returned values stored at the given Output URI (the ID). You will have to cast them to the appropriate class yourself, which you know in advance, as you have built the request... Returns null in all other cases (Service errors, no outputs,...)

getInput

protected Hashtable getInput()
I have to put this because of all service refactoring stuff.

Returns:
Nothing, null.


Copyright © 2014 universAAL Consortium. All Rights Reserved.