use of org.apache.jena.shared.JenaException in project jena by apache.
the class DatasetGraphCollection method delete.
@Override
public void delete(Quad quad) {
Graph g = fetchGraph(quad.getGraph());
if (g == null)
throw new JenaException("No such graph: " + quad.getGraph());
g.delete(quad.asTriple());
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class ParserSPARQL10 method perform.
// All throwable handling.
private static void perform(Query query, String string, Action action) {
Reader in = new StringReader(string);
SPARQLParser10 parser = new SPARQLParser10(in);
try {
query.setStrict(true);
parser.setQuery(query);
action.exec(parser);
} catch (org.apache.jena.sparql.lang.sparql_10.ParseException ex) {
throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
} catch (org.apache.jena.sparql.lang.sparql_10.TokenMgrError tErr) {
// Last valid token : not the same as token error message - but this should not happen
int col = parser.token.endColumn;
int line = parser.token.endLine;
throw new QueryParseException(tErr.getMessage(), line, col);
} catch (QueryException ex) {
throw ex;
} catch (JenaException ex) {
throw new QueryException(ex.getMessage(), ex);
} catch (Error err) {
// The token stream can throw errors.
throw new QueryParseException(err.getMessage(), err, -1, -1);
} catch (Throwable th) {
Log.warn(ParserSPARQL10.class, "Unexpected throwable: ", th);
throw new QueryException(th.getMessage(), th);
}
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class TestInputStreamFactory method open.
private Object open(IRI uri, boolean in) {
IRI relative = uri.isAbsolute() ? base.relativize(uri, IRIRelativize.CHILD) : uri;
if (relative.isAbsolute())
throw new IllegalArgumentException("This TestInputStreamFactory only knows about '" + base + "'.");
String relPath = relative.toString();
if (relPath.length() - relPath.lastIndexOf('.') > 5) {
relPath = relPath + ".rdf";
relative = iriFactory.create(relPath);
}
if (mapBase != null) {
//System.out.println("LazyURL: " + relative + " " + mapBase);
try {
URL url = mapBase.create(relative).toURL();
if (!in) {
if (url.getProtocol().equalsIgnoreCase("file"))
return new FileOutputStream(url.getFile());
throw new IllegalArgumentException("Can only save to file: scheme");
}
return new LazyURLInputStream(url);
} catch (MalformedURLException e) {
throw new JenaException(e);
} catch (IOException e) {
e.printStackTrace();
throw new JenaException(e);
}
}
if (!in)
throw new IllegalArgumentException("Can only save to URLs");
if (zip != null)
return new LazyZipEntryInputStream(zip, relPath);
else
return TestInputStreamFactory.getInputStream(property + relPath);
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class FileUtils method getScratchDirectory.
/**
Answer a File naming a freshly-created directory in the temporary directory. This
directory should be deleted on exit.
TODO handle threading issues, mkdir failure, and better cleanup
@param prefix the prefix for the directory name
@return a File naming the new directory
*/
public static File getScratchDirectory(String prefix) {
File result = new File(getTempDirectory(), prefix + randomNumber());
if (result.exists())
return getScratchDirectory(prefix);
if (result.mkdir() == false)
throw new JenaException("mkdir failed on " + result);
result.deleteOnExit();
return result;
}
use of org.apache.jena.shared.JenaException in project jena by apache.
the class MakeSkolem method bodyCall.
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
@Override
public boolean bodyCall(Node[] args, int length, RuleContext context) {
StringBuilder key = new StringBuilder();
for (int i = 1; i < length; i++) {
Node n = getArg(i, args, context);
if (n.isBlank()) {
key.append("B");
key.append(n.getBlankNodeLabel());
} else if (n.isURI()) {
key.append("U");
key.append(n.getURI());
} else if (n.isLiteral()) {
key.append("L");
key.append(n.getLiteralLexicalForm());
if (n.getLiteralLanguage() != null)
key.append("@" + n.getLiteralLanguage());
if (n.getLiteralDatatypeURI() != null)
key.append("^^" + n.getLiteralDatatypeURI());
} else {
key.append("O");
key.append(n.toString());
}
}
try {
MessageDigest digester = MessageDigest.getInstance("MD5");
digester.reset();
byte[] digest = digester.digest(key.toString().getBytes());
String label = DatatypeConverter.printBase64Binary(digest);
Node skolem = NodeFactory.createBlankNode(label);
return context.getEnv().bind(args[0], skolem);
} catch (NoSuchAlgorithmException e) {
throw new JenaException(e);
}
}
Aggregations