use of org.apache.jena.shared.JenaException in project jena by apache.
the class ManifestSuite method oneManifest.
private Runner oneManifest(final Manifest manifest, List<Runner> r) {
// Recurse
for (Iterator<String> iter = manifest.includedManifests(); iter.hasNext(); ) {
try {
r.add(oneManifest(new Manifest(iter.next()), new ArrayList<Runner>()));
} catch (JenaException ex) {
r.add(new ErrorReportingRunner(null, ex));
}
}
itemHandler.setTestRunnerList(r);
manifest.apply(itemHandler);
try {
return new Suite((Class<?>) null, r) {
@Override
protected String getName() {
return manifest.getName();
}
};
} catch (InitializationError e) {
return new ErrorReportingRunner(null, e);
}
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class NodeCreateUtils method create.
/**
* Returns a Node described by the string, primarily for testing purposes.
* The string represents a URI, a numeric literal, a string literal, a bnode
* label, or a variable.
* <ul>
* <li>'some text' :: a string literal with that text
* <li>'some text'someLanguage:: a string literal with that text and
* language
* <li>'some text'someURI:: a typed literal with that text and datatype
* <li>digits :: a literal [OF WHAT TYPE] with that [numeric] value
* <li>_XXX :: a bnode with an AnonId built from _XXX
* <li>?VVV :: a variable with name VVV
* <li>&PPP :: to be done
* <li>name:stuff :: the URI; name may be expanded using the Extended map
* </ul>
*
* @param pm
* the PrefixMapping for translating pre:X strings
* @param x
* the string encoding the node to create
* @return a node with the appropriate type and label
*/
public static Node create(PrefixMapping pm, String x) {
if (x.equals(""))
throw new JenaException("Node.create does not accept an empty string as argument");
char first = x.charAt(0);
if (first == '\'' || first == '\"')
return NodeFactory.createLiteral(newString(pm, first, x));
if (Character.isDigit(first))
return NodeFactory.createLiteral(x, "", XSDDatatype.XSDinteger);
if (first == '_')
return NodeFactory.createBlankNode(x);
if (x.equals("??"))
return Node.ANY;
if (first == '?')
return NodeFactory.createVariable(x.substring(1));
if (first == '&')
return NodeFactory.createURI("q:" + x.substring(1));
int colon = x.indexOf(':');
String d = pm.getNsPrefixURI("");
return colon < 0 ? NodeFactory.createURI((d == null ? "eh:/" : d) + x) : NodeFactory.createURI(pm.expandPrefix(x));
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class SPARQL_GSP_R method doGet.
@Override
protected void doGet(HttpAction action) {
// Assume success - do the set up before grabbing the lock.
// Sets content type.
MediaType mediaType = ActionLib.contentNegotationRDF(action);
ServletOutputStream output;
try {
output = action.response.getOutputStream();
} catch (IOException ex) {
ServletOps.errorOccurred(ex);
output = null;
}
TypedOutputStream out = new TypedOutputStream(output, mediaType);
Lang lang = RDFLanguages.contentTypeToLang(mediaType.getContentType());
if (action.verbose)
action.log.info(format("[%d] Get: Content-Type=%s, Charset=%s => %s", action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName()));
action.beginRead();
setCommonHeaders(action.response);
try {
Target target = determineTarget(action);
if (action.log.isDebugEnabled())
action.log.debug("GET->" + target);
boolean exists = target.exists();
if (!exists)
ServletOps.errorNotFound("No such graph: <" + target.name + ">");
// If we want to set the Content-Length, we need to buffer.
//response.setContentLength(??) ;
String ct = lang.getContentType().toHeaderString();
action.response.setContentType(ct);
Graph g = target.graph();
//Special case RDF/XML to be the plain (faster, less readable) form
RDFFormat fmt = (lang == Lang.RDFXML) ? RDFFormat.RDFXML_PLAIN : RDFWriterRegistry.defaultSerialization(lang);
try {
RDFDataMgr.write(out, g, fmt);
} catch (JenaException ex) {
// Good news - this happens before any output for RDF/XML-ABBREV.
if (fmt.getLang().equals(Lang.RDFXML))
ServletOps.errorBadRequest("Failed to write output in RDF/XML: " + ex.getMessage());
else
ServletOps.errorOccurred("Failed to write output: " + ex.getMessage(), ex);
}
ServletOps.success(action);
} finally {
action.endRead();
}
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class ModTDBDataset method createDataset.
@Override
public Dataset createDataset() {
if (inMemFile != null) {
Dataset ds = TDBFactory.createDataset();
RDFDataMgr.read(ds, inMemFile);
return ds;
}
if (modAssembler.getAssemblerFile() != null) {
Dataset thing = null;
// Two variants: plain dataset with a TDB graph or a TDB dataset.
try {
thing = (Dataset) AssemblerUtils.build(modAssembler.getAssemblerFile(), VocabTDB.tDatasetTDB);
if (thing != null && !(thing.asDatasetGraph() instanceof DatasetGraphTransaction))
Log.warn(this, "Unexpected: Not a TDB dataset for type DatasetTDB");
if (thing == null)
// Should use assembler inheritance but how do we assert the subclass relationship in a program?
thing = (Dataset) AssemblerUtils.build(modAssembler.getAssemblerFile(), DatasetAssemblerVocab.tDataset);
} catch (JenaException ex) {
throw ex;
} catch (Exception ex) {
throw new CmdException("Error creating", ex);
}
return thing;
}
if (modAssembler.getLocation() == null)
throw new CmdException("No assembler file nor location provided");
// No assembler - use location to find a database.
Dataset ds = TDBFactory.createDataset(modAssembler.getLocation());
return ds;
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class qparse method exec.
@Override
protected void exec() {
try {
Query query = modQuery.getQuery();
try {
LogCtl.disable(ParserBase.ParserLoggerName);
QueryUtils.checkQuery(query, true);
} catch (QueryCheckException ex) {
System.err.println();
System.err.println("**** Check failure: " + ex.getMessage());
if (ex.getCause() != null)
ex.getCause().printStackTrace(System.err);
} finally {
LogCtl.setLevel(ParserBase.ParserLoggerName, "INFO");
}
// Print the query out in some syntax
if (printQuery) {
divider();
modOutput.output(query);
}
// Print internal forms.
if (printOp) {
divider();
modOutput.outputOp(query, false);
}
if (printQuad) {
divider();
modOutput.outputQuad(query, false);
}
if (printOpt) {
divider();
modOutput.outputOp(query, true);
}
if (printQuadOpt) {
divider();
modOutput.outputQuad(query, true);
}
if (printPlan) {
divider();
// This forces internal query initialization - must be after QueryUtils.checkQuery
QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.createGeneral());
QueryOutputUtils.printPlan(query, qExec);
}
} 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 (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 (JenaException ex) {
ex.printStackTrace();
throw ex;
} catch (CmdException ex) {
throw ex;
} catch (Exception ex) {
throw new CmdException("Exception", ex);
}
}
Aggregations