Search in sources :

Example 61 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class ParserARQ method perform.

// All throwable handling.
private static void perform(Query query, String string, Action action) {
    Reader in = new StringReader(string);
    ARQParser parser = new ARQParser(in);
    try {
        query.setStrict(true);
        parser.setQuery(query);
        action.exec(parser);
    } catch (org.apache.jena.sparql.lang.arq.ParseException ex) {
        throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (org.apache.jena.sparql.lang.arq.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(ParserSPARQL11.class, "Unexpected throwable: ", th);
        throw new QueryException(th.getMessage(), th);
    }
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) QueryParseException(org.apache.jena.query.QueryParseException) JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) ARQParser(org.apache.jena.sparql.lang.arq.ARQParser) StringReader(java.io.StringReader)

Example 62 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class TestReifier method getGraph.

@Override
public Graph getGraph() {
    try {
        Constructor<?> cons = getConstructor(graphClass, new Class[] {});
        if (cons != null)
            return (Graph) cons.newInstance();
        Constructor<?> cons2 = getConstructor(graphClass, new Class[] { this.getClass() });
        if (cons2 != null)
            return (Graph) cons2.newInstance(this);
        throw new JenaException("no suitable graph constructor found for " + graphClass);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new JenaException(e);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) JenaException(org.apache.jena.shared.JenaException)

Example 63 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class DatasetGraphAccessorHTTP method target.

protected final String target(Node name) {
    if (!name.isURI())
        throw new JenaException("Not a URI: " + name);
    String guri = name.getURI();
    // Encode
    guri = IRILib.encodeUriComponent(guri);
    return remote + "?" + HttpNames.paramGraph + "=" + guri;
}
Also used : JenaException(org.apache.jena.shared.JenaException)

Example 64 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class TransactionHandlerContractTest method testExecuteInTransactionCatchesThrowable.

@SuppressWarnings("deprecation")
@ContractTest
public void testExecuteInTransactionCatchesThrowable() {
    TransactionHandler th = getTransactionHandlerProducer().newInstance();
    if (th.transactionsSupported()) {
        Command cmd = new Command() {

            @Override
            public Object execute() throws Error {
                throw new Error();
            }
        };
        try {
            th.executeInTransaction(cmd);
            fail("Should have thrown JenaException");
        } catch (JenaException x) {
        }
        try {
            th.execute(() -> {
                throw new Error();
            });
            fail("Should have thrown JenaException");
        } catch (JenaException x) {
        }
        try {
            th.calculate(() -> {
                throw new Error();
            });
            fail("Should have thrown JenaException");
        } catch (JenaException x) {
        }
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) Command(org.apache.jena.shared.Command) TransactionHandler(org.apache.jena.graph.TransactionHandler) ContractTest(org.xenei.junit.contract.ContractTest)

Example 65 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class GraphHelper method getGraph.

/**
	 * Answer an instance of <code>graphClass</code>. If <code>graphClass</code>
	 * has a constructor that takes a <code>ReificationStyle</code> argument,
	 * then that constructor is run on <code>style</code> to get the instance.
	 * Otherwise, if it has a # constructor that takes an argument of
	 * <code>wrap</code>'s class before the <code>ReificationStyle</code>, that
	 * constructor is used; this allows non-static inner classes to be used for
	 * <code>graphClass</code>, with <code>wrap</code> being the outer class
	 * instance. If no suitable constructor exists, a JenaException is thrown.
	 * 
	 * @param wrap
	 *            the outer class instance if graphClass is an inner class
	 * @param graphClass
	 *            a class implementing Graph
	 * @return an instance of graphClass with the given style
	 * @throws RuntimeException
	 *             or JenaException if construction fails
	 */
public static Graph getGraph(Object wrap, Class<? extends Graph> graphClass) {
    try {
        Constructor<?> cons = getConstructor(graphClass, new Class[] {});
        if (cons != null)
            return (Graph) cons.newInstance(new Object[] {});
        Constructor<?> cons2 = getConstructor(graphClass, new Class[] { wrap.getClass() });
        if (cons2 != null)
            return (Graph) cons2.newInstance(new Object[] { wrap });
        throw new JenaException("no suitable graph constructor found for " + graphClass);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new JenaException(e);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) JenaException(org.apache.jena.shared.JenaException)

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