[Mulgara-svn] r788 - in branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter: . arithmetic value
pag at mulgara.org
pag at mulgara.org
Tue Apr 15 06:17:46 UTC 2008
Author: pag
Date: 2008-04-14 23:17:45 -0700 (Mon, 14 Apr 2008)
New Revision: 788
Added:
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractFilterValue.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractLogicUnitTest.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AndUnitTest.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/OrUnitTest.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/RDFTerm.java
Removed:
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BooleanLiteral.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/RDFTerm.java
Modified:
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractBooleanFn.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryComparisonFilter.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryOperatorFilter.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryTestFilter.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Equals.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Filter.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsBlankFn.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsIriFn.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsLiteralFn.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsUriFn.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Not.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/NotEquals.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/SameTerm.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/AbstractNumericOperation.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/AddOperation.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/DivideOperation.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/MinusOperation.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/MultiplyOperation.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/UnaryMinusUnitTest.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/AbstractAccessorFn.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/AbstractComparableLiteral.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/BlankNodeValue.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/Bool.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/ComparableExpression.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/DataTypeFn.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/IRI.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/LangFn.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/SimpleLiteral.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/StrFn.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/TypedLiteral.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/ValueLiteral.java
branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/Var.java
Log:
Refactor to have all testable filters return Literal XSD boolean values, plus new tests across the board
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractBooleanFn.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractBooleanFn.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractBooleanFn.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,7 +12,7 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
-import org.mulgara.query.filter.value.RDFTerm;
+import org.mulgara.query.filter.value.Bool;
/**
@@ -23,7 +23,7 @@
* @copyright © 2008 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public abstract class AbstractBooleanFn extends AbstractContextOwner implements Filter {
+public abstract class AbstractBooleanFn extends AbstractFilterValue implements Filter {
/** The variable to test */
RDFTerm operand;
@@ -33,8 +33,8 @@
* @param The term to test
*/
public AbstractBooleanFn(RDFTerm operand) {
+ super(operand);
this.operand = operand;
- operand.setContextOwner(this);
}
/**
@@ -45,6 +45,11 @@
return fnTest();
}
+ /** @see org.mulgara.query.filter.AbstractFilterValue#resolve() */
+ protected RDFTerm resolve() throws QueryException {
+ return fnTest() ? Bool.TRUE : Bool.FALSE;
+ }
+
/**
* An implementation specific test
* @return <code>true</code> when this test passes.
Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractFilterValue.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractFilterValue.java (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractFilterValue.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -0,0 +1,117 @@
+/**
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.filter;
+
+import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.value.Bool;
+import org.mulgara.query.filter.value.IRI;
+import org.mulgara.query.filter.value.SimpleLiteral;
+import org.mulgara.query.filter.value.ValueLiteral;
+
+
+/**
+ * A root for most values, for setting the context and giving default responses to many items.
+ *
+ * @created Apr 14, 2008
+ * @author Paul Gearon
+ * @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public abstract class AbstractFilterValue extends AbstractContextOwner implements Filter, ValueLiteral {
+
+ /** The operands for the operation */
+ RDFTerm[] operands;
+
+ /** The owner of the current context */
+ private ContextOwner contextOwner = null;
+
+ public AbstractFilterValue(RDFTerm... operands) {
+ this.operands = operands;
+ for (RDFTerm op: operands) op.setContextOwner(this);
+ }
+
+ /**
+ * @see org.mulgara.query.filter.value.ValueLiteral#getLang()
+ * @throws QueryException if this function does not resolve to a literal
+ */
+ public SimpleLiteral getLang() throws QueryException { return SimpleLiteral.EMPTY; }
+
+ /** @see org.mulgara.query.filter.value.ValueLiteral#getType() */
+ public IRI getType() throws QueryException { return Bool.IRI_TYPE; }
+
+ /**
+ * @see org.mulgara.query.filter.value.ValueLiteral#getLexical()
+ * @throws QueryException if this function does not resolve to a literal
+ */
+ public String getLexical() throws QueryException { return getValue().toString(); }
+
+ /**
+ * @see org.mulgara.query.filter.value.ValueLiteral#getValue()
+ * @return an object, for the result. Never null.
+ * @throws QueryException if this function does not resolve to a literal
+ */
+ public Object getValue() throws QueryException { return resolve().getValue(); }
+
+ /** @see org.mulgara.query.filter.value.ValueLiteral#test(org.mulgara.query.filter.Context) */
+ public boolean test(Context context) throws QueryException {
+ setCurrentContext(context);
+ RDFTerm term = resolve();
+ if (term.isLiteral()) {
+ return ((ValueLiteral)term).test(context);
+ } else if (term instanceof Filter) {
+ return ((Filter)term).test(context);
+ }
+ throw new QueryException("Type error. Cannot get a boolean from a: " + term.getClass().getSimpleName());
+ }
+
+ /** @see org.mulgara.query.filter.RDFTerm#equals(org.mulgara.query.filter.RDFTerm) */
+ public boolean equals(RDFTerm v) throws QueryException { return resolve().equals(v); }
+
+ /** @see org.mulgara.query.filter.RDFTerm#isBlank() */
+ public boolean isBlank() throws QueryException { return false; }
+
+ /** @see org.mulgara.query.filter.RDFTerm#isIRI() */
+ public boolean isIRI() throws QueryException { return false; }
+
+ /** @see org.mulgara.query.filter.RDFTerm#isLiteral() */
+ public boolean isLiteral() throws QueryException { return true; }
+
+ /** @see org.mulgara.query.filter.RDFTerm#isURI() */
+ public boolean isURI() throws QueryException { return isIRI(); }
+
+ /** @see org.mulgara.query.filter.RDFTerm#notEquals(org.mulgara.query.filter.RDFTerm) */
+ public boolean notEquals(RDFTerm v) throws QueryException { return !resolve().equals(v); }
+
+ /** @see org.mulgara.query.filter.RDFTerm#sameTerm(org.mulgara.query.filter.RDFTerm) */
+ public boolean sameTerm(RDFTerm v) throws QueryException { return resolve().sameTerm(v); }
+
+ /** @see org.mulgara.query.filter.RDFTerm#getContextOwner() */
+ public ContextOwner getContextOwner() { return contextOwner; }
+
+ /** @see org.mulgara.query.filter.RDFTerm#setContextOwner(org.mulgara.query.filter.ContextOwner) */
+ public void setContextOwner(ContextOwner owner) { contextOwner = owner; }
+
+ /** @see org.mulgara.query.filter.ContextOwner#getCurrentContext() */
+ public Context getCurrentContext() { return contextOwner.getCurrentContext(); }
+
+ /** @see org.mulgara.query.filter.ContextOwner#setCurrentContext(org.mulgara.query.filter.Context) */
+ public void setCurrentContext(Context context) {
+ if (!(context.equals(contextOwner.getCurrentContext()))) throw new AssertionError("Filter context being set differently to initial calling context.");
+ }
+
+ /**
+ * Resolves this function into whatever the return type should be (Literal or URI).
+ * @return The resolved value for the function.
+ * @throws QueryException There was an error resolving the value against the context.
+ */
+ protected abstract RDFTerm resolve() throws QueryException;
+}
Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractLogicUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractLogicUnitTest.java (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AbstractLogicUnitTest.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -0,0 +1,53 @@
+/**
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.filter;
+
+import static org.mulgara.query.filter.value.TypedLiteral.XSD_NS;
+
+import java.net.URI;
+
+import org.mulgara.query.filter.value.Bool;
+import org.mulgara.query.filter.value.SimpleLiteral;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests binary logic operations.
+ *
+ * @created Apr 14, 2008
+ * @author Paul Gearon
+ * @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public abstract class AbstractLogicUnitTest extends TestCase {
+
+ protected URI xsdInt = URI.create(XSD_NS + "int");
+ protected URI xsdBool = URI.create(XSD_NS + "boolean");
+
+ public AbstractLogicUnitTest(String name) {
+ super(name);
+ }
+
+ protected void basicTest(Filter lhs, Filter rhs, Bool result) throws Exception {
+ BinaryOperatorFilter op = getOperation(lhs, rhs);
+ op.setContextOwner(new TestContextOwner(new TestContext()));
+ assertTrue(op.equals(result));
+ assertFalse(op.isBlank());
+ assertFalse(op.isIRI());
+ assertTrue(op.isLiteral());
+ assertFalse(op.isURI());
+ assertTrue(result.getType().equals(op.getType()));
+ assertEquals(SimpleLiteral.EMPTY, op.getLang());
+ }
+
+ protected abstract BinaryOperatorFilter getOperation(Filter lhs, Filter rhs);
+}
\ No newline at end of file
Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AndUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AndUnitTest.java (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/AndUnitTest.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -0,0 +1,180 @@
+/**
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.filter;
+
+import java.net.URI;
+
+import org.jrdf.graph.Literal;
+import org.jrdf.graph.Node;
+import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.TestContext;
+import org.mulgara.query.filter.TestContextOwner;
+import org.mulgara.query.rdf.BlankNodeImpl;
+import org.mulgara.query.rdf.LiteralImpl;
+import org.mulgara.query.rdf.URIReferenceImpl;
+
+import org.mulgara.query.filter.value.Bool;
+import org.mulgara.query.filter.value.NumericLiteral;
+import org.mulgara.query.filter.value.TypedLiteral;
+import org.mulgara.query.filter.value.Var;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * Tests the AND operation.
+ *
+ * @created Apr 14, 2008
+ * @author Paul Gearon
+ * @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class AndUnitTest extends AbstractLogicUnitTest {
+
+ /**
+ * Build the unit test.
+ * @param name The name of the test
+ */
+ public AndUnitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Hook for test runner to obtain a test suite from.
+ * @return The test suite
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new AndUnitTest("testLiteral"));
+ suite.addTest(new AndUnitTest("testVar"));
+ return suite;
+ }
+
+ protected BinaryOperatorFilter getOperation(Filter lhs, Filter rhs) {
+ return new And(lhs, rhs);
+ }
+
+ public void testLiteral() throws Exception {
+ Bool t = Bool.TRUE;
+ Bool f = Bool.FALSE;
+ basicTest(t, t, t);
+ basicTest(f, t, f);
+ basicTest(t, f, f);
+ basicTest(f, f, f);
+
+ basicTest(new NumericLiteral(7), t, t);
+ basicTest(new NumericLiteral(0), t, f);
+ basicTest(new NumericLiteral(7), f, f);
+ basicTest(new NumericLiteral(0), f, f);
+
+ basicTest(TypedLiteral.newLiteral("foo"), t, t);
+ basicTest(TypedLiteral.newLiteral(""), t, f);
+ basicTest(TypedLiteral.newLiteral("foo"), f, f);
+ basicTest(TypedLiteral.newLiteral(""), f, f);
+ }
+
+ public void testVar() throws Exception {
+ Var x = new Var("x");
+ Var y = new Var("y");
+ And fn = new And(x, y);
+
+ URI fooBar = URI.create("foo:bar");
+ Literal seven = new LiteralImpl("7", xsdInt);
+ Literal zero = new LiteralImpl("0", xsdInt);
+ Literal trueLiteral = new LiteralImpl("true", xsdBool);
+ Literal falseLiteral = new LiteralImpl("false", xsdBool);
+ Node[][] rows = {
+ new Node[] {seven, seven},
+ new Node[] {seven, zero},
+ new Node[] {seven, trueLiteral},
+ new Node[] {seven, falseLiteral},
+
+ new Node[] {falseLiteral, new LiteralImpl("foo", "en")},
+ new Node[] {trueLiteral, new LiteralImpl("foo", fooBar)},
+ new Node[] {new LiteralImpl(""), trueLiteral},
+ new Node[] {new LiteralImpl(""), falseLiteral},
+ new Node[] {trueLiteral, new URIReferenceImpl(fooBar)},
+ new Node[] {falseLiteral, new URIReferenceImpl(fooBar)},
+ new Node[] {trueLiteral, new BlankNodeImpl(1001)},
+ new Node[] {falseLiteral, new BlankNodeImpl(1002)},
+ new Node[] {trueLiteral, null},
+ new Node[] {falseLiteral, null}
+ };
+ TestContext c = new TestContext(new String[] {"x", "y"}, rows);
+ c.beforeFirst();
+ fn.setContextOwner(new TestContextOwner(c));
+
+ // check the context setting
+ fn.setCurrentContext(c);
+
+ Bool t = Bool.TRUE;
+ Bool f = Bool.FALSE;
+
+ assertTrue(c.next());
+ assertTrue(t.equals(fn));
+
+ assertTrue(c.next());
+ assertTrue(f.equals(fn));
+
+ assertTrue(c.next());
+ assertTrue(t.equals(fn));
+
+ assertTrue(c.next());
+ assertTrue(f.equals(fn));
+
+ assertTrue(c.next());
+ assertTrue(f.equals(fn));
+
+ assertTrue(c.next());
+ try {
+ fn.getValue();
+ fail("EBV on an unknown type of literal");
+ } catch (QueryException qe) { }
+
+ assertTrue(c.next());
+ assertTrue(f.equals(fn));
+
+ assertTrue(c.next());
+ assertTrue(f.equals(fn));
+
+ assertTrue(c.next());
+ try {
+ fn.getValue();
+ fail("Logic operation on a URI");
+ } catch (QueryException qe) { }
+
+ assertTrue(c.next());
+ assertTrue(f.equals(fn));
+
+ assertTrue(c.next());
+ try {
+ fn.getValue();
+ fail("Logic operation on a blank node");
+ } catch (QueryException qe) { }
+
+ assertTrue(c.next());
+ assertTrue(f.equals(fn));
+
+ assertTrue(c.next());
+ try {
+ fn.getValue();
+ fail("Logic operation on an unbound");
+ } catch (QueryException qe) { }
+
+ assertTrue(c.next());
+ assertTrue(f.equals(fn));
+
+ assertFalse(c.next());
+ }
+
+}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryComparisonFilter.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryComparisonFilter.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryComparisonFilter.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,6 +12,7 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.value.Bool;
import org.mulgara.query.filter.value.ComparableExpression;
@@ -23,7 +24,7 @@
* @copyright © 2008 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public abstract class BinaryComparisonFilter extends AbstractContextOwner implements Filter {
+public abstract class BinaryComparisonFilter extends AbstractFilterValue implements Filter {
/** The first operand */
protected ComparableExpression lhs;
@@ -37,10 +38,9 @@
* @param rhs The right comparison expression
*/
BinaryComparisonFilter(ComparableExpression lhs, ComparableExpression rhs) {
+ super(lhs, rhs);
this.lhs = lhs;
this.rhs = rhs;
- lhs.setContextOwner(this);
- rhs.setContextOwner(this);
}
/**
@@ -51,6 +51,11 @@
return testCmp();
}
+ /** @see org.mulgara.query.filter.AbstractFilterValue#resolve() */
+ protected RDFTerm resolve() throws QueryException {
+ return testCmp() ? Bool.TRUE : Bool.FALSE;
+ }
+
/**
* A comparison specific function.
* @return <code>true</code> iff the comparison passes.
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryOperatorFilter.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryOperatorFilter.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryOperatorFilter.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,6 +12,8 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.value.Bool;
+import org.mulgara.query.filter.value.ValueLiteral;
/**
@@ -22,7 +24,7 @@
* @copyright © 2008 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public abstract class BinaryOperatorFilter extends AbstractContextOwner implements Filter {
+public abstract class BinaryOperatorFilter extends AbstractFilterValue implements ValueLiteral {
/** The first operand */
protected Filter lhs;
@@ -36,14 +38,13 @@
* @param rhs The right filter expression
*/
BinaryOperatorFilter(Filter lhs, Filter rhs) {
+ super(lhs, rhs);
this.lhs = lhs;
this.rhs = rhs;
}
- /** @see org.mulgara.query.filter.Filter#test(org.mulgara.query.filter.Context) */
- public boolean test(Context context) throws QueryException {
- setCurrentContext(context);
- return testOp(context);
+ public RDFTerm resolve() throws QueryException {
+ return testOp(getCurrentContext()) ? Bool.TRUE : Bool.FALSE;
}
/**
@@ -53,4 +54,5 @@
* @throws QueryException If there was an <em>unrecoverable</em> error resolving the operands
*/
abstract boolean testOp(Context context) throws QueryException;
+
}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryTestFilter.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryTestFilter.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BinaryTestFilter.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,7 +12,7 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
-import org.mulgara.query.filter.value.RDFTerm;
+import org.mulgara.query.filter.value.Bool;
/**
@@ -23,7 +23,7 @@
* @copyright © 2008 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public abstract class BinaryTestFilter extends AbstractContextOwner implements Filter {
+public abstract class BinaryTestFilter extends AbstractFilterValue implements Filter {
/** The first operand */
protected RDFTerm lhs;
@@ -37,10 +37,9 @@
* @param rhs The right expression
*/
BinaryTestFilter(RDFTerm lhs, RDFTerm rhs) {
+ super(lhs, rhs);
this.lhs = lhs;
this.rhs = rhs;
- lhs.setContextOwner(this);
- rhs.setContextOwner(this);
}
/**
@@ -51,6 +50,11 @@
return testCmp();
}
+ /** @see org.mulgara.query.filter.AbstractFilterValue#resolve() */
+ protected RDFTerm resolve() throws QueryException {
+ return testCmp() ? Bool.TRUE : Bool.FALSE;
+ }
+
/**
* A test specific comparison.
* @return <code>true</code> iff the test passes.
Deleted: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BooleanLiteral.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BooleanLiteral.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/BooleanLiteral.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -1,58 +0,0 @@
-/**
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-package org.mulgara.query.filter;
-
-
-/**
- * A test that always returns a given boolean value.
- *
- * @created Mar 7, 2008
- * @author Paul Gearon
- * @copyright © 2008 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public class BooleanLiteral implements Filter {
-
- /** The internal value of this literal */
- private boolean value;
-
- /**
- * Create a boolean value.
- * @param value The value to create.
- */
- public BooleanLiteral(boolean value) {
- this.value = value;
- }
-
- /**
- * @see org.mulgara.query.filter.Filter#test()
- */
- public boolean test(Context context) {
- return value;
- }
-
- /**
- * @see org.mulgara.query.filter.Filter#setCurrentContext(org.mulgara.query.filter.Context)
- * Context is irrelevant for this class.
- */
- public void setCurrentContext(Context context) {
- }
-
- /**
- * @see org.mulgara.query.filter.Filter#getCurrentContext()
- * Context is irrelevant for this class.
- */
- public Context getCurrentContext() {
- return null;
- }
-
-}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Equals.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Equals.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Equals.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,7 +12,6 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
-import org.mulgara.query.filter.value.RDFTerm;
/**
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Filter.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Filter.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Filter.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -22,7 +22,7 @@
* @copyright © 2008 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public interface Filter extends ContextOwner {
+public interface Filter extends ContextOwner, RDFTerm {
/**
* Tests a binding according to the filter.
@@ -37,6 +37,17 @@
public boolean test(Context context) { return true; }
public void setCurrentContext(Context context) { }
public Context getCurrentContext() { return null; }
+ // RDFTerm methods
+ public boolean equals(RDFTerm v) throws QueryException { return v == this; }
+ public ContextOwner getContextOwner() { return null; }
+ public Object getValue() throws QueryException { return true; }
+ public boolean isBlank() throws QueryException { return false; }
+ public boolean isIRI() throws QueryException { return false; }
+ public boolean isLiteral() throws QueryException { return true; }
+ public boolean isURI() throws QueryException { return false; }
+ public boolean notEquals(RDFTerm v) throws QueryException { return !equals(v); }
+ public boolean sameTerm(RDFTerm v) throws QueryException { return equals(v); }
+ public void setContextOwner(ContextOwner owner) { }
};
}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsBlankFn.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsBlankFn.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsBlankFn.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,7 +12,6 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
-import org.mulgara.query.filter.value.RDFTerm;
/**
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsIriFn.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsIriFn.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsIriFn.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,7 +12,6 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
-import org.mulgara.query.filter.value.RDFTerm;
/**
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsLiteralFn.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsLiteralFn.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsLiteralFn.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,7 +12,6 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
-import org.mulgara.query.filter.value.RDFTerm;
/**
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsUriFn.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsUriFn.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/IsUriFn.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,7 +12,6 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
-import org.mulgara.query.filter.value.RDFTerm;
/**
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Not.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Not.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/Not.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,6 +12,7 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.value.Bool;
/**
@@ -22,9 +23,9 @@
* @copyright © 2008 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public class Not extends AbstractContextOwner implements Filter {
+public class Not extends AbstractFilterValue implements Filter {
- /** The filter to invert */
+ /** The filter to invert. Local storage of operands[0]. */
Filter operand;
/**
@@ -32,6 +33,7 @@
* @param filter The filter to invert
*/
public Not(Filter operand) {
+ super(operand);
this.operand = operand;
}
@@ -43,4 +45,9 @@
return !operand.test(context);
}
+ /** @see org.mulgara.query.filter.AbstractFilterValue#resolve() */
+ protected RDFTerm resolve() throws QueryException {
+ return operand.test(getCurrentContext()) ? Bool.FALSE : Bool.TRUE;
+ }
+
}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/NotEquals.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/NotEquals.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/NotEquals.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,7 +12,6 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
-import org.mulgara.query.filter.value.RDFTerm;
/**
Added: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/OrUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/OrUnitTest.java (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/OrUnitTest.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -0,0 +1,185 @@
+/**
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.filter;
+
+import java.net.URI;
+
+import org.jrdf.graph.Literal;
+import org.jrdf.graph.Node;
+import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.TestContext;
+import org.mulgara.query.filter.TestContextOwner;
+import org.mulgara.query.rdf.BlankNodeImpl;
+import org.mulgara.query.rdf.LiteralImpl;
+import org.mulgara.query.rdf.URIReferenceImpl;
+
+import org.mulgara.query.filter.value.Bool;
+import org.mulgara.query.filter.value.NumericLiteral;
+import org.mulgara.query.filter.value.TypedLiteral;
+import org.mulgara.query.filter.value.Var;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * Tests the OR operation.
+ *
+ * @created Apr 14, 2008
+ * @author Paul Gearon
+ * @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class OrUnitTest extends AbstractLogicUnitTest {
+
+ /**
+ * Build the unit test.
+ * @param name The name of the test
+ */
+ public OrUnitTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Hook for test runner to obtain a test suite from.
+ * @return The test suite
+ */
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new OrUnitTest("testLiteral"));
+ suite.addTest(new OrUnitTest("testVar"));
+ return suite;
+ }
+
+ protected BinaryOperatorFilter getOperation(Filter lhs, Filter rhs) {
+ return new Or(lhs, rhs);
+ }
+
+ public void testLiteral() throws Exception {
+ Bool t = Bool.TRUE;
+ Bool f = Bool.FALSE;
+ basicTest(t, t, t);
+ basicTest(f, t, t);
+ basicTest(t, f, t);
+ basicTest(f, f, f);
+
+ basicTest(new NumericLiteral(7), t, t);
+ basicTest(new NumericLiteral(0), t, t);
+ basicTest(new NumericLiteral(7), f, t);
+ basicTest(new NumericLiteral(0), f, f);
+
+ basicTest(TypedLiteral.newLiteral("foo"), t, t);
+ basicTest(TypedLiteral.newLiteral(""), t, t);
+ basicTest(TypedLiteral.newLiteral("foo"), f, t);
+ basicTest(TypedLiteral.newLiteral(""), f, f);
+ }
+
+ public void testVar() throws Exception {
+ Var x = new Var("x");
+ Var y = new Var("y");
+ Or fn = new Or(x, y);
+
+ URI fooBar = URI.create("foo:bar");
+ Literal seven = new LiteralImpl("7", xsdInt);
+ Literal zero = new LiteralImpl("0", xsdInt);
+ Literal trueLiteral = new LiteralImpl("true", xsdBool);
+ Literal falseLiteral = new LiteralImpl("false", xsdBool);
+ Node[][] rows = {
+ new Node[] {zero, seven},
+ new Node[] {zero, zero},
+ new Node[] {zero, trueLiteral},
+ new Node[] {zero, falseLiteral},
+
+ new Node[] {falseLiteral, new LiteralImpl("foo", "en")},
+ new Node[] {falseLiteral, new LiteralImpl("foo", fooBar)},
+ new Node[] {new LiteralImpl(""), trueLiteral},
+ new Node[] {new LiteralImpl(""), falseLiteral},
+ new Node[] {falseLiteral, new URIReferenceImpl(fooBar)},
+ new Node[] {trueLiteral, new URIReferenceImpl(fooBar)},
+ new Node[] {falseLiteral, new BlankNodeImpl(1001)},
+ new Node[] {trueLiteral, new BlankNodeImpl(1002)},
+ new Node[] {falseLiteral, null},
+ new Node[] {trueLiteral, null}
+ };
+ TestContext c = new TestContext(new String[] {"x", "y"}, rows);
+ c.beforeFirst();
+ fn.setContextOwner(new TestContextOwner(c));
+
+ // check the context setting
+ fn.setCurrentContext(c);
+
+ Bool t = Bool.TRUE;
+ Bool f = Bool.FALSE;
+
+ assertTrue(c.next());
+ assertTrue(t.equals(fn));
+
+ assertTrue(c.next());
+ assertTrue(f.equals(fn));
+
+ assertTrue(c.next());
+ assertTrue(t.equals(fn));
+
+ assertTrue(c.next());
+ assertTrue(f.equals(fn));
+
+ // now the foo literals
+ assertTrue(c.next());
+ assertTrue(t.equals(fn));
+
+ assertTrue(c.next());
+ try {
+ fn.getValue();
+ fail("EBV on an unknown type of literal");
+ } catch (QueryException qe) { }
+
+ // The zero length string literals
+ assertTrue(c.next());
+ assertTrue(t.equals(fn));
+
+ assertTrue(c.next());
+ assertTrue(f.equals(fn));
+
+ // The URIs
+ assertTrue(c.next());
+ try {
+ fn.getValue();
+ fail("Logic operation on a URI");
+ } catch (QueryException qe) { }
+
+ assertTrue(c.next());
+ assertTrue(t.equals(fn));
+
+ // The blank nodes
+ assertTrue(c.next());
+ try {
+ fn.getValue();
+ fail("Logic operation on a blank node");
+ } catch (QueryException qe) { }
+
+ assertTrue(c.next());
+ assertTrue(t.equals(fn));
+
+ // The unbounds
+ assertTrue(c.next());
+ try {
+ fn.getValue();
+ fail("Logic operation on an unbound");
+ } catch (QueryException qe) { }
+
+ assertTrue(c.next());
+ assertTrue(t.equals(fn));
+
+ assertFalse(c.next());
+ }
+
+}
Copied: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/RDFTerm.java (from rev 755, branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/RDFTerm.java)
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/RDFTerm.java (rev 0)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/RDFTerm.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -0,0 +1,91 @@
+/**
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+package org.mulgara.query.filter;
+
+import org.mulgara.query.QueryException;
+
+
+/**
+ * Represents data that can appear in an expression, used by filters
+ *
+ * @created Mar 10, 2008
+ * @author Paul Gearon
+ * @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public interface RDFTerm {
+
+ /**
+ * Returns the data represented by this expression.
+ * @return The represented data.
+ * @throws QueryException Resolving the data for this value leads to an error.
+ */
+ public Object getValue() throws QueryException;
+
+ /**
+ * A value based equality test.
+ * @param v The object to compare to
+ * @return <code>true</code> iff v has the same value as the current object.
+ * @throws QueryException Resolving the data for this value leads to an error,
+ * or the types are incompatible.
+ */
+ public boolean equals(RDFTerm v) throws QueryException;
+
+ /**
+ * A value based inequality test.
+ * @param v The object to compare to
+ * @return <code>false</code> iff v has the same value as the current object.
+ * @throws QueryException Resolving the data for this value leads to an error,
+ * or the types are incompatible.
+ */
+ public boolean notEquals(RDFTerm v) throws QueryException;
+
+ /**
+ * Tests if this object is a URI or IRI.
+ * @return <code>true</code> if this object is an IRI.
+ */
+ public boolean isIRI() throws QueryException;
+
+ /** @see #isIRI() */
+ public boolean isURI() throws QueryException;
+
+ /**
+ * Tests if this value is a blank node
+ * @return <code>true</code> if this expression is a blank node
+ */
+ public boolean isBlank() throws QueryException;
+
+ /**
+ * Tests if this value is a literal
+ * @return <code>true</code> if this expression is a literal
+ */
+ public boolean isLiteral() throws QueryException;
+
+ /**
+ * Tests if this is the same term as another expression
+ * @param v The expression to test against
+ * @return <code>true</code> if the terms are the same
+ */
+ public boolean sameTerm(RDFTerm v) throws QueryException;
+
+ /**
+ * Sets the object that contains the current context to work in.
+ * @param owner The object that owns this context.
+ */
+ public void setContextOwner(ContextOwner owner);
+
+ /**
+ * Gets the object that contains the current context to work in.
+ * @return The object that owns this context.
+ */
+ public ContextOwner getContextOwner();
+}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/SameTerm.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/SameTerm.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/SameTerm.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,7 +12,6 @@
package org.mulgara.query.filter;
import org.mulgara.query.QueryException;
-import org.mulgara.query.filter.value.RDFTerm;
/**
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/AbstractNumericOperation.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/AbstractNumericOperation.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/AbstractNumericOperation.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -6,11 +6,11 @@
import org.mulgara.query.QueryException;
import org.mulgara.query.filter.Context;
import org.mulgara.query.filter.ContextOwner;
+import org.mulgara.query.filter.RDFTerm;
import org.mulgara.query.filter.value.AbstractComparable;
import org.mulgara.query.filter.value.IRI;
import org.mulgara.query.filter.value.NumericExpression;
import org.mulgara.query.filter.value.NumericLiteral;
-import org.mulgara.query.filter.value.RDFTerm;
import org.mulgara.query.filter.value.SimpleLiteral;
/**
@@ -33,25 +33,25 @@
/** @see org.mulgara.query.filter.value.ComparableExpression#getValue() */
public Number getValue() throws QueryException { return getNumber(); }
- /** @see org.mulgara.query.filter.value.RDFTerm#equals() */
+ /** @see org.mulgara.query.filter.RDFTerm#equals() */
public boolean equals(RDFTerm v) throws QueryException { return compare(getNumber(), v.getValue()) == 0; }
- /** @see org.mulgara.query.filter.value.RDFTerm#isBlank() */
+ /** @see org.mulgara.query.filter.RDFTerm#isBlank() */
public boolean isBlank() throws QueryException { return false; }
- /** @see org.mulgara.query.filter.value.RDFTerm#isIRI() */
+ /** @see org.mulgara.query.filter.RDFTerm#isIRI() */
public boolean isIRI() throws QueryException { return false; }
- /** @see org.mulgara.query.filter.value.RDFTerm#isLiteral() */
+ /** @see org.mulgara.query.filter.RDFTerm#isLiteral() */
public boolean isLiteral() throws QueryException { return true; }
- /** @see org.mulgara.query.filter.value.RDFTerm#isURI() */
+ /** @see org.mulgara.query.filter.RDFTerm#isURI() */
public boolean isURI() throws QueryException { return false; }
- /** @see org.mulgara.query.filter.value.RDFTerm#notEquals() */
+ /** @see org.mulgara.query.filter.RDFTerm#notEquals() */
public boolean notEquals(RDFTerm v) throws QueryException { return compare(getNumber(), v.getValue()) != 0; }
- /** @see org.mulgara.query.filter.value.RDFTerm#sameTerm() */
+ /** @see org.mulgara.query.filter.RDFTerm#sameTerm() */
public boolean sameTerm(RDFTerm v) throws QueryException { return getNumber().equals(v.getValue()); }
/** @see org.mulgara.query.filter.Filter#test() */
@@ -60,12 +60,12 @@
return getNumber().doubleValue() != 0.0;
}
- /** @see org.mulgara.query.filter.value.RDFTerm#setContextOwner(org.mulgara.query.filter.ContextOwner) */
+ /** @see org.mulgara.query.filter.RDFTerm#setContextOwner(org.mulgara.query.filter.ContextOwner) */
public void setContextOwner(ContextOwner owner) {
this.owner = owner;
}
- /** @see org.mulgara.query.filter.value.RDFTerm#getContextOwner() */
+ /** @see org.mulgara.query.filter.RDFTerm#getContextOwner() */
public ContextOwner getContextOwner() {
return owner;
}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/AddOperation.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/AddOperation.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/AddOperation.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -24,7 +24,7 @@
*/
public class AddOperation extends BinaryOperation {
- AddOperation(NumericExpression lhs, NumericExpression rhs) {
+ public AddOperation(NumericExpression lhs, NumericExpression rhs) {
super(lhs, rhs);
}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/DivideOperation.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/DivideOperation.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/DivideOperation.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -24,7 +24,7 @@
*/
public class DivideOperation extends BinaryOperation {
- DivideOperation(NumericExpression lhs, NumericExpression rhs) {
+ public DivideOperation(NumericExpression lhs, NumericExpression rhs) {
super(lhs, rhs);
}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/MinusOperation.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/MinusOperation.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/MinusOperation.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -24,7 +24,7 @@
*/
public class MinusOperation extends BinaryOperation {
- MinusOperation(NumericExpression lhs, NumericExpression rhs) {
+ public MinusOperation(NumericExpression lhs, NumericExpression rhs) {
super(lhs, rhs);
}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/MultiplyOperation.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/MultiplyOperation.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/MultiplyOperation.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -24,7 +24,7 @@
*/
public class MultiplyOperation extends BinaryOperation {
- MultiplyOperation(NumericExpression lhs, NumericExpression rhs) {
+ public MultiplyOperation(NumericExpression lhs, NumericExpression rhs) {
super(lhs, rhs);
}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/UnaryMinusUnitTest.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/UnaryMinusUnitTest.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/arithmetic/UnaryMinusUnitTest.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -41,7 +41,7 @@
* @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public abstract class UnaryMinusUnitTest extends TestCase {
+public class UnaryMinusUnitTest extends TestCase {
URI xsdInt = URI.create(XSD_NS + "int");
URI xsdLong = URI.create(XSD_NS + "long");
@@ -62,8 +62,8 @@
*/
public static Test suite() {
TestSuite suite = new TestSuite();
- suite.addTest(new AddOperationUnitTest("testLiteral"));
- suite.addTest(new AddOperationUnitTest("testVar"));
+ suite.addTest(new UnaryMinusUnitTest("testLiteral"));
+ suite.addTest(new UnaryMinusUnitTest("testVar"));
return suite;
}
@@ -130,16 +130,16 @@
fn.setCurrentContext(c);
assertTrue(c.next());
- assertTrue(new NumericLiteral(op.intValue()).equals(fn));
+ assertTrue(new NumericLiteral(-op.intValue()).equals(fn));
assertTrue(c.next());
- assertTrue(new NumericLiteral(op.longValue()).equals(fn));
+ assertTrue(new NumericLiteral(-op.longValue()).equals(fn));
assertTrue(c.next());
- assertTrue(new NumericLiteral(op.floatValue()).equals(fn));
+ assertTrue(new NumericLiteral(-op.floatValue()).equals(fn));
assertTrue(c.next());
- assertTrue(new NumericLiteral(op.doubleValue()).equals(fn));
+ assertTrue(new NumericLiteral(-op.doubleValue()).equals(fn));
assertTrue(c.next());
try {
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/AbstractAccessorFn.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/AbstractAccessorFn.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/AbstractAccessorFn.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,9 +12,9 @@
package org.mulgara.query.filter.value;
import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.AbstractFilterValue;
import org.mulgara.query.filter.Context;
-import org.mulgara.query.filter.ContextOwner;
-import org.mulgara.query.filter.Filter;
+import org.mulgara.query.filter.RDFTerm;
/**
@@ -28,135 +28,26 @@
* @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
* @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
*/
-public abstract class AbstractAccessorFn implements ValueLiteral {
+public abstract class AbstractAccessorFn extends AbstractFilterValue implements ValueLiteral {
/** The operand for the function */
RDFTerm operand;
- /** The owner of the current context */
- private ContextOwner contextOwner = null;
-
public AbstractAccessorFn(RDFTerm operand) {
+ super(operand);
this.operand = operand;
- operand.setContextOwner(this);
}
- /**
- * @see org.mulgara.query.filter.value.ValueLiteral#getLang()
- * @throws QueryException if this function does not resolve to a literal
- */
- public SimpleLiteral getLang() throws QueryException {
- return SimpleLiteral.EMPTY;
- }
-
/** @see org.mulgara.query.filter.value.ValueLiteral#getType() */
public IRI getType() throws QueryException {
return SimpleLiteral.STRING_TYPE;
}
/**
- * @see org.mulgara.query.filter.value.ValueLiteral#getLexical()
- * @throws QueryException if this function does not resolve to a literal
+ * @see org.mulgara.query.filter.ContextOwner#setCurrentContext(org.mulgara.query.filter.Context)
+ * Overridden from AbstractFilterValue to provide a different error message.
*/
- public String getLexical() throws QueryException {
- return (String)getValue();
- }
-
- /**
- * @see org.mulgara.query.filter.value.ValueLiteral#getValue()
- * @return a string, for the result. Never null.
- * @throws QueryException if this function does not resolve to a literal
- */
- public Object getValue() throws QueryException {
- return resolve().getValue();
- }
-
- /** @see org.mulgara.query.filter.value.ValueLiteral#test(org.mulgara.query.filter.Context) */
- public boolean test(Context context) throws QueryException {
- setCurrentContext(context);
- RDFTerm term = resolve();
- if (term.isLiteral()) {
- return ((ValueLiteral)term).test(context);
- } else if (term instanceof Filter) {
- return ((Filter)term).test(context);
- }
- throw new QueryException("Type error. Cannot get a boolean from a: " + term.getClass().getSimpleName());
- }
-
- /** @see org.mulgara.query.filter.value.RDFTerm#equals(org.mulgara.query.filter.value.RDFTerm) */
- public boolean equals(RDFTerm v) throws QueryException {
- return resolve().equals(v);
- }
-
- /**
- * @see org.mulgara.query.filter.value.RDFTerm#isBlank()
- * May be overridden.
- */
- public boolean isBlank() throws QueryException {
- return false;
- }
-
- /**
- * @see org.mulgara.query.filter.value.RDFTerm#isIRI()
- * May be overridden.
- */
- public boolean isIRI() throws QueryException {
- return false;
- }
-
- /**
- * @see org.mulgara.query.filter.value.RDFTerm#isLiteral()
- * May be overridden.
- */
- public boolean isLiteral() throws QueryException {
- return true;
- }
-
- /**
- * @see org.mulgara.query.filter.value.RDFTerm#isURI()
- * May be overridden.
- */
- public boolean isURI() throws QueryException {
- return isIRI();
- }
-
- /**
- * @see org.mulgara.query.filter.value.RDFTerm#notEquals(org.mulgara.query.filter.value.RDFTerm)
- * May be overridden.
- */
- public boolean notEquals(RDFTerm v) throws QueryException {
- return !resolve().equals(v);
- }
-
- /** @see org.mulgara.query.filter.value.RDFTerm#sameTerm(org.mulgara.query.filter.value.RDFTerm) */
- public boolean sameTerm(RDFTerm v) throws QueryException {
- return resolve().sameTerm(v);
- }
-
- /** @see org.mulgara.query.filter.value.RDFTerm#getContextOwner() */
- public ContextOwner getContextOwner() {
- return contextOwner;
- }
-
- /** @see org.mulgara.query.filter.value.RDFTerm#setContextOwner(org.mulgara.query.filter.ContextOwner) */
- public void setContextOwner(ContextOwner owner) {
- contextOwner = owner;
- }
-
- /** @see org.mulgara.query.filter.ContextOwner#getCurrentContext() */
- public Context getCurrentContext() {
- return contextOwner.getCurrentContext();
- }
-
- /** @see org.mulgara.query.filter.ContextOwner#setCurrentContext(org.mulgara.query.filter.Context) */
public void setCurrentContext(Context context) {
- if (!(context.equals(contextOwner.getCurrentContext()))) throw new AssertionError("Function context being set differently to initial calling context.");
+ if (!(context.equals(getContextOwner().getCurrentContext()))) throw new AssertionError("Function context being set differently to initial calling context.");
}
-
- /**
- * Resolves this function into whatever the return type should be (Literal or URI).
- * @return The resolved value for the function.
- * @throws QueryException There was an error resolving the value against the context.
- */
- abstract RDFTerm resolve() throws QueryException;
}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/AbstractComparableLiteral.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/AbstractComparableLiteral.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/AbstractComparableLiteral.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -16,6 +16,7 @@
import java.util.Map;
import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.RDFTerm;
/**
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/BlankNodeValue.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/BlankNodeValue.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/BlankNodeValue.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -14,6 +14,7 @@
import org.jrdf.graph.BlankNode;
import org.mulgara.query.QueryException;
import org.mulgara.query.filter.ContextOwner;
+import org.mulgara.query.filter.RDFTerm;
/**
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/Bool.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/Bool.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/Bool.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -29,6 +29,15 @@
/** xsd:boolean */
public static final URI TYPE = URI.create(XSD_NS + "boolean");
+ /** xsd:boolean as an IRI */
+ public static final IRI IRI_TYPE = new IRI(URI.create(XSD_NS + "boolean"));
+
+ /** A single boolean value for true */
+ public static final Bool TRUE = new Bool(Boolean.TRUE);
+
+ /** A single boolean value for false */
+ public static final Bool FALSE = new Bool(Boolean.FALSE);
+
/**
* Creates the value to wrap the boolean
* @param n The boolean to wrap
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/ComparableExpression.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/ComparableExpression.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/ComparableExpression.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -13,6 +13,7 @@
import org.mulgara.query.QueryException;
import org.mulgara.query.filter.Filter;
+import org.mulgara.query.filter.RDFTerm;
/**
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/DataTypeFn.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/DataTypeFn.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/DataTypeFn.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -13,6 +13,7 @@
import org.mulgara.query.QueryException;
import org.mulgara.query.filter.Context;
+import org.mulgara.query.filter.RDFTerm;
/**
* Represents a datatype() function that accesses the datatype on a literal.
@@ -33,12 +34,12 @@
super(operand);
}
- /** @see org.mulgara.query.filter.value.RDFTerm#isLiteral() */
+ /** @see org.mulgara.query.filter.RDFTerm#isLiteral() */
public boolean isLiteral() throws QueryException {
return false;
}
- /** @see org.mulgara.query.filter.value.RDFTerm#isIri() */
+ /** @see org.mulgara.query.filter.RDFTerm#isIri() */
public boolean isIRI() throws QueryException {
return true;
}
@@ -68,7 +69,7 @@
* @return The operands type IRI
* @throws QueryException If there was an error resolving the operand
*/
- RDFTerm resolve() throws QueryException {
+ protected RDFTerm resolve() throws QueryException {
if (!operand.isLiteral()) throw new QueryException("Disallowed type in DATATYPE function. Expected a Literal. Got a : " + operand.getClass().getSimpleName());
return ((ValueLiteral)operand).getType();
}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/IRI.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/IRI.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/IRI.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -15,6 +15,7 @@
import org.mulgara.query.QueryException;
import org.mulgara.query.filter.ContextOwner;
+import org.mulgara.query.filter.RDFTerm;
/**
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/LangFn.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/LangFn.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/LangFn.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -12,6 +12,7 @@
package org.mulgara.query.filter.value;
import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.RDFTerm;
/**
* Represents a Lang() function that accesses the language on a literal.
@@ -41,7 +42,7 @@
}
/**
- * @see org.mulgara.query.filter.value.RDFTerm#isLiteral()
+ * @see org.mulgara.query.filter.RDFTerm#isLiteral()
* May be overridden.
*/
public boolean isLiteral() throws QueryException {
@@ -53,7 +54,7 @@
* @return
* @throws QueryException
*/
- RDFTerm resolve() throws QueryException {
+ protected RDFTerm resolve() throws QueryException {
if (!operand.isLiteral()) throw new QueryException("Disallowed type in LANG function. Expected a Literal. Got a : " + operand.getClass().getSimpleName());
return ((ValueLiteral)operand).getLang();
}
Deleted: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/RDFTerm.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/RDFTerm.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/RDFTerm.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -1,92 +0,0 @@
-/**
- * The contents of this file are subject to the Open Software License
- * Version 3.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.opensource.org/licenses/osl-3.0.txt
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- */
-package org.mulgara.query.filter.value;
-
-import org.mulgara.query.QueryException;
-import org.mulgara.query.filter.ContextOwner;
-
-
-/**
- * Represents data that can appear in an expression, used by filters
- *
- * @created Mar 10, 2008
- * @author Paul Gearon
- * @copyright © 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
- * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
- */
-public interface RDFTerm {
-
- /**
- * Returns the data represented by this expression.
- * @return The represented data.
- * @throws QueryException Resolving the data for this value leads to an error.
- */
- public Object getValue() throws QueryException;
-
- /**
- * A value based equality test.
- * @param v The object to compare to
- * @return <code>true</code> iff v has the same value as the current object.
- * @throws QueryException Resolving the data for this value leads to an error,
- * or the types are incompatible.
- */
- public boolean equals(RDFTerm v) throws QueryException;
-
- /**
- * A value based inequality test.
- * @param v The object to compare to
- * @return <code>false</code> iff v has the same value as the current object.
- * @throws QueryException Resolving the data for this value leads to an error,
- * or the types are incompatible.
- */
- public boolean notEquals(RDFTerm v) throws QueryException;
-
- /**
- * Tests if this object is a URI or IRI.
- * @return <code>true</code> if this object is an IRI.
- */
- public boolean isIRI() throws QueryException;
-
- /** @see #isIRI() */
- public boolean isURI() throws QueryException;
-
- /**
- * Tests if this value is a blank node
- * @return <code>true</code> if this expression is a blank node
- */
- public boolean isBlank() throws QueryException;
-
- /**
- * Tests if this value is a literal
- * @return <code>true</code> if this expression is a literal
- */
- public boolean isLiteral() throws QueryException;
-
- /**
- * Tests if this is the same term as another expression
- * @param v The expression to test against
- * @return <code>true</code> if the terms are the same
- */
- public boolean sameTerm(RDFTerm v) throws QueryException;
-
- /**
- * Sets the object that contains the current context to work in.
- * @param owner The object that owns this context.
- */
- public void setContextOwner(ContextOwner owner);
-
- /**
- * Gets the object that contains the current context to work in.
- * @return The object that owns this context.
- */
- public ContextOwner getContextOwner();
-}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/SimpleLiteral.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/SimpleLiteral.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/SimpleLiteral.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -33,7 +33,7 @@
private SimpleLiteral lang = EMPTY;
/** The type used for strings */
- static final IRI STRING_TYPE = new IRI(new TypedLiteral.XSDString().getTypeURI());
+ public static final IRI STRING_TYPE = new IRI(new TypedLiteral.XSDString().getTypeURI());
/**
* Creates the value to wrap the string
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/StrFn.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/StrFn.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/StrFn.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -13,6 +13,7 @@
import org.jrdf.graph.BlankNode;
import org.mulgara.query.QueryException;
+import org.mulgara.query.filter.RDFTerm;
/**
* Represents a str() function that stringizes any underlying data.
@@ -57,7 +58,7 @@
* @return The operand
* @throws QueryException if the operand does not resolve
*/
- RDFTerm resolve() throws QueryException {
+ protected RDFTerm resolve() throws QueryException {
return new SimpleLiteral(getLexical());
}
}
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/TypedLiteral.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/TypedLiteral.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/TypedLiteral.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -111,15 +111,22 @@
/**
* No context needed as this is a literal value.
- * @see org.mulgara.query.filter.value.RDFTerm#getContextOwner()
+ * @see org.mulgara.query.filter.RDFTerm#getContextOwner()
*/
public ContextOwner getContextOwner() {
return null;
}
/**
+ * A public string representation of this literal.
+ */
+ public String toString() {
+ return "'" + lexical + "'^^<" + type + ">";
+ }
+
+ /**
* No context needed as this is a literal value.
- * @see org.mulgara.query.filter.value.RDFTerm#setContextOwner(org.mulgara.query.filter.ContextOwner)
+ * @see org.mulgara.query.filter.RDFTerm#setContextOwner(org.mulgara.query.filter.ContextOwner)
*/
public void setContextOwner(ContextOwner owner) { }
@@ -127,7 +134,8 @@
public boolean test(Context context) throws QueryException {
if (type == null) return ((String)value).length() != 0;
TypeInfo test = infoMap.get(type);
- return test != null && test.ebv(value.toString());
+ if (test == null) throw new QueryException("Type Error: no effective boolean value for: " + toString());
+ return test.ebv(value.toString());
}
/** A map of XSD datatypes onto the tests for their types */
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/ValueLiteral.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/ValueLiteral.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/ValueLiteral.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -14,6 +14,7 @@
import org.mulgara.query.QueryException;
import org.mulgara.query.filter.Context;
import org.mulgara.query.filter.Filter;
+import org.mulgara.query.filter.RDFTerm;
/**
Modified: branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/Var.java
===================================================================
--- branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/Var.java 2008-04-15 06:02:06 UTC (rev 787)
+++ branches/mgr-61-sparql/src/jar/query/java/org/mulgara/query/filter/value/Var.java 2008-04-15 06:17:45 UTC (rev 788)
@@ -20,6 +20,7 @@
import org.mulgara.query.filter.AbstractContextOwner;
import org.mulgara.query.filter.Context;
import org.mulgara.query.filter.ContextOwner;
+import org.mulgara.query.filter.RDFTerm;
/**
@@ -182,12 +183,12 @@
return ((ComparableExpression)term).test(context);
}
- /** @see org.mulgara.query.filter.value.RDFTerm#getContextOwner() */
+ /** @see org.mulgara.query.filter.RDFTerm#getContextOwner() */
public ContextOwner getContextOwner() {
return contextOwner;
}
- /** @see org.mulgara.query.filter.value.RDFTerm#setContextOwner(org.mulgara.query.filter.ContextOwner) */
+ /** @see org.mulgara.query.filter.RDFTerm#setContextOwner(org.mulgara.query.filter.ContextOwner) */
public void setContextOwner(ContextOwner owner) {
this.contextOwner = owner;
}
More information about the Mulgara-svn
mailing list