use of org.apache.jena.sdb.assembler.CommandAssemblerException in project jena by apache.
the class CmdDescAssembler method open.
/* This SPARQL query will process arguments
PREFIX acmd: <http://jena.hpl.hp.com/2007/sdb#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX list: <http://jena.apache.org/ARQ/list#>
SELECT ?name ?value
{ ?x rdf:type acmd:Cmd ;
acmd:args ?args .
{ ?args list:member [ acmd:name ?name ; acmd:value ?value ] }
UNION
{ ?args list:member ?e .
OPTIONAL { ?e acmd:name ?name }
FILTER (!bound(?name)) .
?e acmd:value ?value .
}
UNION
{ ?args list:member ?value . FILTER isLiteral(?value) }
}
*/
@Override
public Object open(Assembler a, Resource root, Mode mode) {
CmdDesc cd = new CmdDesc();
String main = GraphUtils.getStringValue(root, AssemblerVocab.pMain);
if (main == null)
main = GraphUtils.getStringValue(root, AssemblerVocab.pClassname);
cd.setCmd(main);
Resource x = GraphUtils.getResourceValue(root, AssemblerVocab.pArgs);
if (x != null) {
for (; !x.equals(RDF.nil); ) {
RDFNode e = x.getRequiredProperty(RDF.first).getObject();
// Move to next list item
x = x.getRequiredProperty(RDF.rest).getResource();
// Either : a literal or a named pair.
if (e.isLiteral()) {
cd.addPosn(((Literal) e).getString());
continue;
}
Resource entry = (Resource) e;
String name = GraphUtils.getStringValue(entry, AssemblerVocab.pArgName);
String value = GraphUtils.getStringValue(entry, AssemblerVocab.pArgValue);
if (value == null)
throw new CommandAssemblerException(entry, "Strange entry: " + entry);
if (name != null)
cd.addNamedArg(name, value);
else
cd.addPosn(value);
}
}
return cd;
}
Aggregations