aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Pitschke2012-06-29 16:37:14 (EDT)
committerSteve Pitschke2012-06-29 16:37:14 (EDT)
commite1f1ff1390b001226ec6e73d8c74cfb5cc8101c0 (patch)
tree758f428fbaae3a1584f50dd61334f0f9af5a15ef
parentcfbdb6e4abeee0b9ba52020da1d7c2638f399024 (diff)
downloadorg.eclipse.lyo.core-e1f1ff1390b001226ec6e73d8c74cfb5cc8101c0.zip
org.eclipse.lyo.core-e1f1ff1390b001226ec6e73d8c74cfb5cc8101c0.tar.gz
org.eclipse.lyo.core-e1f1ff1390b001226ec6e73d8c74cfb5cc8101c0.tar.bz2
Bug 383469: Added APIs and tests for oslc.select and oslc.propertiesrefs/changes/60/6560/1
Change-Id: I8c4f81b27fc90405fe972b2c354b1cf5836ed183 Signed-off-by: Steve Pitschke <pitschke@us.ibm.com>
-rw-r--r--org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcProperty.g93
-rw-r--r--org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcSelect.g67
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Identifier.java23
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/NestedProperty.java24
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Properties.java30
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Property.java32
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/PropertyList.java26
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/SelectClause.java23
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Wildcard.java23
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/IndentifierInvocationHandler.java55
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/LangedStringValueInvocationHandler.java1
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/NestedPropertyInvocationHandler.java96
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertiesInvocationHandler.java49
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertyInvocationHandler.java85
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertyListInvocationHandler.java130
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/WildcardInvocationHandler.java49
-rw-r--r--org.eclipse.lyo.core.query/src/test/java/org/eclipse/lyo/core/query/test/BasicSelectTest.java88
17 files changed, 738 insertions, 156 deletions
diff --git a/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcProperty.g b/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcProperty.g
deleted file mode 100644
index d133ed2..0000000
--- a/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcProperty.g
+++ /dev/null
@@ -1,93 +0,0 @@
-grammar OslcProperty;
-
-
-@header {
-package org.eclipse.lyo.core.query;
-}
-
-@lexer::header
-{
-package org.eclipse.lyo.core.query;
-}
-
-/*
-options {
- output=AST;
- ASTLabelType=CommonTree;
-}
-
-properties :
- ( property (','! property )* )
-
- ;
-props : properties EOF -> properties
- ;
-
-
-property :
- prefixedName ( nested_property )*
- ;
-
-nested_property :
- '{' properties '}'
- ;
-*/
-
-prefixedName : PN_PREFIX ':' PN_LOCAL;
-
-
-fragment
-PN_CHARS_BASE
- : 'A'..'Z'
- | 'a'..'z'
- | '\u00C0'..'\u00D6'
- | '\u00D8'..'\u00F6'
- | '\u00F8'..'\u02FF'
- | '\u0370'..'\u037D'
- | '\u037F'..'\u1FFF'
- | '\u200C'..'\u200D'
- | '\u2070'..'\u218F'
- | '\u2C00'..'\u2FEF'
- | '\u3001'..'\uD7FF'
- | '\uF900'..'\uFDCF'
- | '\uFDF0'..'\uFFFD'
- ;
-
-fragment PN_CHARS_U
- : PN_CHARS_BASE | '_'
- ;
-
-
-fragment PN_CHARS
- : PN_CHARS_U
- | MINUS
- | DIGIT
- | '\u00B7'
- | '\u0300'..'\u036F'
- | '\u203F'..'\u2040'
- ;
-
-fragment
-PN_PREFIX
- : PN_CHARS_BASE ((PN_CHARS|DOT)* PN_CHARS)?
- ;
-
-fragment
-PN_LOCAL
- : ( PN_CHARS_U | DIGIT ) ((PN_CHARS|DOT)* PN_CHARS)?
- ;
-
-fragment
-DIGIT
- : '0'..'9'
- ;
-
-fragment
-DOT
- : '.'
- ;
-
-fragment
-MINUS
- : '-'
- ;
diff --git a/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcSelect.g b/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcSelect.g
index 0522b1c..ce5a73e 100644
--- a/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcSelect.g
+++ b/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcSelect.g
@@ -32,6 +32,10 @@ package org.eclipse.lyo.core.query;
public List<String> getErrors() {
return errors;
}
+ public OslcSelectParser(String where)
+ {
+ this(new CommonTokenStream(new OslcSelectLexer(new ANTLRStringStream(where))));
+ }
}
oslc_select : properties
@@ -52,24 +56,14 @@ nested_property : identifier OPEN_CURLY_BRACE properties CLOSE_CURLY_BRACE -> ^(
identifier : prefixedName -> ^( 'prefixed_name' prefixedName )
;
-wildcard : ASTERISK -> ^( 'wildcard' ASTERISK )
+wildcard : ASTERISK -> ^( 'wildcard' )
;
-uri_ref_esc : '<' iriRef '>';
-
-string_esc : STRING_LITERAL ;
-
-iriRef
- : IRI_REF
- | prefixedName
- ;
-
prefixedName
: PNAME_LN
| PNAME_NS
;
-
// $>
// $<Lexer
@@ -87,21 +81,6 @@ PNAME_LN
: PNAME_NS PN_LOCAL
;
-
-IRI_REF
- : LESS ( options {greedy=false;} : ~(LESS | GREATER | '"' | OPEN_CURLY_BRACE | CLOSE_CURLY_BRACE | '|' | '^' | '\\' | '`' | ('\u0000'..'\u0020')) )* GREATER
- ;
-
-
-
-STRING_LITERAL
- : '"' ( options {greedy=false;} : ~('\u0022' | '\u005C' | '\u000A' | '\u000D') | ECHAR )* '"'
- ;
-
-STRING_LITERAL_LONG
- : '"""' ( options {greedy=false;} : ( '"' | '""' )? ( ~('"'|'\\') | ECHAR ) )* '"""'
- ;
-
fragment
ECHAR
: '\\' ('t' | 'b' | 'n' | 'r' | 'f' | '\\' | '"' | '\'')
@@ -113,11 +92,6 @@ PN_CHARS_U
;
fragment
-VARNAME
- : ( PN_CHARS_U | DIGIT ) ( PN_CHARS_U | DIGIT | '\u00B7' | '\u0300'..'\u036F' | '\u203F'..'\u2040' )*
- ;
-
-fragment
PN_CHARS
: PN_CHARS_U
| MINUS
@@ -172,18 +146,6 @@ CLOSE_CURLY_BRACE
: '}'
;
-OPEN_SQUARE_BRACE
- : '['
- ;
-
-CLOSE_SQUARE_BRACE
- : ']'
- ;
-
-SEMICOLON
- : ';'
- ;
-
DOT
: '.'
;
@@ -208,23 +170,4 @@ NOT
: '!'
;
-DIVIDE
- : '/'
- ;
-
-EQUAL
- : '='
- ;
-
-LESS
- : '<'
- ;
-
-GREATER
- : '>'
- ;
-
-ANY : .
- ;
-
// $>
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Identifier.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Identifier.java
new file mode 100644
index 0000000..dbe0ca0
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Identifier.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * PName identifier from olsc.select of oslc.properties clause
+ */
+public interface Identifier extends Property
+{
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/NestedProperty.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/NestedProperty.java
new file mode 100644
index 0000000..b7d9515
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/NestedProperty.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Nested property from olsc.select of oslc.properties clause
+ */
+public interface NestedProperty extends Property
+{
+ Properties properties();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Properties.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Properties.java
new file mode 100644
index 0000000..d11420d
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Properties.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Properties from olsc.select of oslc.properties clause
+ */
+public interface Properties
+{
+ enum Type
+ {
+ WILDCARD,
+ PROPERTY_LIST;
+ }
+
+ Type type();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Property.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Property.java
new file mode 100644
index 0000000..053d434
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Property.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Property list element from olsc.select of oslc.properties clause
+ */
+public interface Property
+{
+ enum Type
+ {
+ IDENTIFIER,
+ NESTED_PROPERTY
+ }
+
+ Type type();
+
+ PName identifier();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/PropertyList.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/PropertyList.java
new file mode 100644
index 0000000..908c150
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/PropertyList.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.List;
+
+/**
+ * Property list from olsc.select of oslc.properties clause
+ */
+public interface PropertyList extends Properties
+{
+ List<Property> children();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/SelectClause.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/SelectClause.java
new file mode 100644
index 0000000..d4ea486
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/SelectClause.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Top level select clause from olsc.select
+ */
+public interface SelectClause extends Properties
+{
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Wildcard.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Wildcard.java
new file mode 100644
index 0000000..f88a60f
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Wildcard.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Wildcard property from olsc.select of oslc.properties clause
+ */
+public interface Wildcard extends Properties
+{
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/IndentifierInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/IndentifierInvocationHandler.java
new file mode 100644
index 0000000..e2ee0f8
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/IndentifierInvocationHandler.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.Identifier;
+import org.eclipse.lyo.core.query.Property.Type;
+
+/**
+ * Proxy implementation of {@link Indentifier} interface
+ */
+public class IndentifierInvocationHandler extends PropertyInvocationHandler
+{
+ public
+ IndentifierInvocationHandler(
+ CommonTree tree,
+ Map<String, String> prefixMap
+ )
+ {
+ super(tree, Type.IDENTIFIER, prefixMap);
+ }
+
+ /**
+ * @see org.eclipse.lyo.core.query.impl.PropertiesInvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ @Override
+ public Object invoke(
+ Object proxy,
+ Method method,
+ Object[] args
+ ) throws Throwable
+ {
+ if (! method.getName().equals("toString")) {
+ return super.invoke(proxy, method, args);
+ }
+
+ return ((Identifier)proxy).identifier().toString();
+ }
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/LangedStringValueInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/LangedStringValueInvocationHandler.java
index c1a57cb..286a0ab 100644
--- a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/LangedStringValueInvocationHandler.java
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/LangedStringValueInvocationHandler.java
@@ -20,7 +20,6 @@ import java.lang.reflect.Method;
import org.antlr.runtime.tree.CommonTree;
import org.eclipse.lyo.core.query.LangedStringValue;
-import org.eclipse.lyo.core.query.TypedValue;
import org.eclipse.lyo.core.query.Value.Type;
/**
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/NestedPropertyInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/NestedPropertyInvocationHandler.java
new file mode 100644
index 0000000..5031d90
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/NestedPropertyInvocationHandler.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * 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.lang.reflect.Proxy;
+import java.util.Map;
+
+import org.antlr.runtime.tree.CommonTree;
+import org.eclipse.lyo.core.query.NestedProperty;
+import org.eclipse.lyo.core.query.OslcSelectParser;
+import org.eclipse.lyo.core.query.Properties;
+import org.eclipse.lyo.core.query.Property.Type;
+import org.eclipse.lyo.core.query.PropertyList;
+import org.eclipse.lyo.core.query.Wildcard;
+
+/**
+ * Proxy implementation of {@link NestedProperty} interface
+ */
+class NestedPropertyInvocationHandler extends PropertyInvocationHandler
+{
+ public
+ NestedPropertyInvocationHandler(
+ CommonTree tree,
+ Map<String, String> prefixMap
+ )
+ {
+ super((CommonTree)tree.getChild(0).getChild(0), Type.NESTED_PROPERTY,
+ prefixMap);
+
+ this.tree = tree;
+ }
+
+ /**
+ * @see org.eclipse.lyo.core.query.impl.PropertyInvocationHandler#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 isProperties = methodName.equals("properties");
+
+ if (! isProperties &&
+ ! methodName.equals("toString")) {
+ return super.invoke(proxy, method, args);
+ }
+
+ if (isProperties && properties != null) {
+ return properties;
+ }
+
+ CommonTree treeProperties = (CommonTree)tree.getChild(1);
+
+ switch (treeProperties.getType())
+ {
+ case OslcSelectParser.WILDCARD:
+ properties = (Properties)
+ Proxy.newProxyInstance(Wildcard.class.getClassLoader(),
+ new Class<?>[] { Wildcard.class },
+ new WildcardInvocationHandler());
+ break;
+ default:
+ case OslcSelectParser.PROPERTIES:
+ properties = (Properties)
+ Proxy.newProxyInstance(PropertyList.class.getClassLoader(),
+ new Class<?>[] { PropertyList.class },
+ new PropertyListInvocationHandler(treeProperties,
+ prefixMap));
+ break;
+ }
+
+ if (isProperties) {
+ return properties;
+ }
+
+ return ((NestedProperty)proxy).identifier().toString() + '{' +
+ properties.toString() + '}';
+ }
+
+ private final CommonTree tree;
+ private Properties properties = null;
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertiesInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertiesInvocationHandler.java
new file mode 100644
index 0000000..e7713d3
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertiesInvocationHandler.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.InvocationHandler;
+import java.lang.reflect.Method;
+
+import org.eclipse.lyo.core.query.Properties;
+import org.eclipse.lyo.core.query.Properties.Type;
+
+/**
+ * Proxy implementation of {@link Properties} interface
+ */
+class PropertiesInvocationHandler implements InvocationHandler
+{
+ protected
+ PropertiesInvocationHandler(Type type)
+ {
+ this.type = type;
+ }
+
+ /**
+ * @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
+ {
+ return type;
+ }
+
+ private final Type type;
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertyInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertyInvocationHandler.java
new file mode 100644
index 0000000..0743673
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertyInvocationHandler.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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.InvocationHandler;
+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.Property;
+import org.eclipse.lyo.core.query.Property.Type;
+
+/**
+ * Proxy implementation of {@link Property} interface
+ */
+class PropertyInvocationHandler implements InvocationHandler
+{
+ public
+ PropertyInvocationHandler(
+ CommonTree tree,
+ Type type,
+ Map<String, String> prefixMap
+ )
+ {
+ this.tree = tree;
+ this.type = type;
+ 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
+ {
+ if (method.getName().equals("type")) {
+ return type;
+ }
+
+ if (identifier != null) {
+ return identifier;
+ }
+
+ String rawIdentifier = tree.getText();
+
+ identifier = new PName();
+
+ int colon = rawIdentifier.indexOf(':');
+
+ if (colon < 0) {
+ identifier.local = rawIdentifier;
+ } else {
+ if (colon > 0) {
+ identifier.prefix = rawIdentifier.substring(0, colon);
+ identifier.namespace = prefixMap.get(identifier.prefix);
+ }
+ identifier.local = rawIdentifier.substring(colon + 1);
+ }
+
+ return identifier;
+ }
+
+ private final CommonTree tree;
+ private final Type type;
+ protected final Map<String, String> prefixMap;
+ private PName identifier = null;
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertyListInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertyListInvocationHandler.java
new file mode 100644
index 0000000..36c0806
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/PropertyListInvocationHandler.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * 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.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.antlr.runtime.tree.CommonTree;
+import org.eclipse.lyo.core.query.Identifier;
+import org.eclipse.lyo.core.query.NestedProperty;
+import org.eclipse.lyo.core.query.OslcSelectParser;
+import org.eclipse.lyo.core.query.Properties.Type;
+import org.eclipse.lyo.core.query.Property;
+
+/**
+ * Proxy implementation of {@link PropertyList} interface
+ */
+public class PropertyListInvocationHandler extends PropertiesInvocationHandler
+{
+ public
+ PropertyListInvocationHandler(
+ CommonTree tree,
+ Map<String, String> prefixMap
+ )
+ {
+ super(Type.PROPERTY_LIST);
+
+ this.tree = tree;
+ this.prefixMap = prefixMap;
+ }
+
+ /**
+ * @see PropertiesInvocationHandler#invoke(Object, Method, Object[])
+ */
+ @Override
+ public Object invoke(
+ Object proxy,
+ Method method,
+ Object[] args
+ ) throws Throwable
+ {
+ String methodName = method.getName();
+ boolean isChildren = methodName.equals("children");
+
+ if (! isChildren &&
+ ! methodName.equals("toString")) {
+ return super.invoke(proxy, method, args);
+ }
+
+ if (isChildren && children != null) {
+ return children;
+ }
+
+ @SuppressWarnings("unchecked")
+ List<CommonTree> treeChildren = tree.getChildren();
+
+ children = new ArrayList<Property>(treeChildren.size());
+
+ for (CommonTree treeChild : treeChildren) {
+
+ Property property;
+
+ switch (treeChild.getType())
+ {
+ case OslcSelectParser.PREFIXED_NAME:
+ property = (Property)
+ Proxy.newProxyInstance(Identifier.class.getClassLoader(),
+ new Class<?>[] { Identifier.class },
+ new IndentifierInvocationHandler(
+ (CommonTree)treeChild.getChild(0),
+ prefixMap));
+ break;
+ default:
+ case OslcSelectParser.NESTED_PROPERTIES:
+ property = (Property)
+ Proxy.newProxyInstance(NestedProperty.class.getClassLoader(),
+ new Class<?>[] { NestedProperty.class },
+ new NestedPropertyInvocationHandler(treeChild,
+ prefixMap));
+ break;
+ }
+
+ children.add(property);
+ }
+
+ children = Collections.unmodifiableList(children);
+
+ if (isChildren) {
+ return children;
+ }
+
+ boolean first = true;
+ StringBuffer buffer = new StringBuffer();
+
+ for (Property property : children) {
+
+ if (first) {
+ first = false;
+ } else {
+ buffer.append(',');
+ }
+
+ buffer.append(property.toString());
+ }
+
+ return buffer.toString();
+ }
+
+ private final CommonTree tree;
+ private Map<String, String> prefixMap;
+ private List<Property> children = null;
+}
+ \ No newline at end of file
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/WildcardInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/WildcardInvocationHandler.java
new file mode 100644
index 0000000..de6f9c1
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/WildcardInvocationHandler.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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 org.eclipse.lyo.core.query.Properties.Type;
+
+/**
+ * Proxy implementation of {@link Wildcard} interface
+ */
+public class WildcardInvocationHandler extends PropertiesInvocationHandler
+{
+ public
+ WildcardInvocationHandler()
+ {
+ super(Type.WILDCARD);
+ }
+
+ /**
+ * @see org.eclipse.lyo.core.query.impl.PropertiesInvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ @Override
+ public Object invoke(
+ Object proxy,
+ Method method,
+ Object[] args
+ ) throws Throwable
+ {
+ if (! method.getName().equals("toString")) {
+ return super.invoke(proxy, method, args);
+ }
+
+ return "*";
+ }
+}
diff --git a/org.eclipse.lyo.core.query/src/test/java/org/eclipse/lyo/core/query/test/BasicSelectTest.java b/org.eclipse.lyo.core.query/src/test/java/org/eclipse/lyo/core/query/test/BasicSelectTest.java
new file mode 100644
index 0000000..0487c7e
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/test/java/org/eclipse/lyo/core/query/test/BasicSelectTest.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * 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.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.tree.CommonTree;
+import org.eclipse.lyo.core.query.OslcSelectParser;
+import org.eclipse.lyo.core.query.PropertyList;
+import org.eclipse.lyo.core.query.SelectClause;
+import org.eclipse.lyo.core.query.Wildcard;
+import org.eclipse.lyo.core.query.impl.PropertyListInvocationHandler;
+import org.eclipse.lyo.core.query.impl.WildcardInvocationHandler;
+
+/**
+ * Basic tests of oslc.select clause parsing
+ */
+public class BasicSelectTest
+{
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args)
+ {
+ Map<String, String> prefixMap = new HashMap<String, String>();
+
+ prefixMap.put("qm", "http://qm.example.com/ns");
+ prefixMap.put("olsc", "http://open-services.net/ns/core#");
+
+ String[] expressions = {
+ "qm:testcase",
+ "*",
+ "oslc:create,qm:verified",
+ "qm:state{oslc:verified_by{oslc:owner,qm:duration}}",
+ "qm:submitted{*}"
+ };
+
+ for (String expression : expressions) {
+
+ OslcSelectParser parser = new OslcSelectParser(expression);
+
+ try {
+ OslcSelectParser.oslc_select_return resultTree =
+ parser.oslc_select();
+
+ CommonTree rawTree = (CommonTree)resultTree.getTree();
+ SelectClause selectClause;
+
+ if (rawTree.getType() == OslcSelectParser.PROPERTIES) {
+ selectClause = (SelectClause)
+ Proxy.newProxyInstance(SelectClause.class.getClassLoader(),
+ new Class<?>[] { SelectClause.class, PropertyList.class },
+ new PropertyListInvocationHandler(
+ (CommonTree)resultTree.getTree(),
+ prefixMap));
+ } else {
+ selectClause = (SelectClause)
+ Proxy.newProxyInstance(SelectClause.class.getClassLoader(),
+ new Class<?>[] { SelectClause.class, Wildcard.class },
+ new WildcardInvocationHandler());
+ }
+
+ System.out.println(selectClause.toString());
+
+ } catch (RecognitionException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+}