Class Converters


  • public class Converters
    extends java.lang.Object
    A collection of static methods to convert from Objects to various types used in Query and Update construction.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Node checkVar​(Node n)
      Converts any Node_Variable nodes into Var nodes.
      static Node makeLiteral​(java.lang.Object o)
      Creates a literal from an object.
      static Node makeLiteral​(java.lang.String value, java.lang.String typeUri)
      Creates a literal from the value and type URI.
      static Node makeNode​(java.lang.Object o, PrefixMapping pMapping)
      Makes a node from an object while using the associated prefix mapping.
      static java.lang.Object makeNodeOrPath​(java.lang.Object o, PrefixMapping pMapping)
      Creates a Path or Node as appropriate.
      static java.util.Collection<Node> makeValueNodes​(java.util.Iterator<?> iter, PrefixMapping prefixMapping)
      Creates a collection of nodes from an iterator of Objects.
      static Var makeVar​(java.lang.Object o)
      Makes a Var from an object.
      static java.lang.String quoted​(java.lang.String q)
      A convenience method to quote a string.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • checkVar

        public static Node checkVar​(Node n)
        Converts any Node_Variable nodes into Var nodes.
        Parameters:
        n - the node to check
        Returns:
        the node n or a new Var if n is an instance of Node_Variable
      • makeLiteral

        public static Node makeLiteral​(java.lang.Object o)
        Creates a literal from an object. If the object type is registered with the TypeMapper the associated literal string is returned. If the object is not registered an IllegalArgumentException is thrown.
        Parameters:
        o - the object to convert.
        Returns:
        the literal node.
        Throws:
        java.lang.IllegalArgumentException - if object type is not registered.
      • makeLiteral

        public static Node makeLiteral​(java.lang.String value,
                                       java.lang.String typeUri)
        Creates a literal from the value and type URI. There are several possible outcomes:
        • If the URI is registered with TypeMapper and the value is the proper lexical form for the type, the registered TypeMapper is used and calling getLiteralValue() on the returned node will return a proper object.
        • If the URI is unregistered a Datatype is created but not registered with the TypeMapper. The resulting node is properly constructed for used in output serialization, queries, or updates. Calling getLiteralValue() on the returned node will throw DatatypeFormatException. Note that if JenaParameters.enableEagerLiteralValidation is true the DatatypeFormatException will be thrown by this method.
        • If the URI is registered but the value is not a proper lexical form a DatatypeFormatException will be thrown by this method.
        Parameters:
        value - the value for the literal
        typeUri - the type URI for the literal node.
        Returns:
        the literal node.
        Throws:
        DatatypeFormatException - on errors noted above
      • makeNode

        public static Node makeNode​(java.lang.Object o,
                                    PrefixMapping pMapping)
        Makes a node from an object while using the associated prefix mapping.
        • Will return Node.ANY if object is null.
        • Will return the enclosed Node from a FrontsNode
        • Will return the object if it is a Node.
        • Will call NodeFactoryExtra.parseNode() using the currently defined prefixes if the object is a String
        • Will call makeLiteral() to create a literal representation if the parseNode() fails or for any other object type.
        Parameters:
        o - The object to convert (may be null).
        pMapping - The prefix mapping to use for prefix resolution.
        Returns:
        The Node value.
        See Also:
        makeLiteral(Object)
      • makeNodeOrPath

        public static java.lang.Object makeNodeOrPath​(java.lang.Object o,
                                                      PrefixMapping pMapping)
        Creates a Path or Node as appropriate.
        • Will return Node.ANY if object is null.
        • Will return the object if it is a Path
        • Will return the enclosed Node from a FrontsNode
        • Will return the object if it is a Node.
        • Will call PathParser.parse() using the prefix mapping if the object is a String
        • Will call NodeFactoryExtra.parseNode() using the currently defined prefixes if the object is a String and the PathParser.parse() fails.
        • Will call makeLiteral() to create a literal representation if the parseNode() fails or for any other object type.
        Parameters:
        o - the object that should be interpreted as a path or a node.
        pMapping - the prefix mapping to resolve path or node with
        Returns:
        the Path or Node
        See Also:
        makeLiteral(Object)
      • makeVar

        public static Var makeVar​(java.lang.Object o)
                           throws ARQInternalErrorException
        Makes a Var from an object.
        • Will return Var.ANON if object is null.
        • Will return null if the object is "*" or Node_RuleVariable.WILD
        • Will return the object if it is a Var
        • Will return resolve FrontsNode to Node and then resolve to Var
        • Will return resolve Node if the Node implements Node_Variable, otherwise throws an NotAVariableException (instance of ARQInternalErrorException)
        • Will return ?x if object is "?x"
        • Will return ?x if object is "x"
        • Will return the enclosed Var of a ExprVar
        • For all other objects will return the "?" prefixed to the toString() value.
        Parameters:
        o - The object to convert.
        Returns:
        the Var value.
        Throws:
        ARQInternalErrorException
      • quoted

        public static java.lang.String quoted​(java.lang.String q)
        A convenience method to quote a string.
        Parameters:
        q - the string to quote. Will use single quotes if there are no single quotes in the string or if the double quote is before the single quote in the string. Will use double quote otherwise.
        Returns:
        the quoted string.
      • makeValueNodes

        public static java.util.Collection<Node> makeValueNodes​(java.util.Iterator<?> iter,
                                                                PrefixMapping prefixMapping)
        Creates a collection of nodes from an iterator of Objects.
        Parameters:
        iter - the iterator of objects, may be null or empty.
        prefixMapping - the PrefixMapping to use when nodes are created.
        Returns:
        a Collection of nodes or null if iter is null or empty.