Class QueryWhereTermHandler<V,C>
- java.lang.Object
-
- com.sodius.oslc.server.process.query.QueryWhereTermHandler<V,C>
-
- Type Parameters:
V
- the type of value expected by the handlerC
- the type of context, as defined by the owningQueryWhereHandler
public abstract class QueryWhereTermHandler<V,C> extends Object
Handles a term found in anoslc.where
expression.A handler is registered in a
QueryWhereHandler
for a given OSLC property, namespace or wildcard.The handler is notified when a term of an
oslc.where
expression is visited and the OSLC property of this term is the one for which the handler was registered.- Since:
- 3.6.0
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
QueryWhereTermHandler(String propertyDefinition, Class<V> type)
Creates a a term handler for a given OSLC property, namespace or wildcard.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <T> T
convertPropertyValue(String property, Value value, Class<T> type)
Converts the given value to the desired type.static <T> T[]
convertPropertyValues(String property, Value[] values, Class<T[]> type)
Converts the given array of values to the desired type.protected abstract void
handle(String property, ComparisonTerm.Operator operator, V value, C context)
Notifies a term of anoslc.where
expression is visited, when its OSLC property is the one for which this handler was registered in theQueryWhereHandler
.
-
-
-
Constructor Detail
-
QueryWhereTermHandler
protected QueryWhereTermHandler(String propertyDefinition, Class<V> type)
Creates a a term handler for a given OSLC property, namespace or wildcard.The
propertyDefinition
argument is the URI of an OSLC property, e.g."http://purl.org/dc/terms/title"
, that can be found in anoslc.where
expression and for which the given handler is to call. It may otherwise be a namespace, e.g."http://example.com/namespace/custom/"
. Handlers are recommended to be registered for explicit OSLC properties. Registering a handler for a namespace is to use when such namespace is for defining custom properties, as found in the underlying application, when the actual list of properties is not known. In this case, the handler is notified of the actual property used in theoslc.where
expression and can process the custom property name dynamically. Last, it can also be a wildcard ("*"
), to match the wildcard that may be found in anoslc.where
expression.The
type
argument defines the type of value the handler expects to receive. When processing aoslc.where
expression, theQueryWhereHandler
converts the string value found in the expression to the desired type of value. The supported types of values are:Value
(no conversion performed)String
Boolean
- A number:
Long
,Integer
,Double
orFloat
Date
URI
- An array of one of the types above
Value
, so that the handler can process any type of value. On the other hand, if the handler is for example known to support only URIs with a wildcard, usingURI[]
is handy to simplify the processing.Using an array type is recommended whenever it makes sense for the given property. It should not be restricted to multi-valued properties in the application. It is what enables using a
"in"
operator to retain resources whose value is one of the values in this list.- Parameters:
propertyDefinition
- the URI of an OSLC property, e.g."http://purl.org/dc/terms/title"
, namespace or wildcard.type
- the type of value expected by the handler- Throws:
NullPointerException
- if propertyDefinition or type is nullIllegalArgumentException
- if the given type is not supported by the handler
-
-
Method Detail
-
convertPropertyValue
public static <T> T convertPropertyValue(String property, Value value, Class<T> type)
Converts the given value to the desired type.A handler is usually registered for a specific type, in which case the conversion of the value to the desired type is realized by the framework. This method is useful though when registering a handler for a given namespace, in which case the value is not converted by the framework and the handler may have to do the conversion on its own when discovering the actual property used for that namespace.
The supported types for the conversion are:
- Type Parameters:
T
- the type of the converted value- Parameters:
property
- the URI of the OSLC property, as provided inhandle(String, Operator, Object, Object)
value
- the term valuetype
- the type to convert to- Returns:
- the converted value
- Throws:
NullPointerException
- if property, value or type is nullIllegalArgumentException
- if the given type is not supported by the handlerWebApplicationException
- if the value cannot be converted to the desired type
-
convertPropertyValues
public static <T> T[] convertPropertyValues(String property, Value[] values, Class<T[]> type)
Converts the given array of values to the desired type.A handler is usually registered for a specific type, in which case the conversion of the value to the desired type is realized by the framework. This method is useful though when registering a handler for a given namespace, in which case the value is not converted by the framework and the handler may have to do the conversion on its own when discovering the actual property used for that namespace.
The supported types for the conversion are:
- Type Parameters:
T
- the type of the converted value- Parameters:
property
- the URI of the OSLC property, as provided inhandle(String, Operator, Object, Object)
values
- the term valuestype
- the type to convert to- Returns:
- the converted values
- Throws:
NullPointerException
- if property, values or type is nullIllegalArgumentException
- if the given type is not supported by the handlerWebApplicationException
- if the values cannot be converted to the desired type
-
handle
protected abstract void handle(String property, ComparisonTerm.Operator operator, V value, C context)
Notifies a term of anoslc.where
expression is visited, when its OSLC property is the one for which this handler was registered in theQueryWhereHandler
.The
property
argument is the URI of the OSLC property used in theoslc.where
term. It may also be a wildcard ("*"
).The
operator
argument is the type of operation of theoslc.where
term. Note that, as a special case, the"in"
term operator is represented in this handler withComparisonTerm.Operator.EQUALS
.The
value
argument is the right operand of theoslc.where
term, converted to the expected type, as stated in the constructor of this handler.The
context
argument is what was provided to thehandle
method. It is whatever provides information about the underlying application to this term handler and what may receive its processing output.- Parameters:
property
- the URI of the OSLC property, or a wildcard ("*"
)operator
- the term operatorvalue
- the term valuecontext
- the context of the handler
-
-