Java Code Examples for org.openrdf.query.QueryResultHandlerException

The following examples show how to use org.openrdf.query.QueryResultHandlerException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void endHeader()
	throws QueryResultHandlerException
{
	if (!headerComplete) {
		try {
			jg.writeEndObject();

			if (tupleVariablesFound) {
				// Write results
				jg.writeObjectFieldStart("results");

				jg.writeArrayFieldStart("bindings");
			}

			headerComplete = true;
		}
		catch (IOException e) {
			throw new QueryResultHandlerException(e);
		}
	}
}
 
Example 2
@Override
public void startHeader()
	throws QueryResultHandlerException
{
	if (!documentOpen) {
		startDocument();
	}

	if (!headerOpen) {
		try {
			// Write header
			jg.writeObjectFieldStart("head");

			headerOpen = true;
		}
		catch (IOException e) {
			throw new QueryResultHandlerException(e);
		}
	}
}
 
Example 3
@Override
public void handleLinks(List<String> linkUrls)
	throws QueryResultHandlerException
{
	try {
		if (!documentOpen) {
			startDocument();
		}

		if (!headerOpen) {
			startHeader();
		}

		jg.writeArrayFieldStart("link");
		for (String nextLink : linkUrls) {
			jg.writeString(nextLink);
		}
		jg.writeEndArray();
	}
	catch (IOException e) {
		throw new QueryResultHandlerException(e);
	}
}
 
Example 4
@Before
public void before()
		throws RepositoryException, IOException, RDFParseException,
		       MalformedQueryException, QueryResultParseException,
			   QueryResultHandlerException {
	repo = new SailRepository(new MemoryStore());
	repo.initialize();
	conn = repo.getConnection();
	vf = conn.getValueFactory();
	conn.add(getResource(data), "file://", RDFFormat.TURTLE);
	SPARQLResultsXMLParserFactory factory =
			new SPARQLResultsXMLParserFactory();
	parser = factory.getParser();
	parser.setValueFactory(vf);
	List<Rule> rules;
	rules = Rules.fromOntology(getResource(data));
	QueryRewriter rewriter = new QueryRewriter(conn, rules);
	query = (TupleQuery) rewriter.rewrite(QueryLanguage.SPARQL, queryString);
	nonInfQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
	System.out.println("== QUERY (" + this.name + ") ==");
	System.out.println(nonInfQuery);
	System.out.println("== REWRITTEN QUERY (" + this.name + ") ==");
	System.out.println(query);
}
 
Example 5
private QueryResult runQuery()
		throws IOException, QueryEvaluationException,
		       QueryResultParseException, TupleQueryResultHandlerException,
			   QueryResultHandlerException {
	TestResultHandler noninf = new TestResultHandler();
	TestResultHandler actual = new TestResultHandler();
	TestResultHandler expect = new TestResultHandler();
	parser.setQueryResultHandler(expect);
	parser.parseQueryResult(getResource(expected));
	nonInfQuery.evaluate(noninf);
	query.evaluate(actual);
	Multiset<BindingSet> noninfset = noninf.getSolutions();
	Multiset<BindingSet> expectset = expect.getSolutions();
	Multiset<BindingSet> actualset = actual.getSolutions();
	return new QueryResult(expectset, actualset, noninfset);
}
 
Example 6
@Override
public void startRDF() throws RDFHandlerException {
    try {
        writer.startDocument();
        writer.startHeader();
        writer.startQueryResult(Arrays.asList(new String[] {
                "subject", "predicate", "object", "context"
        }));
        writer.endHeader();
    } catch (QueryResultHandlerException e) {
        throw new RDFHandlerException(e);
    }
}
 
Example 7
@Override
public void handleNamespace(String prefix, String uri)
        throws RDFHandlerException {
    try {
        writer.handleNamespace(prefix, uri);
    } catch (QueryResultHandlerException e) {
        throw new RDFHandlerException(e);
    }
}
 
Example 8
@Override
public void startDocument()
	throws QueryResultHandlerException
{
	if (!documentOpen) {
		documentOpen = true;
		headerOpen = false;
		headerComplete = false;
		tupleVariablesFound = false;
		firstTupleWritten = false;
		linksFound = false;

		if (getWriterConfig().get(BasicWriterSettings.PRETTY_PRINT)) {
			// By default Jackson does not pretty print, so enable this unless
			// PRETTY_PRINT setting
			// is disabled
			jg.useDefaultPrettyPrinter();
		}

		try {
			if (getWriterConfig().isSet(BasicQueryWriterSettings.JSONP_CALLBACK)) {
				// SES-1019 : Write the callbackfunction name as a wrapper for
				// the results here
				String callbackName = getWriterConfig().get(BasicQueryWriterSettings.JSONP_CALLBACK);
				jg.writeRaw(callbackName);
				jg.writeRaw("(");
			}
			jg.writeStartObject();
		}
		catch (IOException e) {
			throw new QueryResultHandlerException(e);
		}
	}
}
 
Example 9
protected void writeValue(Value value)
	throws IOException, QueryResultHandlerException
{
	jg.writeStartObject();

	if (value instanceof URI) {
		jg.writeStringField("type", "uri");
		jg.writeStringField("value", ((URI)value).toString());
	}
	else if (value instanceof BNode) {
		jg.writeStringField("type", "bnode");
		jg.writeStringField("value", ((BNode)value).getID());
	}
	else if (value instanceof Literal) {
		Literal lit = (Literal)value;

		// TODO: Implement support for
		// BasicWriterSettings.RDF_LANGSTRING_TO_LANG_LITERAL here
		if (lit.getLanguage() != null) {
			jg.writeObjectField("xml:lang", lit.getLanguage());
		}
		// TODO: Implement support for
		// BasicWriterSettings.XSD_STRING_TO_PLAIN_LITERAL here
		if (lit.getDatatype() != null) {
			jg.writeObjectField("datatype", lit.getDatatype().stringValue());
		}

		jg.writeObjectField("type", "literal");

		jg.writeObjectField("value", lit.getLabel());
	}
	else {
		throw new TupleQueryResultHandlerException("Unknown Value object type: " + value.getClass());
	}
	jg.writeEndObject();
}
 
Example 10
@Override
public void handleBoolean(boolean value)
	throws QueryResultHandlerException
{
	if (!documentOpen) {
		startDocument();
	}

	if (!headerOpen) {
		startHeader();
	}

	if (!headerComplete) {
		endHeader();
	}

	if (tupleVariablesFound) {
		throw new QueryResultHandlerException("Cannot call handleBoolean after startQueryResults");
	}

	try {
		if (value) {
			jg.writeBooleanField("boolean", Boolean.TRUE);
		}
		else {
			jg.writeBooleanField("boolean", Boolean.FALSE);
		}

		endDocument();
	}
	catch (IOException e) {
		throw new QueryResultHandlerException(e);
	}
}
 
Example 11
@Test
public void subset()
		throws QueryEvaluationException, TupleQueryResultHandlerException,
		       IOException, QueryResultParseException,
			   QueryResultHandlerException {
	QueryResult q = this.runQuery();
	assertTrue(
		q.getNonInferred() + " should be a subset of " + q.getActual(),
		Multisets.containsOccurrences(
			q.getActual(),
			q.getNonInferred()
		));
}
 
Example 12
@Override
public void handleLinks(List<String> arg0)
        throws QueryResultHandlerException {
    // no-op
}
 
Example 13
@Override
public void handleBoolean(boolean value) throws QueryResultHandlerException {
    // do nothing
}
 
Example 14
@Override
public void handleLinks(List<String> linkUrls)
        throws QueryResultHandlerException {
    // do nothing
}
 
Example 15
@Override
public void parseQueryResult(InputStream in)
	throws IOException, QueryResultParseException, QueryResultHandlerException
{
	parseQueryResultInternal(in, true, true);
}
 
Example 16
@Override
protected void writeValue(final Value value) throws IOException,
        QueryResultHandlerException {
    
    if (value instanceof BigdataBNode &&
            ((BigdataBNode) value).isStatementIdentifier()) {
        
        writeSid((BigdataBNode) value);
        
    } else {
        
        super.writeValue(value);
        
    }
    
}
 
Example 17
protected void writeSid(final BigdataBNode sid) 
        throws IOException, QueryResultHandlerException {
    
    jg.writeStartObject();

    jg.writeStringField("type", BigdataSPARQLResultsJSONParser.SID);
    
    final BigdataStatement stmt = sid.getStatement();
    
    jg.writeFieldName(BigdataSPARQLResultsJSONParser.SUBJECT);
    writeValue(stmt.getSubject());
    
    jg.writeFieldName(BigdataSPARQLResultsJSONParser.PREDICATE);
    writeValue(stmt.getPredicate());
    
    jg.writeFieldName(BigdataSPARQLResultsJSONParser.OBJECT);
    writeValue(stmt.getObject());

    if (stmt.getContext() != null) {
        jg.writeFieldName(BigdataSPARQLResultsJSONParser.CONTEXT);
        writeValue(stmt.getContext());
    }
    
    jg.writeEndObject();
    
}
 
Example 18
@Override
public void handleStylesheet(String stylesheetUrl)
	throws QueryResultHandlerException
{
	// Ignore, as JSON does not support stylesheets
}
 
Example 19
@Override
public void handleNamespace(String prefix, String uri)
	throws QueryResultHandlerException
{
	// Ignored by SPARQLJSONWriterBase
}
 
Example 20
@Override
public void handleBoolean(boolean value) throws QueryResultHandlerException {
}
 
Example 21
@Override
public void handleLinks(List<String> linkUrls) throws QueryResultHandlerException {
}
 
Example 22
@Override
public void handleBoolean(boolean arg0) throws QueryResultHandlerException {
	
}
 
Example 23
@Override
public void handleLinks(List<String> arg0) throws QueryResultHandlerException {
	
}
 
Example 24
@Override
public void handleBoolean(boolean arg0) throws QueryResultHandlerException {

    throw new UnsupportedOperationException("Cannot handle boolean results");
    
}