summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Pitschke2012-06-26 18:47:32 (EDT)
committer Steve Pitschke2012-06-26 18:47:32 (EDT)
commit6435ecf36f5da7ddc1e7d250554d7fe54121c8bf (patch)
tree661bc8e78f45c0ce8da40e5856869629f2248372
parentbeaea6cf31b8eccf3a87f68d127b6ea5d931823f (diff)
downloadorg.eclipse.lyo.core-6435ecf36f5da7ddc1e7d250554d7fe54121c8bf.zip
org.eclipse.lyo.core-6435ecf36f5da7ddc1e7d250554d7fe54121c8bf.tar.gz
org.eclipse.lyo.core-6435ecf36f5da7ddc1e7d250554d7fe54121c8bf.tar.bz2
Bug 383469 - Initial Query APIs for oslc.where clauserefs/changes/22/6522/1
Change-Id: Ibfc91eb259589c8cb5a8c7e61ca9999bc1c83d22 Signed-off-by: Steve Pitschke <pitschke@us.ibm.com>
-rw-r--r--org.eclipse.lyo.core.query/.classpath9
-rw-r--r--org.eclipse.lyo.core.query/.gitignore1
-rw-r--r--org.eclipse.lyo.core.query/.project39
-rw-r--r--org.eclipse.lyo.core.query/.settings/org.eclipse.jdt.core.prefs6
-rw-r--r--org.eclipse.lyo.core.query/.settings/org.eclipse.m2e.core.prefs5
-rw-r--r--org.eclipse.lyo.core.query/pom.xml103
-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.g230
-rw-r--r--org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcWhere.g313
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/BooleanValue.java24
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/ComparisonTerm.java58
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/CompoundTerm.java33
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/DecimalValue.java28
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/InTerm.java30
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/LangedStringValue.java26
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/PName.java25
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/SimpleTerm.java39
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/StringValue.java25
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/TypedValue.java26
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/UriRefValue.java25
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Value.java36
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/WhereClause.java24
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/BooleanValueInvocationHandler.java67
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/ComparisonTermInvocationHandler.java163
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/CompoundTermInvocationHandler.java124
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/DecimalValueInvocationHandler.java63
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/InTermInvocationHandler.java84
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/LangedStringValueInvocationHandler.java77
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/SimpleTermInvocationHandler.java90
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/StringValueInvocationHandler.java71
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/TypedValueInvocationHandler.java100
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/UriRefValueInvocationHandler.java71
-rw-r--r--org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/ValueInvocationHandler.java56
-rw-r--r--org.eclipse.lyo.core.query/src/test/java/org/eclipse/lyo/core/query/test/BasicWhereTest.java147
34 files changed, 2311 insertions, 0 deletions
diff --git a/org.eclipse.lyo.core.query/.classpath b/org.eclipse.lyo.core.query/.classpath
new file mode 100644
index 0000000..c810a56
--- /dev/null
+++ b/org.eclipse.lyo.core.query/.classpath
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="src" path="target/generated-sources/antlr3"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/org.eclipse.lyo.core.query/.gitignore b/org.eclipse.lyo.core.query/.gitignore
new file mode 100644
index 0000000..c2c4a5a
--- /dev/null
+++ b/org.eclipse.lyo.core.query/.gitignore
@@ -0,0 +1 @@
+target/** \ No newline at end of file
diff --git a/org.eclipse.lyo.core.query/.project b/org.eclipse.lyo.core.query/.project
new file mode 100644
index 0000000..2eaab78
--- /dev/null
+++ b/org.eclipse.lyo.core.query/.project
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.lyo.core.query</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.antlr.eclipse.core.antlrbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.antlr.eclipse.core.warningcleanerbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.antlr.eclipse.core.smapbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>org.antlr.eclipse.core.antlrnature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.lyo.core.query/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.lyo.core.query/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..b230318
--- /dev/null
+++ b/org.eclipse.lyo.core.query/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,6 @@
+#Tue Jun 26 17:34:35 EDT 2012
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
diff --git a/org.eclipse.lyo.core.query/.settings/org.eclipse.m2e.core.prefs b/org.eclipse.lyo.core.query/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..caafb39
--- /dev/null
+++ b/org.eclipse.lyo.core.query/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,5 @@
+#Tue Jun 26 13:33:19 EDT 2012
+resolveWorkspaceProjects=true
+version=1
+activeProfiles=
+eclipse.preferences.version=1
diff --git a/org.eclipse.lyo.core.query/pom.xml b/org.eclipse.lyo.core.query/pom.xml
new file mode 100644
index 0000000..ab96b45
--- /dev/null
+++ b/org.eclipse.lyo.core.query/pom.xml
@@ -0,0 +1,103 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.eclipse.lyo.core.query</groupId>
+ <artifactId>org.eclipse.lyo.core.query</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr-runtime</artifactId>
+ <version>3.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.6.4</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <outputDirectory>target/classes</outputDirectory>
+
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ </testResource>
+ </testResources>
+
+ <plugins>
+
+ <plugin>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr3-maven-plugin</artifactId>
+ <version>3.2</version>
+ <configuration>
+ <verbose>true</verbose>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>antlr</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- ********************************************** -->
+ <!-- Compiler Plugin -->
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+
+ </plugins>
+
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.antlr</groupId>
+ <artifactId>
+ antlr3-maven-plugin
+ </artifactId>
+ <versionRange>
+ [3.2,)
+ </versionRange>
+ <goals>
+ <goal>antlr</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <execute></execute>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+</project> \ No newline at end of file
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
new file mode 100644
index 0000000..d133ed2
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcProperty.g
@@ -0,0 +1,93 @@
+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
new file mode 100644
index 0000000..0522b1c
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcSelect.g
@@ -0,0 +1,230 @@
+grammar OslcSelect;
+
+options {
+ output=AST;
+ ASTLabelType=CommonTree;
+}
+
+tokens {
+ PROPERTIES = 'properties';
+ NESTED_PROPERTIES = 'nested_property';
+ PREFIXED_NAME = 'prefixed_name';
+ WILDCARD = 'wildcard';
+}
+
+@header {
+package org.eclipse.lyo.core.query;
+}
+
+@lexer::header
+{
+package org.eclipse.lyo.core.query;
+}
+
+@members {
+ private List<String> errors = new ArrayList<String>();
+ public void displayRecognitionError(String[] tokenNames,
+ RecognitionException e) {
+ String hdr = getErrorHeader(e);
+ String msg = getErrorMessage(e, tokenNames);
+ errors.add(hdr + " " + msg);
+ }
+ public List<String> getErrors() {
+ return errors;
+ }
+}
+
+oslc_select : properties
+ ;
+
+property : identifier | nested_property
+ ;
+
+property_list : property ( ',' property )* -> ^( 'properties' property (property)* )
+ ;
+
+properties : ( wildcard | property_list )
+ ;
+
+nested_property : identifier OPEN_CURLY_BRACE properties CLOSE_CURLY_BRACE -> ^( 'nested_property' identifier properties )
+ ;
+
+identifier : prefixedName -> ^( 'prefixed_name' prefixedName )
+ ;
+
+wildcard : ASTERISK -> ^( 'wildcard' ASTERISK )
+ ;
+
+uri_ref_esc : '<' iriRef '>';
+
+string_esc : STRING_LITERAL ;
+
+iriRef
+ : IRI_REF
+ | prefixedName
+ ;
+
+prefixedName
+ : PNAME_LN
+ | PNAME_NS
+ ;
+
+
+// $>
+
+// $<Lexer
+
+
+WS
+ : (' '| '\t'| EOL)+ { $channel=HIDDEN; }
+ ;
+
+PNAME_NS
+ : p=PN_PREFIX? ':'
+ ;
+
+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' | '\\' | '"' | '\'')
+ ;
+
+fragment
+PN_CHARS_U
+ : PN_CHARS_BASE | '_'
+ ;
+
+fragment
+VARNAME
+ : ( PN_CHARS_U | DIGIT ) ( PN_CHARS_U | DIGIT | '\u00B7' | '\u0300'..'\u036F' | '\u203F'..'\u2040' )*
+ ;
+
+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
+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
+DIGIT
+ : '0'..'9'
+ ;
+
+fragment
+EOL
+ : '\n' | '\r'
+ ;
+
+OPEN_CURLY_BRACE
+ : '{'
+ ;
+
+CLOSE_CURLY_BRACE
+ : '}'
+ ;
+
+OPEN_SQUARE_BRACE
+ : '['
+ ;
+
+CLOSE_SQUARE_BRACE
+ : ']'
+ ;
+
+SEMICOLON
+ : ';'
+ ;
+
+DOT
+ : '.'
+ ;
+
+PLUS
+ : '+'
+ ;
+
+MINUS
+ : '-'
+ ;
+
+ASTERISK
+ : '*'
+ ;
+
+COMMA
+ : ','
+ ;
+
+NOT
+ : '!'
+ ;
+
+DIVIDE
+ : '/'
+ ;
+
+EQUAL
+ : '='
+ ;
+
+LESS
+ : '<'
+ ;
+
+GREATER
+ : '>'
+ ;
+
+ANY : .
+ ;
+
+// $>
diff --git a/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcWhere.g b/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcWhere.g
new file mode 100644
index 0000000..e522e32
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/antlr3/org/eclipse/lyo/core/query/OslcWhere.g
@@ -0,0 +1,313 @@
+grammar OslcWhere;
+
+options {
+ output=AST;
+ ASTLabelType=CommonTree;
+}
+
+tokens {
+ SIMPLE_TERM = 'simple_term';
+ IN_TERM = 'in_term';
+ COMPOUND_TERM = 'compound_term';
+ TERMS = 'terms';
+ TYPED_VALUE = 'typed_value';
+ LANGED_VALUE = 'langed_value';
+ IN_VALUES = 'in_values';
+}
+
+@header {
+package org.eclipse.lyo.core.query;
+}
+
+@lexer::header
+{
+package org.eclipse.lyo.core.query;
+}
+
+@members {
+ private List<String> errors = new ArrayList<String>();
+ public void displayRecognitionError(String[] tokenNames,
+ RecognitionException e) {
+ String hdr = getErrorHeader(e);
+ String msg = getErrorMessage(e, tokenNames);
+ errors.add(hdr + " " + msg);
+ }
+ public List<String> getErrors() {
+ return errors;
+ }
+ public OslcWhereParser(String where)
+ {
+ this(new CommonTokenStream(new OslcWhereLexer(new ANTLRStringStream(where))));
+ }
+}
+
+
+oslc_where : compound_term
+ ;
+
+compound_term : simple_term ( boolean_op simple_term)* -> ^( 'terms' simple_term (simple_term)* )
+ ;
+
+simple_term : term | scoped_term
+ ;
+
+space : ' '! ;
+
+boolean_op : ' and '! ;
+
+term : term_simple | in_term ;
+
+term_simple
+ : identifier_wc comparison_op value -> ^( 'simple_term' identifier_wc comparison_op value )
+ ;
+
+in_term : identifier_wc in_op space? in_val -> ^( 'in_term' identifier_wc in_val )
+ ;
+
+
+scoped_term : identifier_wc '{' compound_term '}' -> ^( 'compound_term' identifier_wc compound_term )
+ ;
+
+identifier_wc : identifier | wildcard ;
+
+identifier : prefixedName ;
+
+wildcard : ASTERISK ;
+
+comparison_op : '=' | '!=' | '<' | '>' | '<=' | '>=' ;
+
+in_op : ' in' ;
+
+in_val : '[' value (',' value)* ']' -> ^( 'in_values' value (value)* )
+ ;
+
+value : iriRef | literal_value ;
+
+literal_value : boolean_val | decimal | string_esc | typed_string | langed_string
+ ;
+
+typed_string
+ : string_esc ( '^^' prefixedName ) -> ^( 'typed_value' string_esc prefixedName? )
+ ;
+
+langed_string
+ : string_esc LANGTAG -> ^( 'langed_value' string_esc LANGTAG )
+ ;
+
+
+boolean_val : BOOLEAN ;
+
+decimal : DECIMAL ;
+
+string_esc : STRING_LITERAL ;
+
+properties :
+ property (',' property )*
+ ;
+
+property :
+ prefixedName ( nested_property )*
+ ;
+
+nested_property :
+ '{' property (',' property )* '}'
+ ;
+
+iriRef
+ : IRI_REF
+ | prefixedName
+ ;
+
+prefixedName
+ : PNAME_LN
+ | PNAME_NS
+ ;
+
+
+// $>
+
+// $<Lexer
+
+
+WS
+ : (' '| '\t'| EOL)+ { $channel=HIDDEN; }
+ ;
+
+PNAME_NS
+ : p=PN_PREFIX? ':'
+ ;
+
+PNAME_LN
+ : PNAME_NS PN_LOCAL
+ ;
+
+
+IRI_REF
+ : LESS ( options {greedy=false;} : ~(LESS | GREATER | '"' | OPEN_CURLY_BRACE | CLOSE_CURLY_BRACE | '|' | '^' | '\\' | '`' | ('\u0000'..'\u0020')) )* GREATER
+ ;
+
+
+LANGTAG
+ : '@' PN_CHARS_BASE+ (MINUS (PN_CHARS_BASE DIGIT)+)?
+ ;
+
+BOOLEAN
+ : 'true'
+ | 'false'
+ ;
+
+DECIMAL
+ : (MINUS | PLUS)? DIGIT+ DOT DIGIT*
+ | (MINUS | PLUS)? DOT DIGIT+
+ ;
+
+STRING_LITERAL
+ : '"' ( options {greedy=false;} : ~('\u0022' | '\u005C' | '\u000A' | '\u000D') | ECHAR )* '"'
+ ;
+
+fragment
+ECHAR
+ : '\\' ('t' | 'b' | 'n' | 'r' | 'f' | '\\' | '"' | '\'')
+ ;
+
+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
+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
+DIGIT
+ : '0'..'9'
+ ;
+
+fragment
+EOL
+ : '\n' | '\r'
+ ;
+
+REFERENCE
+ : '^^'
+ ;
+
+LESS_EQUAL
+ : '<='
+ ;
+
+GREATER_EQUAL
+ : '>='
+ ;
+
+NOT_EQUAL
+ : '!='
+ ;
+
+AND
+ : '&&'
+ ;
+
+OR
+ : '||'
+ ;
+
+OPEN_BRACE
+ : '('
+ ;
+
+CLOSE_BRACE
+ : ')'
+ ;
+
+OPEN_CURLY_BRACE
+ : '{'
+ ;
+
+CLOSE_CURLY_BRACE
+ : '}'
+ ;
+
+OPEN_SQUARE_BRACE
+ : '['
+ ;
+
+CLOSE_SQUARE_BRACE
+ : ']'
+ ;
+
+SEMICOLON
+ : ';'
+ ;
+
+DOT
+ : '.'
+ ;
+
+PLUS
+ : '+'
+ ;
+
+MINUS
+ : '-'
+ ;
+
+ASTERISK
+ : '*'
+ ;
+
+COMMA
+ : ','
+ ;
+
+NOT
+ : '!'
+ ;
+
+EQUAL
+ : '='
+ ;
+
+LESS
+ : '<'
+ ;
+
+GREATER
+ : '>'
+ ;
+
+// $>
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/BooleanValue.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/BooleanValue.java
new file mode 100644
index 0000000..2c5e2ae
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/BooleanValue.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;
+
+/**
+ * Boolean literal operand from olsc.where clause
+ */
+public interface BooleanValue extends Value
+{
+ boolean value();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/ComparisonTerm.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/ComparisonTerm.java
new file mode 100644
index 0000000..1d1e351
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/ComparisonTerm.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Simple comparison term from oslc.where clause
+ */
+public interface ComparisonTerm extends SimpleTerm
+{
+ enum Operator
+ {
+ EQUALS,
+ NOT_EQUALS,
+ LESS_THAN,
+ GREATER_THAN,
+ LESS_EQUALS,
+ GREATER_EQUALS;
+
+ public String
+ toString()
+ {
+ switch (this)
+ {
+ case EQUALS:
+ return "=";
+ case NOT_EQUALS:
+ return "!=";
+ case LESS_THAN:
+ return "<";
+ case GREATER_THAN:
+ return ">";
+ case LESS_EQUALS:
+ return "<=";
+ default:
+ case GREATER_EQUALS:
+ return ">=";
+ }
+ }
+ };
+
+ Operator operator();
+
+ Value operand();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/CompoundTerm.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/CompoundTerm.java
new file mode 100644
index 0000000..0c002c6
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/CompoundTerm.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Compound term from oslc.where clause.<p>
+ *
+ * <b>Note:</b> If top-level compound term, {@link SimpleTerm#property()}
+ * will return <code>null</code>.
+ */
+public interface CompoundTerm extends SimpleTerm
+{
+ /**
+ * @return immutable list of child simple terms
+ */
+ List<SimpleTerm> children();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/DecimalValue.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/DecimalValue.java
new file mode 100644
index 0000000..92c95e8
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/DecimalValue.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Decimal literal operand from olsc.where clause.<p>
+ *
+ * Not converted to any Java native class as only clients of this
+ * interface can convert to native DB field values without losing
+ * precision.
+ */
+public interface DecimalValue extends Value
+{
+ String value();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/InTerm.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/InTerm.java
new file mode 100644
index 0000000..afdf597
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/InTerm.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;
+
+import java.util.List;
+
+/**
+ * <i>in</i> operator simple term from olsc.where clause
+ */
+public interface InTerm extends SimpleTerm
+{
+ /**
+ * @return immutable list of values
+ */
+ List<Value> values();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/LangedStringValue.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/LangedStringValue.java
new file mode 100644
index 0000000..c92f799
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/LangedStringValue.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;
+
+/**
+ * Language specified string value operand from oslc.where clause
+ */
+public interface LangedStringValue extends Value
+{
+ String value();
+
+ String langTag();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/PName.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/PName.java
new file mode 100644
index 0000000..70e46e7
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/PName.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ *
+ * Jim Conallen - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.lyo.core.query;
+
+public class PName {
+ public String namespace;
+ public String prefix;
+ public String local;
+ public String toString(){
+ return prefix + ':' + local;
+ }
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/SimpleTerm.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/SimpleTerm.java
new file mode 100644
index 0000000..b96f385
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/SimpleTerm.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * simple term from oslc.where clause
+ */
+public interface SimpleTerm
+{
+ enum Type
+ {
+ COMPARISON,
+ IN_TERM,
+ NESTED,
+ TOP_LEVEL;
+ }
+
+ Type type();
+
+ /**
+ * @return type of simple term. When {@link CompoundTerm}
+ * return <code>null</code>.
+ */
+ PName property();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/StringValue.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/StringValue.java
new file mode 100644
index 0000000..1f08201
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/StringValue.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * String literal operand from olsc.where clause
+ */
+public interface StringValue extends Value
+{
+ String value();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/TypedValue.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/TypedValue.java
new file mode 100644
index 0000000..8f12cc1
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/TypedValue.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;
+
+/**
+ * Typed value operand from oslc.where clause
+ */
+public interface TypedValue extends Value
+{
+ String value();
+
+ PName prefixedName();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/UriRefValue.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/UriRefValue.java
new file mode 100644
index 0000000..c3a673d
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/UriRefValue.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * URI_REF operand from oslc.where clause
+ */
+public interface UriRefValue extends Value
+{
+ PName value();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Value.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Value.java
new file mode 100644
index 0000000..8ce5e32
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/Value.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Operand from {@link ComparisonTerm} or {@link InTerm}
+ * {@link SimpleTerm} from olsc.where clause
+ */
+public interface Value
+{
+ enum Type
+ {
+ URI_REF,
+ BOOLEAN,
+ DECIMAL,
+ STRING,
+ TYPED_STRING,
+ LANGED_STRING;
+ }
+
+ Type type();
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/WhereClause.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/WhereClause.java
new file mode 100644
index 0000000..4901e06
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/WhereClause.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;
+
+/**
+ * Top-level {@link ComparisonTerm} from olsc.where clause
+ */
+public interface WhereClause
+{
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/BooleanValueInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/BooleanValueInvocationHandler.java
new file mode 100644
index 0000000..27d402d
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/BooleanValueInvocationHandler.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.antlr.runtime.tree.CommonTree;
+import org.eclipse.lyo.core.query.BooleanValue;
+import org.eclipse.lyo.core.query.Value.Type;
+
+/**
+ * Proxy implementation of {@link BooleanValue} interface
+ */
+class BooleanValueInvocationHandler extends ValueInvocationHandler
+{
+ public
+ BooleanValueInvocationHandler(CommonTree tree)
+ {
+ super(tree, Type.BOOLEAN);
+ }
+
+ /**
+ * @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("toString")) {
+ super.invoke(proxy, method, args);
+ }
+
+ if (value == null) {
+ value = Boolean.valueOf(tree.getText());
+ }
+
+ if (isValue) {
+ return value;
+ }
+
+ return value.toString();
+ }
+
+ private Boolean value = null;
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/ComparisonTermInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/ComparisonTermInvocationHandler.java
new file mode 100644
index 0000000..e0e125f
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/ComparisonTermInvocationHandler.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * 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.BooleanValue;
+import org.eclipse.lyo.core.query.ComparisonTerm;
+import org.eclipse.lyo.core.query.ComparisonTerm.Operator;
+import org.eclipse.lyo.core.query.DecimalValue;
+import org.eclipse.lyo.core.query.LangedStringValue;
+import org.eclipse.lyo.core.query.OslcWhereParser;
+import org.eclipse.lyo.core.query.SimpleTerm.Type;
+import org.eclipse.lyo.core.query.StringValue;
+import org.eclipse.lyo.core.query.TypedValue;
+import org.eclipse.lyo.core.query.UriRefValue;
+import org.eclipse.lyo.core.query.Value;
+
+/**
+ * Proxy implmentation of {@link ComparisonTerm} interface
+ */
+class ComparisonTermInvocationHandler extends SimpleTermInvocationHandler
+{
+ public
+ ComparisonTermInvocationHandler(
+ CommonTree tree,
+ Map<String, String> prefixMap
+ )
+ {
+ super(tree, Type.COMPARISON, prefixMap);
+
+ switch (((CommonTree)tree.getChild(1)).getType()) {
+ case OslcWhereParser.EQUAL:
+ operator = Operator.EQUALS;
+ break;
+ case OslcWhereParser.NOT_EQUAL:
+ operator = Operator.NOT_EQUALS;
+ break;
+ case OslcWhereParser.LESS:
+ operator = Operator.LESS_THAN;
+ break;
+ case OslcWhereParser.LESS_EQUAL:
+ operator = Operator.LESS_EQUALS;
+ break;
+ case OslcWhereParser.GREATER:
+ operator = Operator.GREATER_THAN;
+ break;
+ default:
+ case OslcWhereParser.GREATER_EQUAL:
+ operator = Operator.GREATER_EQUALS;
+ break;
+ }
+ }
+
+ /**
+ * @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();
+
+ if (methodName.equals("operator")) {
+ return operator;
+ }
+
+ if (! methodName.equals("operand")) {
+ return super.invoke(proxy, method, args);
+ }
+
+ if (operand == null) {
+
+ CommonTree treeOperand = (CommonTree)tree.getChild(2);
+
+ operand = createValue(treeOperand, "unspported literal value type",
+ prefixMap);
+ }
+
+ return operand;
+ }
+
+ static Value
+ createValue(
+ CommonTree treeOperand,
+ String errorPrefix,
+ Map<String, String> prefixMap
+ )
+ {
+ switch (treeOperand.getToken().getType()) {
+ case OslcWhereParser.IRI_REF:
+ return
+ (Value)Proxy.newProxyInstance(
+ UriRefValue.class.getClassLoader(),
+ new Class<?>[] { UriRefValue.class },
+ new UriRefValueInvocationHandler(
+ treeOperand));
+ case OslcWhereParser.BOOLEAN:
+ return
+ (Value)Proxy.newProxyInstance(
+ BooleanValue.class.getClassLoader(),
+ new Class<?>[] { BooleanValue.class },
+ new BooleanValueInvocationHandler(
+ treeOperand));
+ case OslcWhereParser.DECIMAL:
+ return
+ (Value)Proxy.newProxyInstance(
+ DecimalValue.class.getClassLoader(),
+ new Class<?>[] { DecimalValue.class },
+ new DecimalValueInvocationHandler(
+ treeOperand));
+ case OslcWhereParser.STRING_LITERAL:
+ return
+ (Value)Proxy.newProxyInstance(
+ StringValue.class.getClassLoader(),
+ new Class<?>[] { StringValue.class },
+ new StringValueInvocationHandler(
+ treeOperand));
+ case OslcWhereParser.TYPED_VALUE:
+ return
+ (Value)Proxy.newProxyInstance(
+ TypedValue.class.getClassLoader(),
+ new Class<?>[] { TypedValue.class },
+ new TypedValueInvocationHandler(
+ treeOperand, prefixMap));
+ case OslcWhereParser.LANGED_VALUE:
+ return
+ (Value)Proxy.newProxyInstance(
+ LangedStringValue.class.getClassLoader(),
+ new Class<?>[] { LangedStringValue.class },
+ new LangedStringValueInvocationHandler(
+ treeOperand));
+ default:
+ throw new IllegalStateException(
+ errorPrefix + ": " +
+ treeOperand.getToken().getText());
+ }
+ }
+
+ private final Operator operator;
+ private Value operand = null;
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/CompoundTermInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/CompoundTermInvocationHandler.java
new file mode 100644
index 0000000..f25a2a4
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/CompoundTermInvocationHandler.java
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * 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.ComparisonTerm;
+import org.eclipse.lyo.core.query.CompoundTerm;
+import org.eclipse.lyo.core.query.InTerm;
+import org.eclipse.lyo.core.query.OslcWhereParser;
+import org.eclipse.lyo.core.query.SimpleTerm;
+import org.eclipse.lyo.core.query.SimpleTerm.Type;
+
+/**
+ * Proxy implementation of {@link CompoundTerm} interface
+ */
+public class CompoundTermInvocationHandler extends SimpleTermInvocationHandler
+{
+ public
+ CompoundTermInvocationHandler(
+ CommonTree tree,
+ boolean isTopLevel,
+ Map<String, String> prefixMap
+ )
+ {
+ super(isTopLevel ? null : tree,
+ isTopLevel ? Type.TOP_LEVEL : Type.NESTED,
+ prefixMap);
+
+ this.tree = tree;
+ this.isTopLevel = isTopLevel;
+ }
+
+ /**
+ * @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("children")) {
+ return super.invoke(proxy, method, args);
+ }
+
+ if (children != null) {
+ return children;
+ }
+
+ @SuppressWarnings("unchecked")
+ List<CommonTree> treeChildren =
+ isTopLevel ?
+ tree.getChildren() :
+ ((CommonTree)tree.getChild(1)).getChildren();
+
+ children =
+ new ArrayList<SimpleTerm>(
+ treeChildren.size() - (isTopLevel ? 0 : 1));
+
+ for (CommonTree child : treeChildren) {
+
+ Object simpleTerm;
+
+ switch(child.getToken().getType()) {
+ case OslcWhereParser.SIMPLE_TERM:
+ simpleTerm =
+ Proxy.newProxyInstance(ComparisonTerm.class.getClassLoader(),
+ new Class<?>[] { ComparisonTerm.class },
+ new ComparisonTermInvocationHandler(
+ child, prefixMap));
+ break;
+ case OslcWhereParser.IN_TERM:
+ simpleTerm =
+ Proxy.newProxyInstance(InTerm.class.getClassLoader(),
+ new Class<?>[] { InTerm.class },
+ new InTermInvocationHandler(
+ child, prefixMap));
+ break;
+ case OslcWhereParser.COMPOUND_TERM:
+ simpleTerm =
+ Proxy.newProxyInstance(CompoundTerm.class.getClassLoader(),
+ new Class<?>[] { CompoundTerm.class },
+ new CompoundTermInvocationHandler(
+ child, false, prefixMap));
+ break;
+ default:
+ throw new IllegalStateException("unimplemented type of simple term: " + child.getToken().getText());
+ }
+
+ children.add((SimpleTerm)simpleTerm);
+ }
+
+ children = Collections.unmodifiableList(children);
+
+ return children;
+ }
+
+ private final CommonTree tree;
+ private final boolean isTopLevel;
+ private List<SimpleTerm> children = null;
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/DecimalValueInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/DecimalValueInvocationHandler.java
new file mode 100644
index 0000000..429c133
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/DecimalValueInvocationHandler.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.antlr.runtime.tree.CommonTree;
+import org.eclipse.lyo.core.query.DecimalValue;
+import org.eclipse.lyo.core.query.Value.Type;
+
+/**
+ * Proxy implementation of {@link DecimalValue} interface
+ */
+class DecimalValueInvocationHandler extends ValueInvocationHandler
+{
+ public
+ DecimalValueInvocationHandler(CommonTree tree)
+ {
+ super(tree, Type.DECIMAL);
+ }
+
+ /**
+ * @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("toString")) {
+ super.invoke(proxy, method, args);
+ }
+
+ if (value == null) {
+ value = tree.getText();
+ }
+
+ return value;
+ }
+
+ private String value = null;
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/InTermInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/InTermInvocationHandler.java
new file mode 100644
index 0000000..50ff157
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/InTermInvocationHandler.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * 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.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.InTerm;
+import org.eclipse.lyo.core.query.SimpleTerm.Type;
+import org.eclipse.lyo.core.query.Value;
+
+/**
+ * Proxy implementation of {@link InTerm} interface
+ */
+class InTermInvocationHandler extends SimpleTermInvocationHandler
+{
+ public
+ InTermInvocationHandler(
+ CommonTree tree,
+ Map<String, String> prefixMap
+ )
+ {
+ super(tree, Type.IN_TERM, 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("values")) {
+ return super.invoke(proxy, method, args);
+ }
+
+ if (values == null) {
+
+ @SuppressWarnings("unchecked")
+ List<CommonTree> treeValues =
+ ((CommonTree)tree.getChild(1)).getChildren();
+
+ values = new ArrayList<Value>(treeValues.size() - 1);
+
+ for (CommonTree treeValue : treeValues) {
+
+ Value value =
+ ComparisonTermInvocationHandler.createValue(
+ treeValue, "unspported literal value type",
+ prefixMap);
+
+ values.add(value);
+ }
+
+ values = Collections.unmodifiableList(values);
+ }
+
+ return values;
+ }
+
+ private List<Value> values = null;
+}
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
new file mode 100644
index 0000000..7debee1
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/LangedStringValueInvocationHandler.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.antlr.runtime.tree.CommonTree;
+import org.eclipse.lyo.core.query.LangedStringValue;
+import org.eclipse.lyo.core.query.Value.Type;
+
+/**
+ * Proxy implementation of {@link LangedStringValue} interface
+ */
+class LangedStringValueInvocationHandler extends ValueInvocationHandler
+{
+ public
+ LangedStringValueInvocationHandler(CommonTree tree)
+ {
+ super(tree, Type.LANGED_STRING);
+ }
+
+ /**
+ * @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("langTag")) {
+ 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 (langTag == null) {
+ langTag = ((CommonTree)tree.getChild(1)).getText().substring(1);
+ }
+
+ return langTag;
+ }
+
+ private String value = null;
+ private String langTag = null;
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/SimpleTermInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/SimpleTermInvocationHandler.java
new file mode 100644
index 0000000..8d8438f
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/SimpleTermInvocationHandler.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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.SimpleTerm;
+import org.eclipse.lyo.core.query.SimpleTerm.Type;;
+
+/**
+ * Proxy implementation of {@link SimpleTerm} interface
+ */
+abstract class SimpleTermInvocationHandler implements InvocationHandler
+{
+ protected
+ SimpleTermInvocationHandler(
+ 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[])
+ */
+ public Object
+ invoke(
+ Object proxy,
+ Method method,
+ Object[] args
+ ) throws Throwable
+ {
+ if (method.getName().equals("type")) {
+ return type;
+ }
+
+ if (property != null) {
+ return property;
+ }
+
+ if (tree == null) {
+ return null;
+ }
+
+ String rawProperty = tree.getChild(0).toString();
+
+ property = new PName();
+
+ int colon = rawProperty.indexOf(':');
+
+ if (colon < 0) {
+ property.local = rawProperty;
+ } else {
+ if (colon > 0) {
+ property.prefix = rawProperty.substring(0, colon);
+ property.namespace = prefixMap.get(property.prefix);
+ }
+ property.local = rawProperty.substring(colon + 1);
+ }
+
+ return property;
+ }
+
+ protected final CommonTree tree;
+ protected final Map<String, String> prefixMap;
+ private final Type type;
+ private PName property = null;
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/StringValueInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/StringValueInvocationHandler.java
new file mode 100644
index 0000000..de34926
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/StringValueInvocationHandler.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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.antlr.runtime.tree.CommonTree;
+import org.eclipse.lyo.core.query.StringValue;
+import org.eclipse.lyo.core.query.Value.Type;
+
+/**
+ * Proxy implementation of {@link StringValue} interface
+ */
+class StringValueInvocationHandler extends ValueInvocationHandler
+{
+ public
+ StringValueInvocationHandler(CommonTree tree)
+ {
+ super(tree, Type.STRING);
+ }
+
+ /**
+ * @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("toString")) {
+ super.invoke(proxy, method, args);
+ }
+
+ if (value == null) {
+
+ String rawValue = tree.getText();
+
+ // XXX - determine if need to unescape
+ value = rawValue.substring(1, rawValue.length() - 1);
+ }
+
+ if (isValue) {
+ return value;
+ }
+
+ return '"' + value + '"';
+ }
+
+ private String value = null;
+}
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
new file mode 100644
index 0000000..d004aef
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/TypedValueInvocationHandler.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * 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")) {
+ super.invoke(proxy, method, args);
+ }
+
+ if (isValue) {
+
+ if (value == null) {
+
+ String rawValue = ((CommonTree)tree.getChild(0)).getToken().toString();
+
+ // XXX - determine if need to unescape
+ value = rawValue.substring(1, rawValue.length() - 1);
+ }
+
+ return value;
+ }
+
+ if (prefixedName == null) {
+
+ String rawPName = tree.getChild(1).toString();
+
+ 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);
+ }
+ }
+
+ return prefixedName;
+ }
+
+ private final Map<String, String> prefixMap;
+ private String value = null;
+ private PName prefixedName = null;
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/UriRefValueInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/UriRefValueInvocationHandler.java
new file mode 100644
index 0000000..62c6f8b
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/UriRefValueInvocationHandler.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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.antlr.runtime.tree.CommonTree;
+import org.eclipse.lyo.core.query.UriRefValue;
+import org.eclipse.lyo.core.query.Value.Type;
+
+/**
+ * Proxy implementation of {@link UriRefValue} interface
+ */
+class UriRefValueInvocationHandler extends ValueInvocationHandler
+{
+ public
+ UriRefValueInvocationHandler(CommonTree tree)
+ {
+ super(tree, Type.URI_REF);
+ }
+
+ /**
+ * @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("toString")) {
+ super.invoke(proxy, method, args);
+ }
+
+ if (value == null) {
+
+ String rawValue = tree.getText();
+
+ // XXX - determine if need to unescape
+ value = rawValue.substring(1, rawValue.length() - 1);
+ }
+
+ if (isValue) {
+ return value;
+ }
+
+ return '<' + value + '>';
+ }
+
+ private String value = null;
+}
diff --git a/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/ValueInvocationHandler.java b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/ValueInvocationHandler.java
new file mode 100644
index 0000000..219f0f4
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/main/java/org/eclipse/lyo/core/query/impl/ValueInvocationHandler.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * 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.antlr.runtime.tree.CommonTree;
+import org.eclipse.lyo.core.query.Value;
+import org.eclipse.lyo.core.query.Value.Type;
+
+/**
+ * Proxy implementation of {@link Value} interface
+ */
+abstract class ValueInvocationHandler implements InvocationHandler
+{
+ protected
+ ValueInvocationHandler(
+ CommonTree tree,
+ Type type
+ )
+ {
+ this.tree = tree;
+ this.type = type;
+ }
+
+ /**
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ public Object
+ invoke(
+ Object proxy,
+ Method method,
+ Object[] args
+ ) throws Throwable
+ {
+ return type;
+ }
+
+ protected final CommonTree tree;
+ private final Type type;
+}
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
new file mode 100644
index 0000000..c270112
--- /dev/null
+++ b/org.eclipse.lyo.core.query/src/test/java/org/eclipse/lyo/core/query/test/BasicWhereTest.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * 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.List;
+import java.util.Map;
+
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.tree.CommonTree;
+import org.eclipse.lyo.core.query.ComparisonTerm;
+import org.eclipse.lyo.core.query.CompoundTerm;
+import org.eclipse.lyo.core.query.InTerm;
+import org.eclipse.lyo.core.query.OslcWhereParser;
+import org.eclipse.lyo.core.query.SimpleTerm;
+import org.eclipse.lyo.core.query.Value;
+import org.eclipse.lyo.core.query.WhereClause;
+import org.eclipse.lyo.core.query.impl.CompoundTermInvocationHandler;
+
+/**
+ * @author pitschke
+ *
+ */
+public class BasicWhereTest
+{
+
+ /**
+ * @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=<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\""
+ };
+
+ for (String expression : expressions) {
+
+ OslcWhereParser parser = new OslcWhereParser(expression);
+
+ try {
+ OslcWhereParser.oslc_where_return resultTree =
+ parser.oslc_where();
+
+ CompoundTerm whereClause = (CompoundTerm)
+ Proxy.newProxyInstance(CompoundTerm.class.getClassLoader(),
+ new Class<?>[] { CompoundTerm.class, WhereClause.class },
+ new CompoundTermInvocationHandler(
+ (CommonTree)resultTree.getTree(), true,
+ prefixMap));
+
+ System.out.println("Is where: " + (whereClause instanceof WhereClause));
+
+ dumpCompound(whereClause);
+
+ System.out.println();
+
+ } catch (RecognitionException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static void
+ dumpCompound(CompoundTerm compoundTerm)
+ {
+ List<SimpleTerm> children = compoundTerm.children();
+ boolean first = true;
+
+ for (SimpleTerm term : children) {
+
+ if (first) {
+ first = false;
+ } else {
+ System.out.print(" and ");
+ }
+
+ System.out.print(term.property().toString());
+
+ switch (term.type()) {
+ case COMPARISON:
+ {
+ ComparisonTerm compTerm = (ComparisonTerm)term;
+
+ System.out.print(compTerm.operator().toString());
+ System.out.print(compTerm.operand().toString());
+ }
+ break;
+ case IN_TERM:
+ {
+ System.out.print(" in [");
+
+ InTerm inTerm = (InTerm)term;
+ boolean firstValue = true;
+
+ for (Value value : inTerm.values()) {
+
+ if (firstValue) {
+ firstValue = false;
+ } else {
+ System.out.print(',');
+ }
+
+ System.out.print(value.toString());
+ }
+
+ System.out.print(']');
+ }
+ break;
+ case NESTED:
+ {
+ System.out.print('{');
+
+ dumpCompound((CompoundTerm)term);
+
+ System.out.print('}');
+ }
+ break;
+ default:
+ throw new IllegalStateException("unknown simple term type");
+ }
+ }
+ }
+}