Search in sources :

Example 31 with JenaException

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);
    }
}
Also used : Suite(org.junit.runners.Suite) JenaException(org.apache.jena.shared.JenaException) InitializationError(org.junit.runners.model.InitializationError) ArrayList(java.util.ArrayList) ErrorReportingRunner(org.junit.internal.runners.ErrorReportingRunner)

Example 32 with JenaException

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

Example 33 with JenaException

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();
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) Graph(org.apache.jena.graph.Graph) ServletOutputStream(javax.servlet.ServletOutputStream) MediaType(org.apache.jena.atlas.web.MediaType) TypedOutputStream(org.apache.jena.atlas.web.TypedOutputStream) IOException(java.io.IOException)

Example 34 with JenaException

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;
}
Also used : JenaException(org.apache.jena.shared.JenaException) CmdException(jena.cmd.CmdException) ModDataset(arq.cmdline.ModDataset) DatasetGraphTransaction(org.apache.jena.tdb.transaction.DatasetGraphTransaction) CmdException(jena.cmd.CmdException) JenaException(org.apache.jena.shared.JenaException)

Example 35 with JenaException

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);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) 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