summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Pitschke2013-07-23 15:49:04 (EDT)
committer Gerrit Code Review @ Eclipse.org2013-07-24 17:04:14 (EDT)
commit94c6881de4abf3de9acd9c277467077fd91c0b35 (patch)
treeae941070a227be074b61e60e5460c72dd1e9b86c
parent3e492f29f80c2504837f248c70cd5ebde66874a8 (diff)
downloadorg.eclipse.lyo.core-94c6881de4abf3de9acd9c277467077fd91c0b35.zip
org.eclipse.lyo.core-94c6881de4abf3de9acd9c277467077fd91c0b35.tar.gz
org.eclipse.lyo.core-94c6881de4abf3de9acd9c277467077fd91c0b35.tar.bz2
Bug 413572: Fix parsing of oslc_where typed values and test thereofrefs/changes/94/14794/2
Signed-off-by: Steve Pitschke <pitschke@us.ibm.com>
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/TypedValueInvocationHandler.java214
-rw-r--r--org.eclipse.lyo.core.query/src/test/java/org/eclipse/lyo/core/query/test/BasicWhereTest.java124
2 files changed, 168 insertions, 170 deletions
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/TypedValueInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/TypedValueInvocationHandler.java
index 823d762..a437743 100644
--- a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/TypedValueInvocationHandler.java
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/TypedValueInvocationHandler.java
@@ -1,108 +1,106 @@
-/*******************************************************************************
- * Copyright (c) 2012 IBM Corporation.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
- *
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- *
- * Steve Pitschke - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.lyo.core.query.impl;
-
-import java.lang.reflect.Method;
-import java.util.Map;
-
-import org.antlr.runtime.tree.CommonTree;
-import org.eclipse.lyo.core.query.PName;
-import org.eclipse.lyo.core.query.TypedValue;
-import org.eclipse.lyo.core.query.Value.Type;
-
-/**
- * Proxy implementation of {@link TypedValue} interface
- */
-class TypedValueInvocationHandler extends ValueInvocationHandler
-{
- public
- TypedValueInvocationHandler(
- CommonTree tree,
- Map<String, String> prefixMap
- )
- {
- super(tree, Type.TYPED_STRING);
-
- this.prefixMap = prefixMap;
- }
-
- /**
- * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
- */
- @Override
- public Object
- invoke(
- Object proxy,
- Method method,
- Object[] args
- ) throws Throwable
- {
- String methodName = method.getName();
- boolean isValue = methodName.equals("value");
-
- if (! isValue &&
- ! methodName.equals("prefixedName") &&
- ! methodName.equals("toString")) {
- return super.invoke(proxy, method, args);
- }
-
- if (isValue) {
-
- if (value == null) {
-
- String rawValue = ((CommonTree)tree.getChild(0)).getText();
-
- // XXX - determine if need to unescape
- value = rawValue.substring(1, rawValue.length() - 1);
- }
-
- return value;
- }
-
- if (prefixedName == null) {
-
- String rawPName = tree.getChild(1).getText();
-
- rawPName = rawPName.substring(1, rawPName.length() - 1);
-
- prefixedName = new PName();
-
- int colon = rawPName.indexOf(':');
-
- if (colon < 0) {
- prefixedName.local = rawPName;
- } else {
- if (colon > 0) {
- prefixedName.prefix = rawPName.substring(0, colon);
- prefixedName.namespace = prefixMap.get(prefixedName.prefix);
- }
- prefixedName.local = rawPName.substring(colon + 1);
- }
- }
-
- if (methodName.equals("prefixedName")) {
- return prefixedName;
- }
-
- return '"' + ((TypedValue)proxy).value() + "\"^^\"" +
- ((TypedValue)proxy).prefixedName() + '"';
- }
-
- private final Map<String, String> prefixMap;
- private String value = null;
- private PName prefixedName = null;
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Steve Pitschke - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.core.query.impl;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import org.antlr.runtime.tree.CommonTree;
+import org.eclipse.lyo.core.query.PName;
+import org.eclipse.lyo.core.query.TypedValue;
+import org.eclipse.lyo.core.query.Value.Type;
+
+/**
+ * Proxy implementation of {@link TypedValue} interface
+ */
+class TypedValueInvocationHandler extends ValueInvocationHandler
+{
+ public
+ TypedValueInvocationHandler(
+ CommonTree tree,
+ Map<String, String> prefixMap
+ )
+ {
+ super(tree, Type.TYPED_STRING);
+
+ this.prefixMap = prefixMap;
+ }
+
+ /**
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ @Override
+ public Object
+ invoke(
+ Object proxy,
+ Method method,
+ Object[] args
+ ) throws Throwable
+ {
+ String methodName = method.getName();
+ boolean isValue = methodName.equals("value");
+
+ if (! isValue &&
+ ! methodName.equals("prefixedName") &&
+ ! methodName.equals("toString")) {
+ return super.invoke(proxy, method, args);
+ }
+
+ if (isValue) {
+
+ if (value == null) {
+
+ String rawValue = ((CommonTree)tree.getChild(0)).getText();
+
+ // XXX - determine if need to unescape
+ value = rawValue.substring(1, rawValue.length() - 1);
+ }
+
+ return value;
+ }
+
+ if (prefixedName == null) {
+
+ String rawPName = tree.getChild(1).getText();
+
+ prefixedName = new PName();
+
+ int colon = rawPName.indexOf(':');
+
+ if (colon < 0) {
+ prefixedName.local = rawPName;
+ } else {
+ if (colon > 0) {
+ prefixedName.prefix = rawPName.substring(0, colon);
+ prefixedName.namespace = prefixMap.get(prefixedName.prefix);
+ }
+ prefixedName.local = rawPName.substring(colon + 1);
+ }
+ }
+
+ if (methodName.equals("prefixedName")) {
+ return prefixedName;
+ }
+
+ return '"' + ((TypedValue)proxy).value() + "\"^^" +
+ ((TypedValue)proxy).prefixedName();
+ }
+
+ private final Map<String, String> prefixMap;
+ private String value = null;
+ private PName prefixedName = null;
+}
diff --git a/org.eclipse.lyo.core.query/src/test/java/org/eclipse/lyo/core/query/test/BasicWhereTest.java b/org.eclipse.lyo.core.query/src/test/java/org/eclipse/lyo/core/query/test/BasicWhereTest.java
index 963c96f..162fc56 100644
--- a/org.eclipse.lyo.core.query/src/test/java/org/eclipse/lyo/core/query/test/BasicWhereTest.java
+++ b/org.eclipse.lyo.core.query/src/test/java/org/eclipse/lyo/core/query/test/BasicWhereTest.java
@@ -1,62 +1,62 @@
-/*******************************************************************************
- * Copyright (c) 2012 IBM Corporation.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
- *
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- *
- * Steve Pitschke - initial API and implementation
- *******************************************************************************/
-package org.eclipse.lyo.core.query.test;
-
-import java.util.Map;
-
-import org.eclipse.lyo.core.query.ParseException;
-import org.eclipse.lyo.core.query.QueryUtils;
-import org.eclipse.lyo.core.query.WhereClause;
-
-/**
- * Basic tests of oslc.where clause parsing
- */
-public class BasicWhereTest
-{
- public static void main(String[] args)
- {
- String prefixes = "qm=<http://qm.example.com/ns>," +
- "olsc=<http://open-services.net/ns/core#>," +
- "xs=<http://www.w3.org/2001/XMLSchema>";
-
- String[] expressions = {
- "qm:testcase=<http://example.com/tests/31459>",
- "qm:duration>=10.4",
- "oslc:create!=\"Bob\" and qm:verified!=true",
- "qm:state in [\"Done\",\"Open\"]",
- "oslc:verified_by{oslc:owner=\"Steve\" and qm:duration=-47.0} and oslc:description=\"very hairy expression\"",
- "qm:submitted<\"2011-10-10T07:00:00Z\"^^\"xs:dateTime\"",
- "oslc:label>\"The End\"@en-US",
- "XXX"
- };
-
- for (String expression : expressions) {
-
- try {
-
- Map<String, String> prefixMap =
- QueryUtils.parsePrefixes(prefixes);
- WhereClause whereClause = (WhereClause)
- QueryUtils.parseWhere(expression, prefixMap);
-
- System.out.println(whereClause);
-
- } catch (ParseException e) {
- e.printStackTrace(System.out);
- }
- }
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Steve Pitschke - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.lyo.core.query.test;
+
+import java.util.Map;
+
+import org.eclipse.lyo.core.query.ParseException;
+import org.eclipse.lyo.core.query.QueryUtils;
+import org.eclipse.lyo.core.query.WhereClause;
+
+/**
+ * Basic tests of oslc.where clause parsing
+ */
+public class BasicWhereTest
+{
+ public static void main(String[] args)
+ {
+ String prefixes = "qm=<http://qm.example.com/ns>," +
+ "olsc=<http://open-services.net/ns/core#>," +
+ "xs=<http://www.w3.org/2001/XMLSchema>";
+
+ String[] expressions = {
+ "qm:testcase=<http://example.com/tests/31459>",
+ "qm:duration>=10.4",
+ "oslc:create!=\"Bob\" and qm:verified!=true",
+ "qm:state in [\"Done\",\"Open\"]",
+ "oslc:verified_by{oslc:owner=\"Steve\" and qm:duration=-47.0} and oslc:description=\"very hairy expression\"",
+ "qm:submitted<\"2011-10-10T07:00:00Z\"^^xs:dateTime",
+ "oslc:label>\"The End\"@en-US",
+ "XXX"
+ };
+
+ for (String expression : expressions) {
+
+ try {
+
+ Map<String, String> prefixMap =
+ QueryUtils.parsePrefixes(prefixes);
+ WhereClause whereClause = (WhereClause)
+ QueryUtils.parseWhere(expression, prefixMap);
+
+ System.out.println(whereClause);
+
+ } catch (ParseException e) {
+ e.printStackTrace(System.out);
+ }
+ }
+ }
+}