chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1039259 - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src: main/antlr3/org/apache/chemistry/opencmis/server/support/query/ main/java/org/apache/chemistry/opencmis/server/support/query/...
Date Fri, 26 Nov 2010 07:43:18 GMT
Author: jens
Date: Fri Nov 26 07:43:17 2010
New Revision: 1039259

URL: http://svn.apache.org/viewvc?rev=1039259&view=rev
Log:
cleanup of Query exception handling

Added:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/CmisQueryException.java
Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CMISQLParser.g
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseGrammar.g
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlExtParser.g
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlStrictParser.g
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryUtil.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTst.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CMISQLParser.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CMISQLParser.g?rev=1039259&r1=1039258&r2=1039259&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CMISQLParser.g
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CMISQLParser.g
Fri Nov 26 07:43:17 2010
@@ -60,20 +60,6 @@ options {
 package org.apache.chemistry.opencmis.server.support.query;
 }
 
-@members {
-    public String errorMessage;
-
-    @Override
-    public void displayRecognitionError(String[] tokenNames,
-            RecognitionException e) {
-        if (errorMessage == null) {
-            String hdr = getErrorHeader(e);
-            String msg = getErrorMessage(e, tokenNames);
-            errorMessage = hdr + " " + msg;
-        }
-    }
-}
-
 query: SELECT^ DISTINCT? select_list from_clause where_clause? order_by_clause?;
 
 select_list

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseGrammar.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseGrammar.g?rev=1039259&r1=1039258&r2=1039259&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseGrammar.g
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisBaseGrammar.g
Fri Nov 26 07:43:17 2010
@@ -35,10 +35,28 @@ options {
     output = AST;
 }
 
-@rulecatch {
-	catch (RecognitionException e) {
-		throw e;
+@members {
+    private List<String> errorMessages = new ArrayList<String>();
+    
+    public boolean hasErrors() {
+    	return errorMessages.size() > 0;
+    }
+
+	public String getErrorMessages() {
+		StringBuffer allMessages = new StringBuffer();
+		
+		for (String msg : errorMessages)
+			allMessages.append(msg).append('\n');
+			
+		return allMessages.toString();
 	}
+
+    @Override
+    // Instead of sending all errors to System.err collect them in a list
+	public void emitErrorMessage(String msg) {
+		errorMessages.add(msg);
+	}
+	
 }
 
 query: 

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlExtParser.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlExtParser.g?rev=1039259&r1=1039258&r2=1039259&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlExtParser.g
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlExtParser.g
Fri Nov 26 07:43:17 2010
@@ -67,6 +67,15 @@ tokens {
 package org.apache.chemistry.opencmis.server.support.query;
 }
 
+@members {
+    public boolean hasErrors() {
+    	return gCmisBaseGrammar.hasErrors();
+    }
+
+	public String getErrorMessages() {
+    	return gCmisBaseGrammar.getErrorMessages();
+	}
+}
 
 query: SELECT^ DISTINCT? select_list from_clause where_clause? order_by_clause?;
 

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlStrictParser.g
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlStrictParser.g?rev=1039259&r1=1039258&r2=1039259&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlStrictParser.g
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQlStrictParser.g
Fri Nov 26 07:43:17 2010
@@ -64,22 +64,12 @@ package org.apache.chemistry.opencmis.se
 }
 
 @members {
-	protected void mismatch(IntStream input, int ttype, BitSet follow)
-		throws RecognitionException
-	{
-		throw new MismatchedTokenException(ttype, input);
-	}
-	
-	public void recoverFromMismatchedSet(IntStream input, RecognitionException e, antlr.collections.impl.BitSet
follow)
-		throws RecognitionException
-	{
-		throw e;
-	}
-}
+    public boolean hasErrors() {
+    	return gCmisBaseGrammar.hasErrors();
+    }
 
-@rulecatch {
-	catch (RecognitionException e) {
-		throw e;
+	public String getErrorMessages() {
+    	return gCmisBaseGrammar.getErrorMessages();
 	}
 }
 

Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/CmisQueryException.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/CmisQueryException.java?rev=1039259&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/CmisQueryException.java
(added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/CmisQueryException.java
Fri Nov 26 07:43:17 2010
@@ -0,0 +1,41 @@
+/*
+ * 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.server.support.query;
+
+
+public class CmisQueryException extends RuntimeException {
+
+    private static final long serialVersionUID = 1L;
+
+    public CmisQueryException() {
+        super();
+    }
+
+    public CmisQueryException(String message) {
+        super(message);
+    }
+
+    public CmisQueryException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public CmisQueryException(Throwable cause) {
+        super(cause);
+    }
+}

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java?rev=1039259&r1=1039258&r2=1039259&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
Fri Nov 26 07:43:17 2010
@@ -69,6 +69,8 @@ public class QueryObject {
 
     // order by part
     protected List<SortSpec> sortSpecs = new ArrayList<SortSpec>();
+    
+    private String errorMessage;
 
     public static class JoinSpec {
 
@@ -132,6 +134,10 @@ public class QueryObject {
     public CmisSelector getColumnReference(Integer token) {
         return columnReferences.get(token);
     }
+    
+    public String getErrorMessage() {
+        return errorMessage;
+    }
 
     // ///////////////////////////////////////////////////////
     // SELECT part
@@ -149,7 +155,7 @@ public class QueryObject {
     public void addAlias(String aliasName, CmisSelector aliasRef) {
         LOG.debug("add alias: " + aliasName + " for: " + aliasRef);
         if (colOrFuncAlias.containsKey(aliasName)) {
-            throw new CmisInvalidArgumentException("You cannot use name " + aliasName
+            throw new CmisQueryException("You cannot use name " + aliasName
                     + " more than once as alias in a select.");
         } else {
             aliasRef.setAliasName(aliasName);
@@ -165,19 +171,24 @@ public class QueryObject {
     // FROM part
 
     public String addType(String aliasName, String typeQueryName) {
-        LOG.debug("add alias: " + aliasName + " for: " + typeQueryName);
-        if (froms.containsKey(aliasName)) {
-            throw new CmisInvalidArgumentException("You cannot use name " + aliasName
-                    + " more than once as alias in a from part.");
-        }
-        if (aliasName == null) {
-            aliasName = typeQueryName;
-        }
-        froms.put(aliasName, typeQueryName);
-        if (from == null) {
-            from = aliasName;
+        try {
+            LOG.debug("add alias: " + aliasName + " for: " + typeQueryName);
+            if (froms.containsKey(aliasName)) {
+                throw new CmisQueryException("You cannot use name " + aliasName
+                        + " more than once as alias in a from part.");
+            }
+            if (aliasName == null) {
+                aliasName = typeQueryName;
+            }
+            froms.put(aliasName, typeQueryName);
+            if (from == null) {
+                from = aliasName;
+            }
+            return aliasName;
+        } catch (CmisQueryException cqe) {
+            errorMessage = cqe.getMessage(); // preserve message
+            return null; // indicate an error to ANTLR so that it generates FailedPredicateException
         }
-        return aliasName;
     }
 
     public String getMainTypeAlias() {
@@ -317,66 +328,73 @@ public class QueryObject {
     // ///////////////////////////////////////////////////////
     // resolve types after first pass traversing the AST is complete
 
-    public void resolveTypes() {
-        LOG.debug("First pass of query traversal is complete, resolving types");
-        if (null == typeMgr)
-            return;
-
-        // First resolve all alias names defined in SELECT:
-        for (CmisSelector alias : colOrFuncAlias.values()) {
-            if (alias instanceof ColumnReference) {
-                ColumnReference colRef = ((ColumnReference) alias);
-                resolveTypeForAlias(colRef);
+    public boolean resolveTypes() {
+        try {
+            LOG.debug("First pass of query traversal is complete, resolving types");
+            if (null == typeMgr)
+                return true;
+
+            // First resolve all alias names defined in SELECT:
+            for (CmisSelector alias : colOrFuncAlias.values()) {
+                if (alias instanceof ColumnReference) {
+                    ColumnReference colRef = ((ColumnReference) alias);
+                    resolveTypeForAlias(colRef);
+                }
             }
-        }
 
-        // Then replace all aliases used somewhere by their resolved column
-        // reference:
-        for (Integer obj : columnReferences.keySet()) {
-            CmisSelector selector = columnReferences.get(obj);
-            String key = selector.getName();
-            if (colOrFuncAlias.containsKey(key)) { // it is an alias
-                CmisSelector resolvedReference = colOrFuncAlias.get(key);
-                columnReferences.put(obj, resolvedReference);
-                // Note: ^ This may replace the value in the map with the same
-                // value, but this does not harm.
-                // Otherwise we need to check if it is resolved or not which
-                // causes two more ifs:
-                // if (selector instanceof ColumnReference) {
-                // ColumnReference colRef = ((ColumnReference) selector);
-                // if (colRef.getTypeDefinition() == null) // it is not yet
-                // resolved
-                // // replace unresolved column reference by resolved on from
-                // alias map
-                // columnReferences.put(obj,
-                // colOrFuncAlias.get(selector.getAliasName()));
-                // } else
-                // columnReferences.put(obj,
-                // colOrFuncAlias.get(selector.getAliasName()));
-                if (whereReferences.remove(selector))
-                    // replace unresolved by resolved reference
-                    whereReferences.add(resolvedReference);
-                if (joinReferences.remove(selector))
-                    // replace unresolved by resolved reference
-                    joinReferences.add(resolvedReference);
+            // Then replace all aliases used somewhere by their resolved column
+            // reference:
+            for (Integer obj : columnReferences.keySet()) {
+                CmisSelector selector = columnReferences.get(obj);
+                String key = selector.getName();
+                if (colOrFuncAlias.containsKey(key)) { // it is an alias
+                    CmisSelector resolvedReference = colOrFuncAlias.get(key);
+                    columnReferences.put(obj, resolvedReference);
+                    // Note: ^ This may replace the value in the map with the same
+                    // value, but this does not harm.
+                    // Otherwise we need to check if it is resolved or not which
+                    // causes two more ifs:
+                    // if (selector instanceof ColumnReference) {
+                    // ColumnReference colRef = ((ColumnReference) selector);
+                    // if (colRef.getTypeDefinition() == null) // it is not yet
+                    // resolved
+                    // // replace unresolved column reference by resolved on from
+                    // alias map
+                    // columnReferences.put(obj,
+                    // colOrFuncAlias.get(selector.getAliasName()));
+                    // } else
+                    // columnReferences.put(obj,
+                    // colOrFuncAlias.get(selector.getAliasName()));
+                    if (whereReferences.remove(selector))
+                        // replace unresolved by resolved reference
+                        whereReferences.add(resolvedReference);
+                    if (joinReferences.remove(selector))
+                        // replace unresolved by resolved reference
+                        joinReferences.add(resolvedReference);
+                }
             }
-        }
 
-        // The replace all remaining column references not using an alias
-        for (CmisSelector select : columnReferences.values()) {
-            // ignore functions here
-            if (select instanceof ColumnReference) {
-                ColumnReference colRef = ((ColumnReference) select);
-                if (colRef.getTypeDefinition() == null) { // not yet resolved
-                    if (colRef.getTypeQueryName() == null) {
-                        // unqualified select: SELECT p FROM
-                        resolveTypeForColumnReference(colRef);
-                    } else {
-                        // qualified select: SELECT t.p FROM
-                        validateColumnReferenceAndResolveType(colRef);
+            // The replace all remaining column references not using an alias
+            for (CmisSelector select : columnReferences.values()) {
+                // ignore functions here
+                if (select instanceof ColumnReference) {
+                    ColumnReference colRef = ((ColumnReference) select);
+                    if (colRef.getTypeDefinition() == null) { // not yet resolved
+                        if (colRef.getTypeQueryName() == null) {
+                            // unqualified select: SELECT p FROM
+                            resolveTypeForColumnReference(colRef);
+                        } else {
+                            // qualified select: SELECT t.p FROM
+                            validateColumnReferenceAndResolveType(colRef);
+                        }
                     }
                 }
             }
+            
+            return true;
+        } catch (CmisQueryException cqe) {
+            errorMessage = cqe.getMessage(); // preserve message
+            return false; // indicate an error to ANTLR so that it generates FailedPredicateException
         }
     }
 
@@ -410,7 +428,7 @@ public class QueryObject {
         for (String typeQueryName : froms.values()) {
             TypeDefinition td = typeMgr.getTypeByQueryName(typeQueryName);
             if (null == td)
-                throw new CmisInvalidArgumentException(typeQueryName + " is neither a type
query name nor an alias.");
+                throw new CmisQueryException(typeQueryName + " is neither a type query name
nor an alias.");
             else if (isStar) {
                 ++noFound;
                 tdFound = null;
@@ -420,10 +438,10 @@ public class QueryObject {
             }
         }
         if (noFound == 0)
-            throw new CmisInvalidArgumentException(propName
+            throw new CmisQueryException(propName
                     + " is not a property query name in any of the types in from ...");
         else if (noFound > 1 && !isStar)
-            throw new CmisInvalidArgumentException(propName
+            throw new CmisQueryException(propName
                     + " is not a unique property query name within the types in from ...");
         else {
             if (null != tdFound) // can be null in select * from t1 JOIN t2....
@@ -438,7 +456,7 @@ public class QueryObject {
         String typeQueryName = getReferencedTypeQueryName(colRef.getTypeQueryName());
         TypeDefinition td = typeMgr.getTypeByQueryName(typeQueryName);
         if (null == td)
-            throw new CmisInvalidArgumentException(colRef.getTypeQueryName()
+            throw new CmisQueryException(colRef.getTypeQueryName()
                     + " is neither a type query name nor an alias.");
 
         validateColumnReferenceAndResolveType(td, colRef);
@@ -453,7 +471,7 @@ public class QueryObject {
         else
             hasProp = TypeValidator.typeContainsPropertyWithQueryName(td, colRef.getPropertyQueryName());
         if (!hasProp)
-            throw new CmisInvalidArgumentException(colRef.getPropertyQueryName()
+            throw new CmisQueryException(colRef.getPropertyQueryName()
                     + " is not a valid property query name in type " + td.getId() + ".");
 
         colRef.setTypeDefinition(typeMgr.getPropertyIdForQueryName(td, colRef.getPropertyQueryName()),
td);

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryUtil.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryUtil.java?rev=1039259&r1=1039258&r2=1039259&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryUtil.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryUtil.java
Fri Nov 26 07:43:17 2010
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 
 import org.antlr.runtime.ANTLRInputStream;
+import org.antlr.runtime.BaseRecognizer;
 import org.antlr.runtime.CharStream;
 import org.antlr.runtime.CommonTokenStream;
 import org.antlr.runtime.RecognitionException;
@@ -30,6 +31,8 @@ import org.antlr.runtime.TokenSource;
 import org.antlr.runtime.TokenStream;
 import org.antlr.runtime.tree.CommonTree;
 import org.antlr.runtime.tree.CommonTreeNodeStream;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.server.support.query.CmisQlStrictParser_CmisBaseGrammar.query_return;
 
 /**
@@ -39,8 +42,11 @@ import org.apache.chemistry.opencmis.ser
  */
 public class QueryUtil extends QueryObject {
 
+    private CmisQueryWalker walker;
+    
     // convenience method because everybody needs this piece of code
-    static public CmisQueryWalker getWalker(String statement) throws UnsupportedEncodingException,
IOException, RecognitionException {
+    public CmisQueryWalker getWalker(String statement) throws UnsupportedEncodingException,
IOException, RecognitionException {
+        
         CharStream input = new ANTLRInputStream(new ByteArrayInputStream(statement.getBytes("UTF-8")));
         TokenSource lexer = new CmisQlStrictLexer(input);
         TokenStream tokens = new CommonTokenStream(lexer);
@@ -48,6 +54,9 @@ public class QueryUtil extends QueryObje
         CommonTree parserTree; // the ANTLR tree after parsing phase
 
         query_return parsedStatement = parser.query();
+        if (parser.hasErrors()) {
+            throw new CmisInvalidArgumentException(parser.getErrorMessages());
+        }
         parserTree = (CommonTree) parsedStatement.getTree();
 
         CommonTreeNodeStream nodes = new CommonTreeNodeStream(parserTree);
@@ -55,4 +64,41 @@ public class QueryUtil extends QueryObje
         CmisQueryWalker walker = new CmisQueryWalker(nodes);
         return walker;
     }
+
+    public CmisQueryWalker traverseStatement(String statement, QueryObject queryObj, PredicateWalkerBase
pw) throws UnsupportedEncodingException, IOException, RecognitionException {
+        walker = getWalker(statement);
+        walker.query(queryObj, pw);
+        walker.getWherePredicateTree();
+        return walker;        
+    }
+    
+    public CmisQueryWalker traverseStatementAndCatchExc(String statement, QueryObject queryObj,
PredicateWalkerBase pw) {
+        QueryUtil queryUtil = new QueryUtil();
+        try {
+            return traverseStatement(statement, queryObj, pw);
+        } catch (RecognitionException e) {
+            String errorMsg = queryUtil.getErrorMessage();
+            throw new CmisInvalidArgumentException("Walking of statement failed with RecognitionException
error: \n   " + errorMsg);
+        } catch (CmisBaseException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new CmisInvalidArgumentException("Walking of statement failed with exception:
\n   " + e);
+        }
+    }
+
+    public String getErrorMessage(RecognitionException e) {
+        if (null == walker)
+            return e.toString();
+        else
+            return getErrorMessage(walker, e);
+    }
+    
+    private String getErrorMessage(BaseRecognizer recognizer, RecognitionException e) {
+        String[] tokenNames = recognizer.getTokenNames();
+        // String hdr = walker.getErrorHeader(e);
+        String hdr = "Line "+e.line+":"+e.charPositionInLine;
+        String msg = recognizer.getErrorMessage(e, tokenNames);
+        return hdr + " " + msg;
+    }
+    
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTst.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTst.java?rev=1039259&r1=1039258&r2=1039259&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTst.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTst.java
Fri Nov 26 07:43:17 2010
@@ -24,6 +24,7 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 
 import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.BaseRecognizer;
 import org.antlr.runtime.CharStream;
 import org.antlr.runtime.CommonTokenStream;
 import org.antlr.runtime.Lexer;
@@ -189,7 +190,10 @@ public class AbstractParserTst{
         if ( tokens.index()!=tokens.size() ) {
             throw new RuntimeException("Invalid input.");
         }
-            
+        
+        /** Check for syntax errors */
+        if (((BaseRecognizer)parObj).getNumberOfSyntaxErrors() > 0)
+            throw new RuntimeException("Syntax error occured");
         return result;
     }
     



Mime
View raw message