java.lang.Object
org.apache.jena.arq.querybuilder.Converters
A collection of static methods to convert from Objects to various types used
in Query and Update construction.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.jena.graph.Node
checkVar
(org.apache.jena.graph.Node n) Converts any Node_Variable nodes into Var nodes.static List<org.apache.jena.sparql.core.TriplePath>
makeCollectionTriplePaths
(Object n, org.apache.jena.shared.PrefixMapping prefixMapping) Create an RDF collection from a collection of objects as per http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#collections.static List<org.apache.jena.graph.Triple>
makeCollectionTriples
(Object collection, org.apache.jena.shared.PrefixMapping prefixMapping) Create an RDF collection from a collection of objects as per http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#collectionsstatic org.apache.jena.graph.Node
Creates a literal from an object.static org.apache.jena.graph.Node
makeLiteral
(String value, String typeUri) Creates a literal from the value and type URI.static org.apache.jena.graph.Node
Makes a node from an object while using the associated prefix mapping.static Object
makeNodeOrPath
(Object o, org.apache.jena.shared.PrefixMapping pMapping) Creates a Path or Node as appropriate.static List<org.apache.jena.sparql.core.TriplePath>
makeTriplePaths
(Object s, Object p, Object o, org.apache.jena.shared.PrefixMapping prefixMapping) Creates a collection ofTriplePath
s from thes, p, o
.static List<org.apache.jena.graph.Triple>
makeTriples
(Object s, Object p, Object o, org.apache.jena.shared.PrefixMapping prefixMapping) Creates a collection ofTriple
s from thes, p, o
.static Collection<org.apache.jena.graph.Node>
makeValueNodes
(Iterator<?> iter, org.apache.jena.shared.PrefixMapping prefixMapping) Creates a collection of nodes from an iterator of Objects.static org.apache.jena.sparql.core.Var
Makes a Var from an object.static String
A convenience method to quote a string.
-
Method Details
-
checkVar
public static org.apache.jena.graph.Node checkVar(org.apache.jena.graph.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
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:
IllegalArgumentException
- if object type is not registered.
-
makeLiteral
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 ifJenaParameters.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 literaltypeUri
- the type URI for the literal node.- Returns:
- the literal node.
- Throws:
org.apache.jena.datatypes.DatatypeFormatException
- on errors noted above
- 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
-
makeVar
public static org.apache.jena.sparql.core.Var makeVar(Object o) throws org.apache.jena.sparql.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:
org.apache.jena.sparql.ARQInternalErrorException
-
quoted
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.
-