Search in sources :

Example 1 with SPARQLParser10

use of org.apache.jena.sparql.lang.sparql_10.SPARQLParser10 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 2 with SPARQLParser10

use of org.apache.jena.sparql.lang.sparql_10.SPARQLParser10 in project jena by apache.

the class ParserSPARQL10 method parseElement.

public static Element parseElement(String string) {
    final Query query = new Query();
    Action action = new Action() {

        @Override
        public void exec(SPARQLParser10 parser) throws Exception {
            Element el = parser.GroupGraphPattern();
            query.setQueryPattern(el);
        }
    };
    perform(query, string, action);
    return query.getQueryPattern();
}
Also used : Query(org.apache.jena.query.Query) Element(org.apache.jena.sparql.syntax.Element) SPARQLParser10(org.apache.jena.sparql.lang.sparql_10.SPARQLParser10)

Example 3 with SPARQLParser10

use of org.apache.jena.sparql.lang.sparql_10.SPARQLParser10 in project jena by apache.

the class ParserSPARQL10 method parseTemplate.

public static Template parseTemplate(String string) {
    final Query query = new Query();
    Action action = new Action() {

        @Override
        public void exec(SPARQLParser10 parser) throws Exception {
            Template t = parser.ConstructTemplate();
            query.setConstructTemplate(t);
        }
    };
    perform(query, string, action);
    return query.getConstructTemplate();
}
Also used : Query(org.apache.jena.query.Query) SPARQLParser10(org.apache.jena.sparql.lang.sparql_10.SPARQLParser10) Template(org.apache.jena.sparql.syntax.Template)

Aggregations

SPARQLParser10 (org.apache.jena.sparql.lang.sparql_10.SPARQLParser10)3 Query (org.apache.jena.query.Query)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 QueryException (org.apache.jena.query.QueryException)1 QueryParseException (org.apache.jena.query.QueryParseException)1 JenaException (org.apache.jena.shared.JenaException)1 Element (org.apache.jena.sparql.syntax.Element)1 Template (org.apache.jena.sparql.syntax.Template)1