use of jena.cmd.CmdException in project jena by apache.
the class textindexdump 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);
}
textIndex = (TextIndex) AssemblerUtils.build(file, TextVocab.textIndex);
}
use of jena.cmd.CmdException in project jena by apache.
the class query method queryExec.
protected void queryExec(boolean timed, ResultsFormat fmt) {
try {
Query query = modQuery.getQuery();
if (isVerbose()) {
IndentedWriter out = new IndentedWriter(System.out, true);
query.serialize(out);
out.flush();
System.out.println();
}
if (isQuiet())
LogCtl.setError(SysRIOT.riotLoggerName);
Dataset dataset = getDataset(query);
// The default policy is to create an empty one - convenience for VALUES and BIND providing the data.
if (dataset == null && !query.hasDatasetDescription()) {
System.err.println("Dataset not specified in query nor provided on command line.");
throw new TerminationException(1);
}
Transactional transactional = (dataset != null && dataset.supportsTransactionAbort()) ? dataset : new TransactionalNull();
Txn.executeRead(transactional, () -> {
modTime.startTimer();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
try {
QueryExecUtils.executeQuery(query, qe, fmt);
} catch (QueryCancelledException ex) {
System.out.flush();
System.err.println("Query timed out");
}
long time = modTime.endTimer();
if (timed) {
totalTime += time;
System.err.println("Time: " + modTime.timeStr(time) + " sec");
}
} catch (ResultSetException ex) {
System.err.println(ex.getMessage());
ex.printStackTrace(System.err);
} catch (QueryException qEx) {
// System.err.println(qEx.getMessage()) ;
throw new CmdException("Query Exeception", qEx);
}
});
} catch (ARQInternalErrorException intEx) {
System.err.println(intEx.getMessage());
if (intEx.getCause() != null) {
System.err.println("Cause:");
intEx.getCause().printStackTrace(System.err);
System.err.println();
}
intEx.printStackTrace(System.err);
} catch (JenaException | CmdException ex) {
throw ex;
} catch (Exception ex) {
throw new CmdException("Exception", ex);
}
}
use of jena.cmd.CmdException in project jena by apache.
the class ModLangOutput method processArgs.
@Override
public void processArgs(CmdArgModule cmdLine) {
if (cmdLine.contains(argPretty)) {
String langName = cmdLine.getValue(argPretty);
Lang lang = RDFLanguages.nameToLang(langName);
if (lang == null)
throw new CmdException("Not recognized as an RDF language : '" + langName + "'");
formattedOutput = RDFWriterRegistry.defaultSerialization(lang);
if (formattedOutput == null) {
System.err.println("Language '" + lang.getLabel() + "' not registered.");
printRegistered(System.err);
throw new CmdException("No output set: '" + langName + "'");
}
}
if (cmdLine.contains(argStream)) {
String langName = cmdLine.getValue(argStream);
Lang lang = RDFLanguages.nameToLang(langName);
if (lang == null)
throw new CmdException("Not recognized as an RDF language : '" + langName + "'");
streamOutput = StreamRDFWriter.defaultSerialization(lang);
if (streamOutput == null) {
System.err.println("Language '" + lang.getLabel() + "' not registered for streaming.");
printRegistered(System.err);
throw new CmdException("No output set: '" + langName + "'");
}
}
if (cmdLine.contains(argOutput)) {
String langName = cmdLine.getValue(argOutput);
Lang lang = RDFLanguages.nameToLang(langName);
if (lang == null)
throw new CmdException("Not recognized as an RDF language : '" + langName + "'");
if (StreamRDFWriter.registered(lang)) {
streamOutput = StreamRDFWriter.defaultSerialization(lang);
} else {
formattedOutput = RDFWriterRegistry.defaultSerialization(lang);
if (formattedOutput == null) {
System.err.println("Language '" + lang.getLabel() + "' not recognized.");
printRegistered(System.err);
throw new CmdException("No output set: '" + langName + "'");
}
}
}
if (cmdLine.contains(argCompress))
compressedOutput = true;
if (streamOutput == null && formattedOutput == null)
streamOutput = RDFFormat.NQUADS;
}
use of jena.cmd.CmdException in project jena by apache.
the class load method processModulesAndArgs.
@Override
protected void processModulesAndArgs() {
if (containsMultiple(graphNameArg))
throw new CmdException("At most one --graph allowed");
graphName = getValue(graphNameArg);
loadFiles = super.getPositional();
dump = contains(dumpArg);
super.processModulesAndArgs();
}
use of jena.cmd.CmdException in project jena by apache.
the class CmdNodeTableBuilder method processModulesAndArgs.
@Override
protected void processModulesAndArgs() {
if (!super.contains(argLocation))
throw new CmdException("Required: --loc DIR");
// if ( !super.contains(argTriplesOut) ) throw new CmdException("Required: --triples FILE") ;
// if ( !super.contains(argQuadsOut) ) throw new CmdException("Required: --quads FILE") ;
locationString = super.getValue(argLocation);
location = Location.create(locationString);
dataFileTriples = super.getValue(argTriplesOut);
if (dataFileTriples == null)
dataFileTriples = location.getPath("triples", "tmp");
dataFileQuads = super.getValue(argQuadsOut);
if (dataFileQuads == null)
dataFileQuads = location.getPath("quads", "tmp");
if (Objects.equals(dataFileTriples, dataFileQuads))
cmdError("Triples and Quads work files are the same");
if (super.contains(argNoStats))
collectStats = false;
//datafiles = getPositionalOrStdin() ;
datafiles = getPositional();
if (datafiles.isEmpty())
datafiles = Arrays.asList("-");
// ---- Checking.
for (String filename : datafiles) {
Lang lang = RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS);
if (lang == null)
// Does not happen due to default above.
cmdError("File suffix not recognized: " + filename);
if (!filename.equals("-") && !FileOps.exists(filename))
cmdError("File does not exist: " + filename);
}
}
Aggregations