Search in sources :

Example 11 with JenaException

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());
}
Also used : JenaException(org.apache.jena.shared.JenaException) GraphUtils.triples2quadsDftGraph(org.apache.jena.sparql.util.graph.GraphUtils.triples2quadsDftGraph) Graph(org.apache.jena.graph.Graph)

Example 12 with JenaException

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);
    }
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) SPARQLParser10(org.apache.jena.sparql.lang.sparql_10.SPARQLParser10) QueryParseException(org.apache.jena.query.QueryParseException) JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) StringReader(java.io.StringReader)

Example 13 with JenaException

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);
}
Also used : JenaException(org.apache.jena.shared.JenaException) MalformedURLException(java.net.MalformedURLException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) URL(java.net.URL)

Example 14 with JenaException

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;
}
Also used : JenaException(org.apache.jena.shared.JenaException)

Example 15 with JenaException

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);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) Node(org.apache.jena.graph.Node) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Aggregations

JenaException (org.apache.jena.shared.JenaException)70 Model (org.apache.jena.rdf.model.Model)12 RDFReader (org.apache.jena.rdf.model.RDFReader)8 IOException (java.io.IOException)7 QueryException (org.apache.jena.query.QueryException)5 QueryParseException (org.apache.jena.query.QueryParseException)5 java.io (java.io)4 InputStream (java.io.InputStream)4 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 Graph (org.apache.jena.graph.Graph)4 ServletOutputStream (javax.servlet.ServletOutputStream)3 CmdException (jena.cmd.CmdException)3 AmbiguousSpecificTypeException (org.apache.jena.assembler.exceptions.AmbiguousSpecificTypeException)3 MediaType (org.apache.jena.atlas.web.MediaType)3 Triple (org.apache.jena.graph.Triple)3 BadDescriptionMultipleRootsException (org.apache.jena.shared.BadDescriptionMultipleRootsException)3 BadDescriptionNoRootException (org.apache.jena.shared.BadDescriptionNoRootException)3 ARQParser (org.apache.jena.sparql.lang.arq.ARQParser)3 FileNotFoundException (java.io.FileNotFoundException)2