Search in sources :

Example 21 with JenaException

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

the class ExceptionTests method testDefaultPromotedError.

public void testDefaultPromotedError() {
    RDFDefaultErrorHandler.silent = true;
    try {
        Model m = ModelFactory.createDefaultModel();
        RDFReader rdr = m.getReader();
        rdr.setProperty("ERR_BAD_RDF_ATTRIBUTE", "EM_FATAL");
        rdr.read(m, "file:testing/wg/rdfms-abouteach/error002.rdf");
        fail("Promoted error did not throw exception");
    } catch (JenaException e) {
    //		System.err.println(e.getMessage());
    } finally {
        RDFDefaultErrorHandler.silent = false;
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) Model(org.apache.jena.rdf.model.Model) RDFReader(org.apache.jena.rdf.model.RDFReader)

Example 22 with JenaException

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

the class ReasonerTester method runTest.

/**
     * Run a single designated test.
     * @param uri the uri of the test, as defined in the manifest file
     * @param reasoner the reasoner to be tested
     * @param testcase the JUnit test case which is requesting this test
     * @return true if the test passes
     * @throws IOException if one of the test files can't be found
     * @throws JenaException if the test can't be found or fails internally
     */
public boolean runTest(String uri, Reasoner reasoner, TestCase testcase) throws IOException {
    // Find the specification for the named test
    Resource test = testManifest.getResource(uri);
    if (!test.hasProperty(RDF.type, testClass)) {
        throw new JenaException("Can't find test: " + uri);
    }
    String description = test.getRequiredProperty(descriptionP).getObject().toString();
    logger.debug("Reasoner test " + test.getURI() + " - " + description);
    // Construct the inferred graph
    Graph tbox = loadTestFile(test, tboxP);
    Graph data = loadTestFile(test, dataP);
    InfGraph graph = reasoner.bindSchema(tbox).bind(data);
    // Run each query triple and accumulate the results
    Graph queryG = loadTestFile(test, queryP);
    Graph resultG = Factory.createGraphMem();
    Iterator<Triple> queries = queryG.find(null, null, null);
    while (queries.hasNext()) {
        TriplePattern query = tripleToPattern(queries.next());
        logger.debug("Query: " + query);
        Iterator<Triple> answers = graph.find(query.asTripleMatch());
        while (answers.hasNext()) {
            Triple ans = answers.next();
            logger.debug("ans: " + TriplePattern.simplePrintString(ans));
            resultG.add(ans);
        }
    }
    // Check the total result set against the correct answer
    Graph correctG = loadTestFile(test, resultP);
    boolean correct = correctG.isIsomorphicWith(resultG);
    // ... end of debugging hack
    if (testcase != null) {
        Assert.assertTrue(description, correct);
    }
    return correct;
}
Also used : Triple(org.apache.jena.graph.Triple) JenaException(org.apache.jena.shared.JenaException) InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Graph(org.apache.jena.graph.Graph) TriplePattern(org.apache.jena.reasoner.TriplePattern)

Example 23 with JenaException

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

the class TestJenaException method testRethrownMessage.

public void testRethrownMessage() {
    Exception e = new Exception("kings and queens");
    JenaException j = new JenaException(e);
    assertTrue(j.getMessage().endsWith(e.getMessage()));
}
Also used : JenaException(org.apache.jena.shared.JenaException) JenaException(org.apache.jena.shared.JenaException)

Example 24 with JenaException

use of org.apache.jena.shared.JenaException 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);
    }
}
Also used : CmdException(jena.cmd.CmdException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) RiotException(org.apache.jena.riot.RiotException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) TerminationException(jena.cmd.TerminationException) JenaException(org.apache.jena.shared.JenaException) RiotNotFoundException(org.apache.jena.riot.RiotNotFoundException) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) JenaException(org.apache.jena.shared.JenaException) TerminationException(jena.cmd.TerminationException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) TransactionalNull(org.apache.jena.sparql.core.TransactionalNull) Transactional(org.apache.jena.sparql.core.Transactional)

Example 25 with JenaException

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

the class GraphTestBase 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) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) 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