use of jena.cmd.CmdException in project jena by apache.
the class rsparql method exec.
@Override
protected void exec() {
Query query = modQuery.getQuery();
try {
String serviceURL = modRemote.getServiceURL();
QueryExecution qe = QueryExecutionFactory.sparqlService(serviceURL, query);
if (modRemote.usePost())
HttpQuery.urlLimit = 0;
QueryExecUtils.executeQuery(query, qe, modResults.getResultsFormat());
} catch (QueryExceptionHTTP ex) {
throw new CmdException("HTTP Exeception", ex);
} catch (Exception ex) {
System.out.flush();
ex.printStackTrace(System.err);
}
}
use of jena.cmd.CmdException in project jena by apache.
the class tdbloader method exec.
@Override
protected void exec() {
if (isVerbose()) {
System.out.println("Java maximum memory: " + Runtime.getRuntime().maxMemory());
System.out.println(ARQ.getContext());
}
if (isVerbose())
showProgress = true;
if (isQuiet())
showProgress = false;
if (super.contains(argStats)) {
if (!hasValueOfTrue(argStats) && !hasValueOfFalse(argStats))
throw new CmdException("Not a boolean value: " + getValue(argStats));
generateStats = super.hasValueOfTrue(argStats);
}
if (super.contains(argNoStats))
generateStats = false;
List<String> urls = getPositional();
if (urls.size() == 0)
urls.add("-");
if (graphName == null) {
loadQuads(urls);
return;
}
for (String url : urls) {
Lang lang = RDFLanguages.filenameToLang(url);
if (lang != null && RDFLanguages.isQuads(lang)) {
System.err.println("Warning: Quads format given - only the default graph is loaded into the graph for --graph");
break;
}
}
loadNamedGraph(urls);
}
use of jena.cmd.CmdException in project jena by apache.
the class spatialindexer method processModulesAndArgs.
@Override
protected void processModulesAndArgs() {
super.processModulesAndArgs();
// Two forms : with and without arg.
// Maximises similarity with other tools.
String file;
if (super.contains(assemblerDescDecl)) {
if (getValues(assemblerDescDecl).size() != 1)
throw new CmdException("Multiple assembler descriptions given");
if (getPositional().size() != 0)
throw new CmdException("Additional assembler descriptions given");
file = getValue(assemblerDescDecl);
} else {
if (getNumPositional() != 1)
throw new CmdException("Multiple assembler descriptions given");
file = getPositionalArg(0);
}
if (file == null)
throw new CmdException("No dataset specified");
// Assumes a single test daatset description in the assembler file.
Dataset ds = SpatialDatasetFactory.create(file);
if (ds == null)
throw new CmdException("No dataset description found");
// get index.
dataset = (DatasetGraphSpatial) (ds.asDatasetGraph());
spatialIndex = dataset.getSpatialIndex();
if (spatialIndex == null)
throw new CmdException("Dataset has no spatial index");
context = new SpatialIndexContext(spatialIndex);
}
use of jena.cmd.CmdException in project jena by apache.
the class load method execUpdate.
@Override
protected void execUpdate(DatasetGraph graphStore) {
if (loadFiles.size() == 0)
throw new CmdException("Nothing to do");
UpdateRequest req = new UpdateRequest();
for (String filename : loadFiles) {
UpdateLoad loadReq = new UpdateLoad(filename, graphName);
req.add(loadReq);
}
if (true) {
// Need a better way
monitor(graphStore.getDefaultGraph());
for (Iterator<Node> iter = graphStore.listGraphNodes(); iter.hasNext(); ) {
Graph g = graphStore.getGraph(iter.next());
monitor(g);
}
}
UpdateExecutionFactory.create(req, graphStore).execute();
if (dump) {
IndentedWriter out = IndentedWriter.stdout;
SSE.write(graphStore);
out.flush();
}
}
use of jena.cmd.CmdException in project jena by apache.
the class qexpr method main2.
public static void main2(String... argv) {
CmdLineArgs cl = new CmdLineArgs(argv);
ArgDecl helpDecl = new ArgDecl(ArgDecl.NoValue, "h", "help");
cl.add(helpDecl);
ArgDecl verboseDecl = new ArgDecl(ArgDecl.NoValue, "v", "verbose");
cl.add(verboseDecl);
ArgDecl versionDecl = new ArgDecl(ArgDecl.NoValue, "ver", "version", "V");
cl.add(versionDecl);
ArgDecl quietDecl = new ArgDecl(ArgDecl.NoValue, "q", "quiet");
cl.add(quietDecl);
ArgDecl reduceDecl = new ArgDecl(ArgDecl.NoValue, "reduce", "fold", "simplify");
cl.add(reduceDecl);
ArgDecl strictDecl = new ArgDecl(ArgDecl.NoValue, "strict");
cl.add(strictDecl);
ArgDecl printDecl = new ArgDecl(ArgDecl.HasValue, "print");
cl.add(printDecl);
try {
cl.process();
} catch (IllegalArgumentException ex) {
System.err.println(ex.getMessage());
usage(System.err);
throw new CmdException();
}
if (cl.contains(helpDecl)) {
usage();
throw new TerminationException(0);
}
if (cl.contains(versionDecl)) {
System.out.println("ARQ Version: " + ARQ.VERSION + " (Jena: " + Jena.VERSION + ")");
throw new TerminationException(0);
}
// ==== General things
boolean verbose = cl.contains(verboseDecl);
boolean quiet = cl.contains(quietDecl);
if (cl.contains(strictDecl))
ARQ.setStrictMode();
boolean actionCopySubstitute = cl.contains(reduceDecl);
boolean actionPrintPrefix = false;
boolean actionPrintSPARQL = false;
boolean actionPrint = cl.contains(printDecl);
for (String v : cl.getValues(printDecl)) {
if (v.equalsIgnoreCase("prefix") || v.equalsIgnoreCase("op")) {
actionPrintPrefix = true;
} else if (v.equalsIgnoreCase("expr")) {
actionPrintSPARQL = true;
} else {
System.err.println("Unknown print form: " + v);
throw new TerminationException(0);
}
}
for (int i = 0; i < cl.getNumPositional(); i++) {
String exprStr = cl.getPositionalArg(i);
exprStr = cl.indirect(exprStr);
try {
PrefixMapping pmap = PrefixMapping.Factory.create();
pmap.setNsPrefixes(ARQConstants.getGlobalPrefixMap());
pmap.setNsPrefix("", "http://example/");
pmap.setNsPrefix("ex", "http://example/ns#");
// Node n = asNode() ;
// return makeNode(n) ;
Expr expr = ExprUtils.parse(exprStr, pmap);
if (verbose)
System.out.print(expr.toString() + " => ");
if (actionPrint) {
if (actionPrintSPARQL)
System.out.println(ExprUtils.fmtSPARQL(expr));
if (actionPrintPrefix)
WriterSSE.out(IndentedWriter.stdout, expr, new Prologue(pmap));
continue;
}
try {
if (actionCopySubstitute) {
Expr e = ExprLib.foldConstants(expr);
System.out.println(e);
} else {
// Default action
ARQ.getContext().set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
FunctionEnv env = new ExecutionContext(ARQ.getContext(), null, null, null);
NodeValue r = expr.eval(null, env);
//System.out.println(r.asQuotedString()) ;
Node n = r.asNode();
String s = NodeFmtLib.displayStr(n);
System.out.println(s);
}
} catch (ExprEvalException ex) {
System.out.println("Exception: " + ex.getMessage());
throw new TerminationException(2);
}
} catch (QueryParseException ex) {
System.err.println("Parse error: " + ex.getMessage());
throw new TerminationException(2);
}
}
}
Aggregations