01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.query.dawg;
07:
08: import static org.openrdf.query.dawg.DAWGTestResultSetSchema.BOOLEAN;
09: import static org.openrdf.query.dawg.DAWGTestResultSetSchema.RESULTSET;
10:
11: import org.openrdf.model.Graph;
12: import org.openrdf.model.Literal;
13: import org.openrdf.model.Resource;
14: import org.openrdf.model.Statement;
15: import org.openrdf.model.impl.GraphImpl;
16: import org.openrdf.model.util.GraphUtil;
17: import org.openrdf.model.util.GraphUtilException;
18: import org.openrdf.model.vocabulary.RDF;
19: import org.openrdf.rio.RDFHandlerException;
20: import org.openrdf.rio.helpers.RDFHandlerBase;
21:
22: /**
23: * @author Arjohn Kampman
24: */
25: public class DAWGTestBooleanParser extends RDFHandlerBase {
26:
27: /*-----------*
28: * Variables *
29: *-----------*/
30:
31: private Graph graph = new GraphImpl();
32:
33: private boolean value;
34:
35: /*--------------*
36: * Constructors *
37: *--------------*/
38:
39: public DAWGTestBooleanParser() {
40: }
41:
42: /*---------*
43: * Methods *
44: *---------*/
45:
46: public boolean getValue() {
47: return value;
48: }
49:
50: @Override
51: public void startRDF() throws RDFHandlerException {
52: graph.clear();
53: }
54:
55: @Override
56: public void handleStatement(Statement st)
57: throws RDFHandlerException {
58: graph.add(st);
59: }
60:
61: @Override
62: public void endRDF() throws RDFHandlerException {
63: try {
64: Resource resultSetNode = GraphUtil.getUniqueSubject(graph,
65: RDF.TYPE, RESULTSET);
66: Literal booleanLit = GraphUtil.getUniqueObjectLiteral(
67: graph, resultSetNode, BOOLEAN);
68:
69: if (booleanLit.equals(DAWGTestResultSetSchema.TRUE)) {
70: value = true;
71: } else if (booleanLit.equals(DAWGTestResultSetSchema.FALSE)) {
72: value = false;
73: } else {
74: new RDFHandlerException("Invalid boolean value: "
75: + booleanLit);
76: }
77: } catch (GraphUtilException e) {
78: throw new RDFHandlerException(e.getMessage(), e);
79: }
80: }
81: }
|