chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1444504 [1/2] - in /chemistry/opencmis/trunk: chemistry-opencmis-samples/chemistry-opencmis-queryparser/ chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/ chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/ che...
Date Sun, 10 Feb 2013 08:24:29 GMT
Author: jens
Date: Sun Feb 10 08:24:28 2013
New Revision: 1444504

URL: http://svn.apache.org/r1444504
Log:
Add an example for a query parser to opencmis 

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/pom.xml
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleQueryProcessor.java
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleQueryWalker.java
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleTypeManager.java
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExtendedAbstractPredicateWalker.java
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/org/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/org/apache/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/org/apache/chemistry/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/org/apache/chemistry/opencmis/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/org/apache/chemistry/opencmis/query/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/org/apache/chemistry/opencmis/query/example/
    chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/org/apache/chemistry/opencmis/query/example/ExampleQueryProcessorTest.java
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/AbstractQueryConditionProcessor.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/query/ProcessQueryTest.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractPredicateWalker.java

Added: chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/pom.xml
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/pom.xml?rev=1444504&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/pom.xml (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/pom.xml Sun Feb 10 08:24:28 2013
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Licensed under the Apache License, Version 2.0 (the "License"); you 
+ may not use this file except in compliance with the License. You may obtain 
+ a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless 
+ required by applicable law or agreed to in writing, software distributed 
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 
+ OR CONDITIONS OF ANY KIND, either express or implied. See the License for 
+ the specific language governing permissions and limitations under the License. -->
+
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.chemistry.opencmis</groupId>
+        <artifactId>chemistry-opencmis</artifactId>
+        <version>0.9.0-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <!-- Project Information -->
+
+    <artifactId>chemistry-opencmis-queryparser-example</artifactId>
+    <name>Apache Chemistry OpenCMIS Query Parser Example</name>
+    
+    <packaging>jar</packaging>
+    
+    <properties>
+        <parentBasedir>../../</parentBasedir>
+    </properties>
+    
+    <build>
+        <plugins>
+
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>chemistry-opencmis-server-support</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+</project>

Added: chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleQueryProcessor.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleQueryProcessor.java?rev=1444504&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleQueryProcessor.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleQueryProcessor.java Sun Feb 10 08:24:28 2013
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.query.example;
+
+import java.util.List;
+import java.util.Map;
+
+import org.antlr.runtime.RecognitionException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+import org.apache.chemistry.opencmis.server.support.TypeManager;
+import org.apache.chemistry.opencmis.server.support.query.CmisSelector;
+import org.apache.chemistry.opencmis.server.support.query.FunctionReference;
+import org.apache.chemistry.opencmis.server.support.query.QueryObject;
+import org.apache.chemistry.opencmis.server.support.query.QueryUtilStrict;
+
+public class ExampleQueryProcessor {
+    
+    public static void main(String[] args) {
+        String query = "SELECT cmis:name AS name, cmis:objectTypeId, SCORE() FROM cmis:document WHERE cmis:name LIKE 'My%'";
+        ExampleQueryProcessor processor = new ExampleQueryProcessor();
+        System.out.println("Original CMISQL query: " + query);
+        String response = processor.parseQuery(query);
+        System.out.println("Generated CMISQL query: " +  response);
+    }
+    
+    public String parseQuery(String queryString) {
+        StringBuffer generatedResponse = new StringBuffer();
+        ExampleQueryWalker walker = new ExampleQueryWalker();
+
+        // create type definitions, for this example we just create cmis:document
+        TypeManager typeManager = ExampleTypeManager.getInstance();
+
+        QueryUtilStrict queryUtil= new QueryUtilStrict(queryString, typeManager, walker);
+        try {
+            queryUtil.processStatement();
+            
+            QueryObject qo = queryUtil.getQueryObject();
+            String selFromPart = getSelectFromString(qo);
+            generatedResponse.append(selFromPart);
+            
+            String whereClause = walker.getResult();
+            generatedResponse.append(whereClause);
+            
+            return generatedResponse.toString();
+            
+        } catch (RecognitionException e) {
+            String message = "Syntax error in query: " + queryUtil.getErrorMessage(e);
+            System.out.println(message);
+            throw new CmisInvalidArgumentException(message, e);
+        }
+    }
+
+    private String getSelectFromString(QueryObject qo) {
+        StringBuffer result = new StringBuffer();
+        result.append("SELECT");
+        List<CmisSelector> sels = qo.getSelectReferences();
+        boolean first = true;
+        for (CmisSelector sel : sels) {
+            if (first) {
+                first = false;
+                result.append(" ");
+            } else 
+                result.append(", ");
+
+            result.append(sel.getName());
+            if (sel instanceof FunctionReference)
+                result.append("()");
+            
+            if (null != sel.getAliasName()) {
+                result.append(" AS ");
+                result.append(sel.getAliasName());
+            }                
+        }
+        
+        result.append(" FROM");
+        Map<String, String> froms = qo.getTypes();
+        first = true;
+        for(String from : froms.keySet()) {
+            if (first) {
+                first = false;
+                result.append(" ");
+            } else 
+                result.append(", ");
+            result.append(from);
+        }
+        result.append(" ");
+        return result.toString();
+    }
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleQueryWalker.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleQueryWalker.java?rev=1444504&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleQueryWalker.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleQueryWalker.java Sun Feb 10 08:24:28 2013
@@ -0,0 +1,657 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.query.example;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.antlr.runtime.tree.Tree;
+import org.apache.chemistry.opencmis.server.support.query.StringUtil;
+import org.apache.chemistry.opencmis.server.support.query.TextSearchLexer;
+
+public class ExampleQueryWalker extends ExtendedAbstractPredicateWalker {
+
+    private StringBuffer result = new StringBuffer();
+    
+    public String getResult() {
+        return result.toString();
+    }
+
+    @Override
+    public Boolean walkPredicate(Tree whereNode) {
+        if (null != whereNode) {
+            onStartProcessing(whereNode);
+            super.walkPredicate(whereNode);
+            onStopProcessing();
+        }
+        return null; // unused
+    }
+
+    @Override
+    public Boolean walkNot(Tree opNode, Tree node) {
+        onNot(opNode, node);
+        super.walkPredicate(node);
+        onPostNot(opNode, node);
+        return false;
+    }
+
+    @Override
+    public Boolean walkAnd(Tree opNode, Tree leftNode, Tree rightNode) {
+        onPreAnd(opNode, leftNode, rightNode);
+        super.walkPredicate(leftNode);
+        onAnd(opNode, leftNode, rightNode);
+        super.walkPredicate(rightNode);
+        onPostAnd(opNode, leftNode, rightNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkOr(Tree opNode, Tree leftNode, Tree rightNode) {
+        onPreOr(opNode, leftNode, rightNode);
+        super.walkPredicate(leftNode);
+        onOr(opNode, leftNode, rightNode);
+        super.walkPredicate(rightNode);
+        onPostOr(opNode, leftNode, rightNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+        onPreEquals(opNode, leftNode, rightNode);
+        super.walkPredicate(leftNode);
+        onEquals(opNode, leftNode, rightNode);
+        super.walkPredicate(rightNode);
+        onPostEquals(opNode, leftNode, rightNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkNotEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+        onPreNotEquals(opNode, leftNode, rightNode);
+        super.walkPredicate(leftNode);
+        onNotEquals(opNode, leftNode, rightNode);
+        super.walkPredicate(rightNode);
+        onPostNotEquals(opNode, leftNode, rightNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkGreaterThan(Tree opNode, Tree leftNode, Tree rightNode) {
+        onPreGreaterThan(opNode, leftNode, rightNode);
+        super.walkPredicate(leftNode);
+        onGreaterThan(opNode, leftNode, rightNode);
+        super.walkPredicate(rightNode);
+        onPostGreaterThan(opNode, leftNode, rightNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkGreaterOrEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+        onPreGreaterOrEquals(opNode, leftNode, rightNode);
+        super.walkPredicate(leftNode);
+        onGreaterOrEquals(opNode, leftNode, rightNode);
+        super.walkPredicate(rightNode);
+        onPostGreaterOrEquals(opNode, leftNode, rightNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkLessThan(Tree opNode, Tree leftNode, Tree rightNode) {
+        onPreLessThan(opNode, leftNode, rightNode);
+        super.walkPredicate(leftNode);
+        onLessThan(opNode, leftNode, rightNode);
+        super.walkPredicate(rightNode);
+        onPostLessThan(opNode, leftNode, rightNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkLessOrEquals(Tree opNode, Tree leftNode, Tree rightNode) {
+        onPreLessOrEquals(opNode, leftNode, rightNode);
+        super.walkPredicate(leftNode);
+        onLessOrEquals(opNode, leftNode, rightNode);
+        super.walkPredicate(rightNode);
+        onPostLessOrEquals(opNode, leftNode, rightNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkIn(Tree opNode, Tree colNode, Tree listNode) {
+        onPreIn(opNode, colNode, listNode);
+        super.walkPredicate(colNode);
+        onIn(opNode, colNode, listNode);
+        super.walkPredicate(listNode);
+        onPostIn(opNode, colNode, listNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkNotIn(Tree opNode, Tree colNode, Tree listNode) {
+        onPreNotIn(opNode, colNode, listNode);
+        super.walkPredicate(colNode);
+        onNotIn(opNode, colNode, listNode);
+        super.walkPredicate(listNode);
+        onPostNotIn(opNode, colNode, listNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkInAny(Tree opNode, Tree colNode, Tree listNode) {
+        onPreInAny(opNode, colNode, listNode);
+        super.walkPredicate(colNode);
+        onInAny(opNode, colNode, listNode);
+        super.walkPredicate(listNode);
+        onPostInAny(opNode, colNode, listNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkNotInAny(Tree opNode, Tree colNode, Tree listNode) {
+        onPreNotInAny(opNode, colNode, listNode);
+        super.walkPredicate(colNode);
+        onNotInAny(opNode, colNode, listNode);
+        super.walkPredicate(listNode);
+        onPostNotInAny(opNode, colNode, listNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkEqAny(Tree opNode, Tree literalNode, Tree colNode) {
+        onPreEqAny(opNode, literalNode, colNode);
+        super.walkPredicate(literalNode);
+        onEqAny(opNode, literalNode, colNode);
+        super.walkPredicate(colNode);
+        onPostEqAny(opNode, literalNode, colNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkIsNull(Tree opNode, Tree colNode) {
+        onIsNull(opNode, colNode);
+        super.walkPredicate(colNode);
+        onPostIsNull(opNode, colNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkIsNotNull(Tree opNode, Tree colNode) {
+        onIsNotNull(opNode, colNode);
+        super.walkPredicate(colNode);
+        onPostIsNotNull(opNode, colNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkLike(Tree opNode, Tree colNode, Tree stringNode) {
+        onPreIsLike(opNode, colNode, stringNode);
+        super.walkPredicate(colNode);
+        onIsLike(opNode, colNode, stringNode);
+        super.walkPredicate(stringNode);
+        onPostIsLike(opNode, colNode, stringNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkNotLike(Tree opNode, Tree colNode, Tree stringNode) {
+        onPreIsNotLike(opNode, colNode, stringNode);
+        super.walkPredicate(colNode);
+        onIsNotLike(opNode, colNode, stringNode);
+        super.walkPredicate(stringNode);
+        onPostIsNotLike(opNode, colNode, stringNode);
+        return false;
+    }
+
+    @Override
+    public Boolean walkContains(Tree opNode, Tree typeNode, Tree textSearchNode) {
+
+        onPreContains(opNode, typeNode, textSearchNode);
+        if (opNode.getChildCount() > 1) {
+            super.walkPredicate(typeNode);
+            onBetweenContains(opNode, typeNode, textSearchNode);
+        } else
+            result.append("'");
+        super.walkSearchExpr(textSearchNode);
+        onContains(opNode, typeNode, textSearchNode);
+        return false;                
+    }
+
+    @Override
+    public Boolean walkInFolder(Tree opNode, Tree typeNode, Tree paramNode) {
+        if (opNode.getChildCount() == 1) {
+            onInFolder(opNode, paramNode, null);
+            super.walkPredicate(paramNode);
+            onPostInFolder(opNode, paramNode, null);
+        } else {
+            onInFolder(opNode, typeNode, paramNode);
+            super.walkPredicate(typeNode);
+            onBetweenInFolder(opNode, typeNode, paramNode);
+            super.walkPredicate(paramNode);
+            onPostInFolder(opNode, typeNode, paramNode);
+        }
+        return false;
+    }
+
+    @Override
+    public Boolean walkInTree(Tree opNode, Tree typeNode, Tree paramNode) {
+        if (opNode.getChildCount() == 1) {
+            onInTree(opNode, paramNode, null);
+            super.walkPredicate(paramNode);
+            onPostInTree(opNode, paramNode, null);
+        } else {
+            onInTree(opNode, typeNode, paramNode);
+            super.walkPredicate(typeNode);
+            onBetweenInTree(opNode, typeNode, paramNode);
+            super.walkPredicate(paramNode);
+            onPostInTree(opNode, typeNode, paramNode);
+        }
+        return false;
+    }
+
+    @Override
+    public Object walkCol(Tree node) {
+        onColNode(node);
+        return null;
+    }
+
+    @Override
+    public Object walkId(Tree node) {
+        return onId(node);
+    }
+    
+    @Override
+    public Boolean walkScore(Tree node) {
+        onScore(node);
+        return false;
+    }
+    
+    @Override
+    protected Boolean walkTextAnd(Tree node) {
+        List<Tree> children = getChildrenAsList(node);
+        onPreTextAnd(node, children);
+        int i=0;
+        for (Tree child : children) {
+            walkSearchExpr(child);
+            onTextAnd(node, children, i++);
+        }
+        onPostTextAnd(node, children);
+        return false;
+    }
+    
+    @Override
+    protected Boolean walkTextOr(Tree node) {
+        List<Tree> children = getChildrenAsList(node);
+        onPreTextOr(node, children);
+        int j=0;
+        for (Tree child : children) {
+            walkSearchExpr(child);
+            onTextOr(node, children, j++);
+        }
+        onPostTextOr(node, children);
+        return false;
+    }
+    
+    @Override
+    protected Boolean walkTextMinus(Tree node) {
+        onTextMinus(node, node.getChild(0));
+        walkSearchExpr(node.getChild(0));
+        onPostTextMinus(node, node.getChild(0));
+        return false;
+    }
+    
+    @Override
+    protected Boolean walkTextWord(Tree node) {
+        onTextWord(onTextLiteral(node));
+        return false;
+    }
+    
+    @Override
+    protected Boolean walkTextPhrase(Tree node) {
+        onTextPhrase(onTextLiteral(node));
+        return false;
+    }
+    
+    @Override
+    public Object walkBoolean(Tree node) {
+        Object obj = super.walkNumber(node);
+        result.append(obj);
+        return obj;
+    }
+
+    @Override
+    public Object walkNumber(Tree node) {
+        Object obj = super.walkNumber(node);
+        result.append(obj);
+        return obj;
+    }
+
+    @Override
+    public Object walkString(Tree node) {
+        String val =  "'" + super.walkString(node) + "'";
+        result.append(val);
+        return val;
+    }
+
+    @Override
+    public Object walkTimestamp(Tree node) {
+        String s = (String) super.walkTimestamp(node);
+        result.append(s);
+        return s;
+    }
+
+    @Override
+    public Object walkList(Tree node) {
+        result.append("(");
+        int n = node.getChildCount();
+        boolean first = true;
+        List<Object> res = new ArrayList<Object>(n);
+        for (int i = 0; i < n; i++) {
+            Object o = node.getChild(i);
+            if (first)
+                first = false;
+            else
+                result.append(", ");
+            result.append(o.toString());
+        }
+        
+        result.append(")");
+
+        return res;
+    }
+    
+    private void endSubExpr() {
+        result.append(")");        
+    }
+
+    private void startSubExpr() {
+        result.append("(");        
+    }
+
+    @Override
+    protected void onStartProcessing(Tree whereNode) {
+        result.append("WHERE ");        
+    }
+
+    @Override
+    protected void onStopProcessing() {
+    }
+
+    @Override
+    protected void onPreEquals(Tree eqNode, Tree leftNode, Tree rightNode) {
+        startSubExpr();
+    }
+    
+    @Override
+    protected void onEquals(Tree eqNode, Tree leftNode, Tree rightNode) {
+        result.append(" = ");
+    }
+
+    @Override
+    protected void onPostEquals(Tree eqNode, Tree leftNode, Tree rightNode) {
+        endSubExpr();
+    }
+
+    @Override
+    protected void onNotEquals(Tree neNode, Tree leftNode, Tree rightNode) {
+        result.append(" <> ");
+    }
+
+    @Override
+    protected void onGreaterThan(Tree gtNode, Tree leftNode, Tree rightNode) {
+        result.append(" > ");
+    }
+
+    @Override
+    protected void onGreaterOrEquals(Tree geNode, Tree leftNode, Tree rightNode) {
+        result.append(" >= ");
+    }
+
+    @Override
+    protected void onLessThan(Tree ltNode, Tree leftNode, Tree rightNode) {
+        result.append(" < ");
+    }
+
+    @Override
+    protected void onLessOrEquals(Tree leqNode, Tree leftNode, Tree rightNode) {
+        result.append(" <= ");
+    }
+
+    @Override
+    protected void onNot(Tree opNode, Tree leftNode) {
+        result.append("NOT (");
+    }
+
+    @Override
+    protected void onPostNot(Tree opNode, Tree leftNode) {
+        endSubExpr();
+    }
+
+    @Override
+    protected void onPreAnd(Tree opNode, Tree leftNode, Tree rightNode) {
+        startSubExpr();
+    }
+    
+    @Override
+    protected void onAnd(Tree opNode, Tree leftNode, Tree rightNode) {
+        result.append(" AND ");
+    }
+    
+    @Override
+    protected void onPostAnd(Tree opNode, Tree leftNode, Tree rightNode) {
+        endSubExpr();
+    }
+
+    @Override
+    protected void onPreOr(Tree opNode, Tree leftNode, Tree rightNode) {
+        startSubExpr();
+    }
+    
+    @Override
+    protected void onOr(Tree opNode, Tree leftNode, Tree rightNode) {
+        result.append(" OR ");
+    }
+
+    @Override
+    protected void onPostOr(Tree opNode, Tree leftNode, Tree rightNode) {
+        endSubExpr();
+    }
+    
+    @Override
+    protected void onIn(Tree node, Tree colNode, Tree listNode) {
+        result.append(" IN ");
+    }
+
+    @Override
+    protected void onNotIn(Tree node, Tree colNode, Tree listNode) {
+        result.append(" NOT IN ");
+    }
+
+    @Override
+    protected void onPreInAny(Tree node, Tree colNode, Tree listNode) {
+        result.append("ANY ");
+    }
+    
+    @Override
+    protected void onInAny(Tree node, Tree colNode, Tree listNode) {
+        result.append(" IN ");
+    }
+
+    @Override
+    protected void onPreNotInAny(Tree node, Tree colNode, Tree listNode) {
+        result.append("ANY ");
+    }
+
+    @Override
+    protected void onNotInAny(Tree node, Tree colNode, Tree listNode) {
+        result.append(" NOT IN ");
+    }
+
+    @Override
+    protected void onEqAny(Tree node, Tree literalNode, Tree colNode) {
+        result.append(" = ANY ");
+    }
+
+    @Override
+    protected void onIsNull(Tree nullNode, Tree colNode) {
+    }
+
+    @Override
+    protected void onPostIsNull(Tree nullNode, Tree colNode) {
+        result.append(" IS NULL");
+    }
+
+    @Override
+    protected void onIsNotNull(Tree notNullNode, Tree colNode) {
+    }
+
+    @Override
+    protected void onPostIsNotNull(Tree notNullNode, Tree colNode) {
+        result.append(" IS NOT NULL");
+    }
+    
+    @Override
+    protected void onPreIsLike(Tree node, Tree colNode, Tree stringNode) {
+        startSubExpr();
+    }
+
+    @Override
+    protected void onIsLike(Tree node, Tree colNode, Tree stringNode) {
+        result.append(" LIKE ");
+    }
+
+    @Override
+    protected void onPostIsLike(Tree node, Tree colNode, Tree stringNode) {
+        endSubExpr();
+    }
+
+    @Override
+    protected void onIsNotLike(Tree node, Tree colNode, Tree stringNode) {
+        result.append(" NOT LIKE ");
+    }
+
+    @Override
+    protected void onInFolder(Tree node, Tree colNode, Tree paramNode) {
+        result.append("IN_FOLDER(");
+    }
+    
+    protected void onBetweenInFolder(Tree node, Tree colNode, Tree paramNode) {
+        result.append(", ");
+    }
+
+    @Override
+    protected void onPostInFolder(Tree node, Tree colNode, Tree paramNode) {
+        result.append(")");
+    }
+
+    @Override
+    protected void onInTree(Tree node, Tree colNode, Tree paramNode) {
+        result.append("IN_TREE(");
+    }
+
+    @Override
+    protected void onBetweenInTree(Tree node, Tree colNode, Tree paramNode) {
+        result.append(", ");
+    }
+    
+    @Override
+    protected void onPostInTree(Tree node, Tree colNode, Tree paramNode) {
+        result.append(")");
+    }
+    
+    @Override
+    protected void onScore(Tree node) {
+        result.append("SCORE()");
+    }
+
+    @Override
+    protected void onColNode(Tree node) {
+        result.append(node.getChild(0).getText());
+    }
+
+    @Override
+    protected void onPreContains(Tree node, Tree typeNode, Tree searchExprNode) {
+        result.append("CONTAINS(");
+    }
+    
+    @Override
+    protected void onBetweenContains(Tree node, Tree typeNode, Tree searchExprNode) {
+        result.append(", '");
+    }
+   
+    @Override
+    protected void onContains(Tree node, Tree typeNode, Tree searchExprNode) {
+        result.append("')");
+    }
+
+    @Override
+    protected void onTextAnd(Tree node, List<Tree> conjunctionNodes, int index) {
+        if (index < conjunctionNodes.size()-1)
+            result.append(" ");        
+    }
+
+    @Override
+    protected void onTextOr(Tree node, List<Tree> termNodes, int index) {
+        if (index < termNodes.size()-1)
+            result.append(" OR ");        
+    }
+
+    @Override
+    protected void onTextMinus(Tree node, Tree notNode) {
+        result.append("-");        
+    }
+
+    @Override
+    protected void onTextWord(String word) {
+        result.append(word);        
+    }
+
+    @Override
+    protected void onTextPhrase(String phrase) {
+       result.append("\\'" + phrase + "\\'");
+    } 
+
+    private String onId(Tree node) {
+        String id = node.getText();
+        result.append(id);
+        return id;
+    }
+    
+    private List<Tree> getChildrenAsList(Tree node) {
+        List<Tree> res = new ArrayList<Tree>(node.getChildCount());
+        for (int i=0; i<node.getChildCount(); i++) {
+            Tree childNnode =  node.getChild(i);
+            res.add(childNnode);
+        }
+        return res;
+    }
+    
+    protected String onTextLiteral(Tree node) {
+        int type = node.getType();
+        String text = node.getText();
+        switch (type) {
+        case TextSearchLexer.TEXT_SEARCH_PHRASE_STRING_LIT:
+            return StringUtil.unescape(text.substring(1, text.length()-1), null);
+        case TextSearchLexer.TEXT_SEARCH_WORD_LIT:
+            return StringUtil.unescape(text, null);
+        default:
+            throw new RuntimeException("Unknown text literal. " + node);
+        }
+
+    }
+
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleTypeManager.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleTypeManager.java?rev=1444504&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleTypeManager.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExampleTypeManager.java Sun Feb 10 08:24:28 2013
@@ -0,0 +1,310 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.query.example;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import org.apache.chemistry.opencmis.commons.enums.Cardinality;
+import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
+import org.apache.chemistry.opencmis.commons.enums.PropertyType;
+import org.apache.chemistry.opencmis.commons.enums.Updatability;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyDefinition;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionContainerImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeMutabilityImpl;
+import org.apache.chemistry.opencmis.server.support.TypeManager;
+
+public class ExampleTypeManager implements TypeManager {
+    
+    private static ExampleTypeManager INSTANCE = new ExampleTypeManager();
+    
+    DocumentTypeDefinition cmisDocumentType;
+    TypeDefinitionContainerImpl cmisDocumentTypeContainer;
+    
+    public static TypeManager getInstance() {
+        return INSTANCE;
+    }
+    
+    private ExampleTypeManager() {
+        cmisDocumentType = createDocumentTypeDefinition();
+        cmisDocumentTypeContainer = new TypeDefinitionContainerImpl(cmisDocumentType);
+
+    }
+    
+    public TypeDefinitionContainer getTypeById(String typeId) {
+        if (BaseTypeId.CMIS_DOCUMENT.value().equals(typeId))
+            return cmisDocumentTypeContainer;
+        else
+            return null;
+    }
+
+    public TypeDefinition getTypeByQueryName(String typeQueryName) {
+        if (BaseTypeId.CMIS_DOCUMENT.value().equals(typeQueryName))
+            return cmisDocumentTypeContainer.getTypeDefinition();
+        else
+            return null;
+    }
+
+    public Collection<TypeDefinitionContainer> getTypeDefinitionList() {
+        TypeDefinitionContainer tdc = cmisDocumentTypeContainer;
+        return Collections.singletonList(tdc);        
+    }
+
+    public List<TypeDefinitionContainer> getRootTypes() {
+        TypeDefinitionContainer tdc = cmisDocumentTypeContainer;
+        return Collections.singletonList(tdc);        
+    }
+
+    public String getPropertyIdForQueryName(TypeDefinition typeDefinition, String propQueryName) {
+        for (PropertyDefinition<?> pd : typeDefinition.getPropertyDefinitions().values()) {
+            if (pd.getQueryName().equals(propQueryName)) {
+                return pd.getId();
+            }
+        }
+        return null;
+    }
+
+    private static DocumentTypeDefinition createDocumentTypeDefinition() {
+        
+        DocumentTypeDefinitionImpl typeDef = new DocumentTypeDefinitionImpl();
+        typeDef.setBaseTypeId(BaseTypeId.CMIS_DOCUMENT);
+        typeDef.setId(BaseTypeId.CMIS_DOCUMENT.value());
+        typeDef.setDisplayName("CMIS Document");
+        // create some suitable defaults for convenience
+        typeDef.setDescription("Description of CMIS Document Type");
+        typeDef.setLocalName(typeDef.getDisplayName());
+        typeDef.setLocalNamespace("local");
+        typeDef.setQueryName(typeDef.getId());
+        typeDef.setIsControllableAcl(true);
+        typeDef.setIsControllablePolicy(false);
+        typeDef.setIsCreatable(true);
+        typeDef.setIsFileable(true);
+        typeDef.setIsFulltextIndexed(false);
+        typeDef.setIsIncludedInSupertypeQuery(true);
+        typeDef.setIsQueryable(true);
+
+        TypeMutabilityImpl typeMutability = new TypeMutabilityImpl();
+        typeMutability.setCanCreate(true);
+        typeMutability.setCanDelete(false);
+        typeMutability.setCanUpdate(false);
+        typeDef.setTypeMutability (typeMutability);
+
+
+        // document specifics:
+        typeDef.setContentStreamAllowed(ContentStreamAllowed.ALLOWED);
+        typeDef.setIsVersionable(false);
+        
+        Map<String, PropertyDefinition<?>> props = new HashMap<String, PropertyDefinition<?>>();
+        setBasicDocumentPropertyDefinitions(props);
+        typeDef.setPropertyDefinitions(props); // set initial empty set of properties
+
+        return typeDef;
+    }
+
+
+    private static void setBasicDocumentPropertyDefinitions(Map<String, PropertyDefinition<?>> propertyDefinitions) {
+        
+        setBasicPropertyDefinitions(propertyDefinitions);
+        PropertyBooleanDefinitionImpl propB = createBooleanDefinition(PropertyIds.IS_IMMUTABLE,
+                "Immutable", Updatability.READONLY);
+        propertyDefinitions.put(propB.getId(), propB);
+
+        propB = createBooleanDefinition(PropertyIds.IS_LATEST_VERSION,
+                "Is Latest Version", Updatability.READONLY);
+        propertyDefinitions.put(propB.getId(), propB);
+
+        propB = createBooleanDefinition(PropertyIds.IS_MAJOR_VERSION,
+                "Is Major Version", Updatability.READONLY);
+        propertyDefinitions.put(propB.getId(), propB);
+
+        propB = createBooleanDefinition(PropertyIds.IS_LATEST_MAJOR_VERSION,
+                "Is Latest Major Version", Updatability.READONLY);
+        propertyDefinitions.put(propB.getId(), propB);
+
+        PropertyStringDefinitionImpl propS = createStringDefinition(PropertyIds.VERSION_LABEL,
+                "Version Label", Updatability.READONLY);
+        propertyDefinitions.put(propS.getId(), propS);
+
+        PropertyIdDefinitionImpl propId = createIdDefinition(PropertyIds.VERSION_SERIES_ID,
+                "Version Series Id", Updatability.READONLY);
+        propId.setIsQueryable(false);
+        propertyDefinitions.put(propId.getId(), propId);
+
+        propB = createBooleanDefinition(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT,
+                "Checked Out", Updatability.READONLY);
+        propertyDefinitions.put(propB.getId(), propB);
+
+        propS = createStringDefinition(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY,
+                "Checked Out By", Updatability.READONLY);
+        propertyDefinitions.put(propS.getId(), propS);
+
+        propId = createIdDefinition(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID,
+                "Checked Out Id", Updatability.READONLY);
+        propertyDefinitions.put(propId.getId(), propId);
+
+        propS = createStringDefinition(PropertyIds.CHECKIN_COMMENT,
+                "Checkin Comment", Updatability.READONLY);
+        // read-only, because
+        // not set as property
+        propertyDefinitions.put(propS.getId(), propS);
+
+        PropertyIntegerDefinitionImpl propI = createIntegerDefinition(
+                PropertyIds.CONTENT_STREAM_LENGTH, "Content Length", Updatability.READONLY);
+        propertyDefinitions.put(propI.getId(), propI);
+
+        propS = createStringDefinition(PropertyIds.CONTENT_STREAM_MIME_TYPE,
+                "Mime Type", Updatability.READONLY);
+        propertyDefinitions.put(propS.getId(), propS);
+
+        propS = createStringDefinition(PropertyIds.CONTENT_STREAM_FILE_NAME,
+                "File Name", Updatability.READONLY);
+        propertyDefinitions.put(propS.getId(), propS);
+
+        propId = createIdDefinition(PropertyIds.CONTENT_STREAM_ID, "Stream Id", Updatability.READONLY);
+        propertyDefinitions.put(propId.getId(), propId);
+
+        // CMIS 1.1:
+        propB = createBooleanDefinition(PropertyIds.IS_PRIVATE_WORKING_COPY, "Private Working Copy", 
+                Updatability.READONLY);
+        propertyDefinitions.put(propB.getId(), propB);
+
+        propertyDefinitions.put(propS.getId(), propS);
+    }
+    
+    static void setBasicPropertyDefinitions(Map<String, PropertyDefinition<?>> propertyDefinitions) {
+
+        PropertyStringDefinitionImpl propS = createStringDefinition(PropertyIds.NAME,
+                "Name", Updatability.READWRITE);
+        propS.setIsRequired(true);
+        propertyDefinitions.put(propS.getId(), propS);
+
+        PropertyIdDefinitionImpl propId = createIdDefinition(PropertyIds.OBJECT_ID,
+                "Object Id", Updatability.READONLY);
+        propertyDefinitions.put(propId.getId(), propId);
+
+        propId = createIdDefinition(PropertyIds.OBJECT_TYPE_ID, "Type-Id", Updatability.ONCREATE);
+        propId.setIsRequired(true);
+        propertyDefinitions.put(propId.getId(), propId);
+
+        propId = createIdDefinition(PropertyIds.BASE_TYPE_ID, "Base-Type-Id", Updatability.READONLY);
+        propertyDefinitions.put(propId.getId(), propId);
+
+        propS = createStringDefinition(PropertyIds.CREATED_BY, "Created By", Updatability.READONLY);
+        propertyDefinitions.put(propS.getId(), propS);
+
+        PropertyDateTimeDefinitionImpl propD = createDateTimeDefinition(
+                PropertyIds.CREATION_DATE, "Creation Date", Updatability.READONLY);
+        propertyDefinitions.put(propD.getId(), propD);
+
+        propS = createStringDefinition(PropertyIds.LAST_MODIFIED_BY,
+                "Modified By", Updatability.READONLY);
+        propertyDefinitions.put(propS.getId(), propS);
+
+        propD = createDateTimeDefinition(PropertyIds.LAST_MODIFICATION_DATE,
+                "Modification Date", Updatability.READONLY);
+        propertyDefinitions.put(propD.getId(), propD);
+
+        propS = createStringDefinition(PropertyIds.CHANGE_TOKEN, "Change Token", Updatability.READONLY);
+        propertyDefinitions.put(propS.getId(), propS);
+
+        // CMIS 1.1:
+        propS = createStringDefinition(PropertyIds.DESCRIPTION, "Description", Updatability.READWRITE);
+        propertyDefinitions.put(propS.getId(), propS);
+
+        propId = createIdMultiDefinition(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, "Secondary Type Ids",
+                Updatability.READWRITE);
+        propertyDefinitions.put(propId.getId(), propId);
+    }
+
+    private static void createStandardDefinition(AbstractPropertyDefinition<?> prop, String id, PropertyType propType,
+            String displayName, Cardinality card, Updatability upd) {
+
+            prop.setId(id);
+        if (displayName == null) {
+            prop.setDisplayName("Sample " + prop.getId() + " boolean property");
+        } else {
+            prop.setDisplayName(displayName);
+        }
+        prop.setDescription("This is a " + prop.getDisplayName() + " property.");
+        prop.setLocalName(id);
+        prop.setLocalNamespace("local");
+        prop.setQueryName(id);
+        prop.setIsInherited(false);
+        prop.setCardinality(card);
+        prop.setIsOpenChoice(false);
+        prop.setIsQueryable(true);
+        prop.setIsRequired(false);
+        prop.setIsOrderable(true);
+        prop.setPropertyType(propType);
+        prop.setUpdatability(upd);
+    }
+
+    private static PropertyBooleanDefinitionImpl createBooleanDefinition(String id, String displayName, Updatability upd) {
+        PropertyBooleanDefinitionImpl prop = new PropertyBooleanDefinitionImpl();
+        createStandardDefinition(prop, id, PropertyType.BOOLEAN, displayName, Cardinality.SINGLE, upd);
+        return prop;
+    }
+
+    private static PropertyDateTimeDefinitionImpl createDateTimeDefinition(String id, String displayName,
+            Updatability upd) {
+        PropertyDateTimeDefinitionImpl prop = new PropertyDateTimeDefinitionImpl();
+        createStandardDefinition(prop, id, PropertyType.DATETIME, displayName, Cardinality.SINGLE, upd);
+        return prop;
+    }
+
+    private static PropertyIdDefinitionImpl createIdDefinition(String id, String displayName, Updatability upd) {
+        PropertyIdDefinitionImpl prop = new PropertyIdDefinitionImpl();
+        createStandardDefinition(prop, id, PropertyType.ID, displayName, Cardinality.SINGLE, upd);
+        return prop;
+    }
+
+    public static PropertyIdDefinitionImpl createIdMultiDefinition(String id, String displayName, Updatability upd) {
+        PropertyIdDefinitionImpl prop = new PropertyIdDefinitionImpl();
+        createStandardDefinition(prop, id, PropertyType.ID, displayName, Cardinality.MULTI, upd);
+        return prop;
+    }
+
+    public static PropertyIntegerDefinitionImpl createIntegerDefinition(String id, String displayName, Updatability upd) {
+        PropertyIntegerDefinitionImpl prop = new PropertyIntegerDefinitionImpl();
+        createStandardDefinition(prop, id, PropertyType.INTEGER, displayName, Cardinality.SINGLE, upd);
+        return prop;
+    }
+
+    private static PropertyStringDefinitionImpl createStringDefinition(String id, String displayName, Updatability upd) {
+        PropertyStringDefinitionImpl prop = new PropertyStringDefinitionImpl();
+        createStandardDefinition(prop, id, PropertyType.STRING, displayName, Cardinality.SINGLE, upd);
+        return prop;
+    }
+
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExtendedAbstractPredicateWalker.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExtendedAbstractPredicateWalker.java?rev=1444504&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExtendedAbstractPredicateWalker.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/main/java/org/apache/chemistry/opencmis/query/example/ExtendedAbstractPredicateWalker.java Sun Feb 10 08:24:28 2013
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.query.example;
+
+import java.util.List;
+
+import org.antlr.runtime.tree.Tree;
+import org.apache.chemistry.opencmis.server.support.query.AbstractPredicateWalker;
+
+public abstract class ExtendedAbstractPredicateWalker extends AbstractPredicateWalker {
+
+    protected abstract void onStartProcessing(Tree whereNode);
+    protected abstract void onStopProcessing();
+
+    // Compare operators
+    protected void onPreEquals(Tree eqNode, Tree leftNode, Tree rightNode) {        
+    }
+    protected abstract void onEquals(Tree eqNode, Tree leftNode, Tree rightNode);
+    protected void onPostEquals(Tree eqNode, Tree leftNode, Tree rightNode) {        
+    }
+
+    protected void onPreNotEquals(Tree neNode, Tree leftNode, Tree rightNode) {        
+    }
+    protected abstract void onNotEquals(Tree neNode, Tree leftNode, Tree rightNode);
+    protected void onPostNotEquals(Tree neNode, Tree leftNode, Tree rightNode) {        
+    }
+ 
+    protected void onPreGreaterThan(Tree gtNode, Tree leftNode, Tree rightNode) {        
+    }
+    protected abstract void onGreaterThan(Tree gtNode, Tree leftNode, Tree rightNode);
+    protected void onPostGreaterThan(Tree gtNode, Tree leftNode, Tree rightNode) {        
+    }
+
+    protected void onPreGreaterOrEquals(Tree geNode, Tree leftNode, Tree rightNode) {        
+    }
+    protected abstract void onGreaterOrEquals(Tree geNode, Tree leftNode, Tree rightNode);
+    protected void onPostGreaterOrEquals(Tree geNode, Tree leftNode, Tree rightNode) {        
+    }
+
+    protected void onPreLessThan(Tree ltNode, Tree leftNode, Tree rightNode)  {        
+    }
+    protected abstract void onLessThan(Tree ltNode, Tree leftNode, Tree rightNode);
+    protected void onPostLessThan(Tree ltNode, Tree leftNode, Tree rightNode) {        
+    }
+
+    protected void onPreLessOrEquals(Tree leqNode, Tree leftNode, Tree rightNode) {        
+    }
+    protected abstract void onLessOrEquals(Tree leqNode, Tree leftNode, Tree rightNode);
+    protected void onPostLessOrEquals(Tree leqNode, Tree leftNode, Tree rightNode) {        
+    }
+
+    // Boolean operators
+    protected abstract void onNot(Tree opNode, Tree leftNode);
+    protected void onPostNot(Tree opNode, Tree leftNode) {
+    }
+    protected void onPreAnd(Tree opNode, Tree leftNode, Tree rightNode) {
+    }
+    protected abstract void onAnd(Tree opNode, Tree leftNode, Tree rightNode);
+    protected void onPostAnd(Tree opNode, Tree leftNode, Tree rightNode) {
+    }
+    protected void onPreOr(Tree opNode, Tree leftNode, Tree rightNode) {
+    }
+    protected abstract void onOr(Tree opNode, Tree leftNode, Tree rightNode);
+    protected void onPostOr(Tree opNode, Tree leftNode, Tree rightNode) {
+    }
+
+    // Multi-value:
+    protected void onPreIn(Tree node, Tree colNode, Tree listNode) {        
+    }
+    protected abstract void onIn(Tree node, Tree colNode, Tree listNode);
+    protected void onPostIn(Tree node, Tree colNode, Tree listNode) {        
+    }
+
+    protected void onPreNotIn(Tree node, Tree colNode, Tree listNode) {        
+    }
+    protected abstract void onNotIn(Tree node, Tree colNode, Tree listNode);
+    protected void onPostNotIn(Tree node, Tree colNode, Tree listNode) {        
+    }
+
+    protected void onPreInAny(Tree node, Tree colNode, Tree listNode) {        
+    }
+    protected abstract void onInAny(Tree node, Tree colNode, Tree listNode);
+    protected void onPostInAny(Tree node, Tree colNode, Tree listNode) {        
+    }
+
+    protected void onPreNotInAny(Tree node, Tree colNode, Tree listNode) {        
+    }
+    protected abstract void onNotInAny(Tree node, Tree literalNode, Tree colNode);
+    protected void onPostNotInAny(Tree node, Tree colNode, Tree listNode) {        
+    }
+    
+    protected void onPreEqAny(Tree node, Tree literalNode, Tree colNode) {
+    }
+    protected abstract void onEqAny(Tree node, Tree literalNode, Tree colNode);
+    protected void onPostEqAny(Tree node, Tree literalNode, Tree colNode) {        
+    }
+
+    // Null comparisons:
+    protected abstract void onIsNull(Tree nullNode, Tree colNode);
+    protected void onPostIsNull(Tree nullNode, Tree colNode) {
+    }
+
+    protected abstract void onIsNotNull(Tree notNullNode, Tree colNode);
+    protected void onPostIsNotNull(Tree notNullNode, Tree colNode) {
+    }
+    
+    // String matching:
+    protected void onPreIsLike(Tree node, Tree colNode, Tree stringNode) {
+    }
+    protected abstract void onIsLike(Tree node, Tree colNode, Tree stringNode);
+    protected void onPostIsLike(Tree node, Tree colNode, Tree stringNode) {
+    }
+
+    protected void onPreIsNotLike(Tree node, Tree colNode, Tree stringNode) {
+    }
+    protected abstract void onIsNotLike(Tree node, Tree colNode, Tree stringNode);
+    protected void onPostIsNotLike(Tree node, Tree colNode, Tree stringNode) {
+    }
+
+    protected abstract void onInFolder(Tree node, Tree colNode, Tree paramNode);
+    protected void onBetweenInFolder(Tree node, Tree colNode, Tree paramNode) {
+    }
+    protected void onPostInFolder(Tree node, Tree colNode, Tree paramNode) {
+    }
+
+    protected abstract void onInTree(Tree node, Tree colNode, Tree paramNode);
+    protected void onBetweenInTree(Tree node, Tree colNode, Tree paramNode) {
+    }
+    protected void onPostInTree(Tree node, Tree colNode, Tree paramNode) {
+    }
+    
+    protected abstract void onScore(Tree node);
+    protected abstract void onColNode(Tree node);
+    
+    protected void onPreTextAnd(Tree node, List<Tree> conjunctionNodes) {
+    }
+    protected abstract void onTextAnd(Tree node, List<Tree> conjunctionNodes, int index);
+    protected void onPostTextAnd(Tree node, List<Tree> conjunctionNodes) {
+    }
+    protected void onPreTextOr(Tree node, List<Tree> termNodes) {
+    }
+    protected abstract void onTextOr(Tree node, List<Tree> termNodes, int index);
+    protected void onPostTextOr(Tree node, List<Tree> termNodes) {
+    }
+    protected abstract void onTextMinus(Tree node, Tree notNode);
+    protected void onPostTextMinus(Tree node, Tree notNode) {        
+    }
+    protected abstract void onTextWord(String word);
+    protected abstract void onTextPhrase(String phrase);
+    
+    protected void onPreContains(Tree node, Tree typeNode, Tree searchExprNode) {        
+    }
+    
+    protected abstract void onContains(Tree node, Tree typeNode, Tree searchExprNode);
+    
+    protected void onBetweenContains(Tree node, Tree typeNode, Tree searchExprNode) {        
+    }
+
+}

Added: chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/org/apache/chemistry/opencmis/query/example/ExampleQueryProcessorTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/org/apache/chemistry/opencmis/query/example/ExampleQueryProcessorTest.java?rev=1444504&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/org/apache/chemistry/opencmis/query/example/ExampleQueryProcessorTest.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-samples/chemistry-opencmis-queryparser/src/test/java/org/apache/chemistry/opencmis/query/example/ExampleQueryProcessorTest.java Sun Feb 10 08:24:28 2013
@@ -0,0 +1,265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.query.example;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class ExampleQueryProcessorTest {
+    
+    private ExampleQueryProcessor queryProcessor;
+    private String queryPrefix = "SELECT cmis:name, cmis:objectId FROM cmis:document WHERE ";
+    private String expectedPrefix = "SELECT cmis:name, cmis:objectId FROM cmis:document WHERE ";
+    
+    @Before
+    public void setUp() {
+        queryProcessor = new ExampleQueryProcessor();
+    }
+    
+    @Test 
+    public void testEquals() {
+        String queryString = queryPrefix + "cmis:name = 'MyDocument'";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "(cmis:name = 'MyDocument')";
+        assertEquals(expected, response);
+        
+        queryString = queryPrefix + "SCORE() = 100";
+        response = queryProcessor.parseQuery(queryString);
+        expected = expectedPrefix + "(SCORE() = 100)";
+        assertEquals(expected, response);
+    }
+    
+    @Test
+    public void testNotEquals() {
+        String queryString = queryPrefix + "cmis:name <> 'MyDocument'";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "cmis:name <> 'MyDocument'";
+        assertEquals(expected, response);        
+    }
+    
+    @Test
+    public void testLessThan() {
+        String queryString = queryPrefix + "cmis:contentStreamLength < 1048576";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "cmis:contentStreamLength < 1048576";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testGreaterThan() {
+        String queryString = queryPrefix + "cmis:contentStreamLength > 1048576";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "cmis:contentStreamLength > 1048576";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testLessOrEquals() {
+        String queryString = queryPrefix + "cmis:contentStreamLength <= 1048576";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "cmis:contentStreamLength <= 1048576";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testGreaterOrEquals() {
+        String queryString = queryPrefix + "cmis:contentStreamLength >= 1048576";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "cmis:contentStreamLength >= 1048576";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testIn() {
+        String queryString = queryPrefix + "cmis:name IN ('MyDocument', 'YourDocument')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "cmis:name IN ('MyDocument', 'YourDocument')";
+        assertEquals(expected, response);        
+    }
+    
+    @Test
+    public void testNotIn() {
+        String queryString = queryPrefix + "cmis:name NOT IN ('MyDocument', 'YourDocument')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "cmis:name NOT IN ('MyDocument', 'YourDocument')";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testAnyIn() {
+        String queryString = queryPrefix + "ANY cmis:secondaryObjectTypeIds IN ('MySecondaryType', 'YourSecondaryType')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "ANY cmis:secondaryObjectTypeIds IN ('MySecondaryType', 'YourSecondaryType')";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testAnyNotIn() {
+        String queryString = queryPrefix + "ANY cmis:secondaryObjectTypeIds NOT IN ('MySecondaryType', 'YourSecondaryType')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "ANY cmis:secondaryObjectTypeIds NOT IN ('MySecondaryType', 'YourSecondaryType')";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testEqAny() {
+        String queryString = queryPrefix + "'MySecondaryType' = ANY cmis:secondaryObjectTypeIds";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "'MySecondaryType' = ANY cmis:secondaryObjectTypeIds";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testIsNull() {
+        String queryString = queryPrefix + "cmis:description IS NULL";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "cmis:description IS NULL";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testIsNotNull() {
+        String queryString = queryPrefix + "cmis:description IS NOT NULL";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "cmis:description IS NOT NULL";
+        assertEquals(expected, response);        
+    }
+    
+    @Test 
+    public void testLike() {
+        String queryString = "SELECT cmis:name AS name, cmis:objectTypeId, SCORE() FROM cmis:document WHERE cmis:name LIKE 'My%'";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = "SELECT cmis:name AS name, cmis:objectTypeId, SCORE() FROM cmis:document WHERE (cmis:name LIKE 'My%')";
+        assertEquals(expected, response);
+    }
+
+    @Test
+    public void testNotLike() {
+        String queryString = queryPrefix + "cmis:name NOT LIKE 'My%'";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "cmis:name NOT LIKE 'My%'";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testInFolder() {
+        String queryString = queryPrefix + "IN_FOLDER('100')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "IN_FOLDER('100')";
+        assertEquals(expected, response);        
+
+        queryString = queryPrefix + "IN_FOLDER(cmis:document, '100')";
+        response = queryProcessor.parseQuery(queryString);
+        expected = expectedPrefix + "IN_FOLDER(cmis:document, '100')";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testInTree() {
+        String queryString = queryPrefix + "IN_TREE('100')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "IN_TREE('100')";
+        assertEquals(expected, response);        
+
+        queryString = queryPrefix + "IN_TREE(cmis:document, '100')";
+        response = queryProcessor.parseQuery(queryString);
+        expected = expectedPrefix + "IN_TREE(cmis:document, '100')";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testAnd() {
+        String queryString = queryPrefix + "cmis:name NOT LIKE 'My*' AND cmis:description IS NULL";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "(cmis:name NOT LIKE 'My*' AND cmis:description IS NULL)";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testOr() {
+        String queryString = queryPrefix + "cmis:name NOT LIKE 'My*' OR cmis:description IS NULL";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "(cmis:name NOT LIKE 'My*' OR cmis:description IS NULL)";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testNot() {
+        String queryString = queryPrefix + "NOT IN_FOLDER('100')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "NOT (IN_FOLDER('100'))";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testContains() {
+        String queryString = queryPrefix + "CONTAINS('Foo')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "CONTAINS('Foo')";
+        assertEquals(expected, response);
+        
+        queryString = queryPrefix + "CONTAINS(cmis:document, 'Foo')";
+        response = queryProcessor.parseQuery(queryString);
+        expected = expectedPrefix + "CONTAINS(cmis:document, 'Foo')";
+        assertEquals(expected, response);
+    }
+
+    @Test
+    public void testTextAnd() {
+        String queryString = queryPrefix + "CONTAINS('abc def')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "CONTAINS('abc def')";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testTextOr() {
+        String queryString = queryPrefix + "CONTAINS('abc OR def')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "CONTAINS('abc OR def')";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testTextMinus() {
+        String queryString = queryPrefix + "CONTAINS('abc -def')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "CONTAINS('abc -def')";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testPhrase() {
+        String queryString = queryPrefix + "CONTAINS('\\'abc\\'')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "CONTAINS('\\'abc\\'')";
+        assertEquals(expected, response);        
+    }
+
+    @Test
+    public void testWord() {
+        String queryString = queryPrefix + "CONTAINS('Foo')";
+        String response = queryProcessor.parseQuery(queryString);
+        String expected = expectedPrefix + "CONTAINS('Foo')";
+        assertEquals(expected, response);        
+    }
+
+}



Mime
View raw message