Class QueryWhereTermHandler<V,​C>

  • Type Parameters:
    V - the type of value expected by the handler
    C - the type of context, as defined by the owning QueryWhereHandler

    public abstract class QueryWhereTermHandler<V,​C>
    extends Object
    Handles a term found in an oslc.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 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 an oslc.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 the oslc.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 an oslc.where expression.

        The type argument defines the type of value the handler expects to receive. When processing a oslc.where expression, the QueryWhereHandler 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 or Float
        • Date
        • URI
        • An array of one of the types above
        When a handler is registered for a wildcard, the type used may be 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, using URI[] 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 null
        IllegalArgumentException - 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:

        • String
        • Boolean
        • A number: Long, Integer, Double or Float
        • Date
        • URI
        Type Parameters:
        T - the type of the converted value
        Parameters:
        property - the URI of the OSLC property, as provided in handle(String, Operator, Object, Object)
        value - the term value
        type - the type to convert to
        Returns:
        the converted value
        Throws:
        NullPointerException - if property, value or type is null
        IllegalArgumentException - if the given type is not supported by the handler
        WebApplicationException - 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:

        • String
        • Boolean
        • A number: Long, Integer, Double or Float
        • Date
        • URI
        Type Parameters:
        T - the type of the converted value
        Parameters:
        property - the URI of the OSLC property, as provided in handle(String, Operator, Object, Object)
        values - the term values
        type - the type to convert to
        Returns:
        the converted values
        Throws:
        NullPointerException - if property, values or type is null
        IllegalArgumentException - if the given type is not supported by the handler
        WebApplicationException - 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 an oslc.where expression is visited, when its OSLC property is the one for which this handler was registered in the QueryWhereHandler.

        The property argument is the URI of the OSLC property used in the oslc.where term. It may also be a wildcard ("*").

        The operator argument is the type of operation of the oslc.where term. Note that, as a special case, the "in" term operator is represented in this handler with ComparisonTerm.Operator.EQUALS.

        The value argument is the right operand of the oslc.where term, converted to the expected type, as stated in the constructor of this handler.

        The context argument is what was provided to the handle 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 operator
        value - the term value
        context - the context of the handler