db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r171353 [6/13] - in /incubator/jdo/trunk/query20: ./ src/ src/conf/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jdo/ src/java/org/apache/jdo/impl/ src/java/org/apache/jdo/impl/jdoql/ src/java/org/apache/jdo/impl/jdoql/jdoqlc/ src/java/org/apache/jdo/impl/jdoql/scope/ src/java/org/apache/jdo/impl/jdoql/tree/ src/java/org/apache/jdo/jdoql/ src/java/org/apache/jdo/jdoql/tree/
Date Sun, 22 May 2005 18:09:00 GMT
Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/VariableChecker.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/VariableChecker.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/VariableChecker.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/VariableChecker.java Sun May 22 11:08:57 2005
@@ -0,0 +1,290 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+/*
+ * VariableChecker.java
+ *
+ * Created on September 12, 2001
+ */
+
+package org.apache.jdo.impl.jdoql.jdoqlc;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
+
+import javax.jdo.JDOUnsupportedOptionException;
+import javax.jdo.JDOFatalInternalException;
+
+import org.apache.jdo.jdoql.JDOQueryException;
+import org.apache.jdo.util.I18NHelper;
+
+
+/**
+ * Checks variable declarations/application.
+ *
+ * @author  Michael Bouschen
+ * @version 0.1
+ */
+public class VariableChecker
+{
+    /** I18N support */
+    protected final static I18NHelper msg = I18NHelper.getInstance(
+        "org.apache.jdo.impl.jdoql.Bundle", VariableChecker.class.getClassLoader()); //NOI18N
+
+    /**
+     * A VarInfo consists of two info fields:
+     * - constraint: the variable is constraint with the specified expr
+     * - used: the variable is used
+     */
+    static class VarInfo
+    {
+        /**
+         * The constraint expression.
+         */
+        JDOQLAST constraint;
+
+        /**
+         * Set of JDOQLAST nodes denoting an access of this variable.
+         */
+        Set used;
+
+        /**
+         * Dependency for this variable. 
+         * The constraint for this variable may use another variable. 
+         */
+        String dependsOn;
+
+        /**
+         * Flag whether this varInfo is checked already (see checkConstraints)
+         */
+        int status;
+
+        static final int UNCHECKED = 0;
+        static final int IN_PROGRESS = 1;
+        static final int CHECKED = 2;
+
+        VarInfo()
+        {
+            this.constraint = null;
+            this.used = new HashSet();
+            this.dependsOn = null;
+            this.status = UNCHECKED;
+        }
+
+        VarInfo(VarInfo other)
+        {
+            this.constraint = other.constraint;
+            this.used = new HashSet(other.used);
+            this.dependsOn = other.dependsOn;
+            this.status = other.status;
+        }
+    }
+
+    /**
+     * Map of variable infos
+     */
+    protected Map varInfos;
+
+    /**
+     * Create an empty variable table
+     */
+    public VariableChecker()
+    {
+        varInfos = new HashMap();
+    }
+
+    /**
+     * Create a variable table initialized with the entries of the other variable table.
+     * The constructor creates copies of the values stored in the map (instances of class VarInfo).
+     */
+    public VariableChecker(VariableChecker other)
+    {
+        varInfos = new HashMap();
+        for (Iterator i = other.varInfos.entrySet().iterator(); i.hasNext();) {
+            Map.Entry entry = (Map.Entry)i.next();
+            varInfos.put(entry.getKey(), new VarInfo((VarInfo)entry.getValue()));
+        }
+    }
+
+    /**
+     * Creates a new entry in the variable table with the specified name as key and 
+     * an empty value.
+     */
+    public void add(String name)
+    {
+        // init var entry as not constraint and unused
+        varInfos.put(name, new VarInfo());
+    }
+
+    /**
+     * Mark the specified variable as used. 
+     * The method sets the info field of the VarInfo object to true.
+     */
+    public void markUsed(JDOQLAST variable, String dependendVar)
+    {
+        String name = variable.getText();
+        VarInfo entry = (VarInfo)varInfos.get(name);
+        if (entry == null) {
+            throw new JDOFatalInternalException(
+                msg.msg("ERR_VariableCheckerUndefinedVariable", //NOI18N
+                        "markUsed", name)); //NOI18N
+        }
+        entry.used.add(variable);
+        if (dependendVar != null) {
+            VarInfo dependendVarInfo = (VarInfo)varInfos.get(dependendVar);
+            if (dependendVarInfo.dependsOn != null) {
+                throw new JDOFatalInternalException(
+                    msg.msg("ERR_VariableCheckerMultipleDependencies", //NOI18N    
+                            dependendVar, dependendVarInfo.dependsOn, name));
+            }
+            dependendVarInfo.dependsOn = name;
+        }
+    }
+
+    /**
+     * Mark the specified variable as constaint with the specified expr.
+     * The method sets the constraint field of the VarInfo object to true.
+     */
+    public void markConstraint(JDOQLAST variable, JDOQLAST expr)
+    {
+        String name = variable.getText();
+        VarInfo entry = (VarInfo)varInfos.get(name);
+        if (entry == null) {
+            throw new JDOFatalInternalException(
+                msg.msg("ERR_VariableCheckerUndefinedVariable", //NOI18N
+                        "markConstraint", name)); //NOI18N
+        }
+        String old = (entry.constraint==null ? null : entry.constraint.getText());
+        if ((old != null) && !old.equals(expr.getText())) {
+            throw new JDOUnsupportedOptionException(
+                msg.msg("EXC_UnsupportedMultipleConstraints", name)); //NOI18N
+        }
+        entry.constraint = expr;
+    }
+
+    /**
+     * Merges the specified variable table (other) into this variable table.
+     */
+    public void merge(VariableChecker other)
+    {
+        for (Iterator i = varInfos.entrySet().iterator(); i.hasNext();) {
+            Map.Entry entry = (Map.Entry)i.next();
+            String name = (String)entry.getKey();
+            VarInfo info = (VarInfo)entry.getValue();
+            VarInfo otherInfo = (VarInfo)other.varInfos.get(name);
+            
+            // copy other info if this info is empty
+            if ((info.constraint == null) && (info.used.size() == 0)) {
+                info.constraint = otherInfo.constraint;
+                info.used = otherInfo.used;
+                info.dependsOn = otherInfo.dependsOn;
+                info.status = otherInfo.status;
+                continue;
+            }
+
+            // do nothing if otherInfo is empty
+            if ((otherInfo.constraint == null) && (otherInfo.used.size() == 0)) {
+                continue;
+            }
+            
+            // constraint check
+            // If both variables tables include constraints they have to be the same
+            if ((info.constraint != null) && (otherInfo.constraint != null)) {
+                if (!otherInfo.constraint.getText().equals(info.constraint.getText())) {
+                    throw new JDOUnsupportedOptionException(
+                        msg.msg("EXC_DifferentConstraints", name)); //NOI18N
+                }
+            }
+            // If at least one variable table does not define constraint, 
+            // nullify the constaint in this variable table
+            else {
+                info.constraint = null;
+                info.dependsOn = null;
+                info.status = VarInfo.UNCHECKED;
+            }
+            
+            // copy otherInfo.used to this used list
+            info.used.addAll(otherInfo.used);
+        }
+    }
+
+    /**
+     *
+     */
+    public void checkConstraints()
+    {
+        for (Iterator i = varInfos.entrySet().iterator(); i.hasNext();) {
+            Map.Entry entry = (Map.Entry)i.next();
+            VarInfo info = (VarInfo)entry.getValue();
+            checkConstraint((String)entry.getKey(), (VarInfo)entry.getValue());
+        }
+    }
+
+    protected void checkConstraint(String variable, VarInfo info)
+    {
+        switch (info.status) {
+        case VarInfo.UNCHECKED:
+            // if unchecked, start checking
+            info.status = VarInfo.IN_PROGRESS;
+            break;
+        case VarInfo.IN_PROGRESS:
+            // if this VarInfo is currently processed we have a cyclic dependency
+            throw new JDOUnsupportedOptionException(
+                msg.msg("EXC_UnsupportedCyclicConstaint", variable)); // NOI18N
+        case VarInfo.CHECKED:
+            // if alreday checked just return
+            return;
+        }
+        
+        if (info.dependsOn != null) {
+            VarInfo dependendVarInfo = (VarInfo)varInfos.get(info.dependsOn);
+            checkConstraint(info.dependsOn, dependendVarInfo);
+        }
+        
+        if (info.constraint == null) {
+            throw new JDOUnsupportedOptionException(
+                msg.msg("EXC_UnconstraintVariable", variable)); //NOI18N
+        }
+        
+        if (info.used.size() == 0) {
+            throw new JDOUnsupportedOptionException(
+                msg.msg("EXC_UnusedVariable", variable)); //NOI18N
+        }
+        
+        // Next line in comment, because the node visitor for queries in memory
+        // does not like VARIABLE_ACCESS child nodes. 
+        // This needs to be investigated for the SQL generation.
+        //attachConstraintToUsedAST(info);
+        info.status = VarInfo.CHECKED;
+    }
+    
+    /**
+     *
+     */
+    protected void attachConstraintToUsedAST(VarInfo info)
+    {
+        for (Iterator i = info.used.iterator(); i.hasNext();) {
+            JDOQLAST varNode = (JDOQLAST)i.next();
+            if (varNode.getFirstChild() == null) 
+                varNode.setFirstChild(JDOQLASTFactory.getInstance().dupTree(info.constraint));
+        }
+    }
+
+}
+

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/AbstractValueTable.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/AbstractValueTable.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/AbstractValueTable.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/AbstractValueTable.java Sun May 22 11:08:57 2005
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+/*
+ * AbstractValueTable.java
+ *
+ * Created on September 11, 2001
+ */
+
+package org.apache.jdo.impl.jdoql.scope;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.io.Serializable;
+
+import javax.jdo.JDOFatalInternalException;
+
+import org.apache.jdo.jdoql.JDOQueryException;
+import org.apache.jdo.jdoql.tree.Declaration;
+import org.apache.jdo.jdoql.tree.ValueTable;
+import org.apache.jdo.util.I18NHelper;
+
+
+/**
+ * This method is the abstract super class for ParameterTable and VariableTable.
+ * It provides common implementation for managing parameter and variable values.
+ *
+ * @author  Michael Bouschen
+ */
+abstract class AbstractValueTable
+    implements ValueTable, Serializable, Cloneable
+{
+    /**
+     * Map of declarations. Key is the the name of the declared identifier, 
+     * value is the Declaration node.
+     */
+    Map declMap = new HashMap();
+    
+    /**
+     * Map of values. This map includes a values entry for each declared 
+     * identifier. Default value is UNDEFINED.
+     */
+    transient Map valueMap;
+    
+    /** I18N support */
+    protected final static I18NHelper msg = I18NHelper.getInstance(
+        "org.apache.jdo.impl.jdoql.Bundle", //NOI18N
+        AbstractValueTable.class.getClassLoader()); 
+ 
+    /**
+     * Adds a new declaration. The value is set to UNDEFINED.
+     * @param decl the declaration node
+     */
+    public void declare(Declaration decl)
+    {
+        String name = decl.getName();
+        declMap.put(name, decl);
+    }
+    
+    /**
+     * This method initializes the map of values for this ValueTable. 
+     * It needs to be called prior to any use of an AbstractValueTable
+     * at query execution time.
+     */
+    public void initValueHandling()
+    {
+        valueMap = new HashMap();
+        for (Iterator i = declMap.keySet().iterator(); i.hasNext();) {
+            String name = (String)i.next();
+            valueMap.put(name, UNDEFINED.getInstance());
+        }
+    }
+
+    /**
+     * Sets the value for the specified identifier.
+     * @param name the name of the identifier
+     * @param value the current value of the identifier
+     */
+    public void setValue(String name, Object value)
+    {
+        if (valueMap == null)
+            throw new JDOFatalInternalException(
+                msg.msg("ERR_InvalidTableForExecution", //NOI18N
+                        this.getClass().getName()));
+        Declaration decl = (Declaration)declMap.get(name);
+        checkDeclaredIdentifier(name, decl);
+        valueMap.put(name, value);
+    }
+    
+    /**
+     * Returns the current value for the specified identifier.
+     * @param name the name of the identifier
+     * @return the current value of the identifier
+     */
+    public Object getValue(String name)
+    {
+        if (valueMap == null)
+            throw new JDOFatalInternalException(
+                msg.msg("ERR_InvalidTableForExecution", //NOI18N
+                        this.getClass().getName()));
+        checkDeclaredIdentifier(name, (Declaration)declMap.get(name));
+        return valueMap.get(name);
+    }
+    
+    /**
+     * Checks whether the type of the specified value is compatible of the type
+     * of the identifier from its declaration.
+     * @param name the name of the identifier
+     * @param value the value to be checked
+     * @return <code>true</code> if the type of the value is compatible with the 
+     * type of the identifier; <code>false</code> otherwise.
+     */
+    public boolean isCompatibleValue(String name, Object value)
+    {
+        Declaration decl = (Declaration)declMap.get(name);
+        checkDeclaredIdentifier(name, decl);
+
+        boolean isCompatible = true;
+
+        // check type compatibility of actual and formal parameter
+        Class formalType = decl.getJavaClass();
+
+        // handle value == null
+        if (value == null) {
+            isCompatible = !formalType.isPrimitive();
+        }
+        else {
+            Class actualType = value.getClass();
+            Class type = formalType;
+            if (formalType.isPrimitive()) {
+                if (formalType == int.class)
+                    type = Integer.class;
+                else if (formalType == long.class)
+                    type = Long.class;
+                else if (formalType == short.class)
+                    type = Short.class;
+                else if (formalType == byte.class)
+                    type = Byte.class;
+                else if (formalType == double.class)
+                    type = Double.class;
+                else if (formalType == float.class)
+                    type = Float.class;
+                else if (formalType == boolean.class)
+                    type = Boolean.class;
+                else if (formalType == char.class)
+                    type = Character.class;
+            }
+            isCompatible = type.isAssignableFrom(actualType);
+        }
+        return isCompatible;
+    }
+ 
+    /**
+     * Internal method to check whether the specified identifier is declared. 
+     * Allows subclasses of AbstractValueTable to use specific error messages.
+     */
+    protected abstract void checkDeclaredIdentifier(String name, 
+                                                    Declaration decl);
+
+}
+

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/ParameterTable.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/ParameterTable.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/ParameterTable.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/ParameterTable.java Sun May 22 11:08:57 2005
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+/*
+ * ParameterTable.java
+ *
+ * Created on August 28, 2001
+ */
+
+package org.apache.jdo.impl.jdoql.scope;
+
+import java.util.*;
+
+import javax.jdo.JDOFatalInternalException;
+
+import org.apache.jdo.impl.jdoql.QueryResultHelperImpl;
+import org.apache.jdo.jdoql.JDOQueryException;
+import org.apache.jdo.jdoql.tree.Declaration;
+import org.apache.jdo.pm.PersistenceManagerInternal;
+
+
+/**
+ * The query parameter table.
+ *
+ * @author  Michael Bouschen
+ */
+public class ParameterTable
+    extends AbstractValueTable
+{
+    /**
+     * List of query parameter names. The query parameter tables stores the 
+     * query parameter names in an extra list to presever the order of 
+     * parameter declarations.
+     */
+    List names = new ArrayList();
+
+    /**
+     * Adds a new declaration. The value is initially set to UNDEFINED.
+     * @param decl the declaration node
+     */
+    public void declare(Declaration decl)
+    {
+        super.declare(decl);
+        names.add(decl.getName());
+    }
+    
+    /**
+     * Returns a copy of this ParameterTable.
+     * @return a copy of this ParameterTable.
+     */
+    public ParameterTable getCopy()
+    {
+        try {
+            return (ParameterTable)clone();
+        }
+        catch (CloneNotSupportedException ex) {
+            throw new JDOFatalInternalException(
+                msg.msg("ERR_UnexpectedCloneProblems", ex)); //NOI18N
+        }
+    }
+    
+    /**
+     * Internal method to check whether the specified identifier is declared. 
+     */
+    protected void checkDeclaredIdentifier(String name, Declaration decl)
+    {
+        if (decl == null)
+            throw new JDOQueryException(
+                msg.msg("EXC_UndefinedQueryParameter", name)); //NOI18N
+    }
+
+    //========= PatameterTable convenience methods ==========
+
+    /**
+     * Sets all query parameter values. The order of declarations in 
+     * declareParameters defines the order in the specified array of parameter 
+     * values. The method checks the type compatibility of the query parameter 
+     * values.
+     * @param paramValues the parameter values
+     */
+    public void setValues(PersistenceManagerInternal queryPM, Object[] paramValues)
+    {
+        if (paramValues != null)
+        {
+            Iterator i = names.iterator();
+            for (int index = 0; index < paramValues.length; index++) {
+                Object value = paramValues[index];
+                if (!i.hasNext()) {
+                    throw new JDOQueryException(
+                        msg.msg("EXC_WrongNumberOfQueryParameters")); //NOI18N
+                }
+                String name = (String)i.next();
+                QueryResultHelperImpl.checkPM(queryPM, value);
+                checkCompatibility(name, value);
+                setValue(name, value);
+            }
+        }
+    }
+
+    /**
+     * Sets all query parameter values. The values are taken from the specified 
+     * map. The method assumes the key in the map to be the parameter name and 
+     * the value in the map to be the parameter value. 
+     * @param paramValues the parameter values
+     */
+    public void setValues(PersistenceManagerInternal queryPM, Map paramValues)
+    {
+        if (paramValues != null)
+        {
+            for (Iterator i = paramValues.entrySet().iterator(); i.hasNext();)
+            {
+                Map.Entry actualParam = (Map.Entry)i.next();
+                String name = (String)actualParam.getKey();
+                Object value = actualParam.getValue();
+                QueryResultHelperImpl.checkPM(queryPM, value);
+                checkCompatibility(name, value);
+                setValue(name, value);
+            }
+        }
+    }
+
+    /**
+     * Checks whether all query parameters are bound. 
+     * If not a JDOQueryException is thrown.
+     */
+    public void checkUnboundParams()
+    {
+        if (valueMap == null)
+            throw new JDOFatalInternalException(
+                msg.msg("ERR_InvalidTableForExecution", //NOI18N
+                        this.getClass().getName()));
+        for (Iterator i = valueMap.entrySet().iterator(); i.hasNext();)
+        {
+            Map.Entry valueEntry = (Map.Entry)i.next();
+            if (valueEntry.getValue() instanceof UNDEFINED)
+            {
+                throw new JDOQueryException(
+                    msg.msg("EXC_UnboundQueryParameter", (String)valueEntry.getKey())); //NOI18N
+            }
+        }
+    }
+
+    //========= Internal helper methods ==========
+   
+    /**
+     * Checks the type compatibility of the specified value and throws a
+     * JDOQueryException if the value has an incompatible type.
+     */
+    private void checkCompatibility(String name, Object value)
+    {
+        if (!isCompatibleValue(name, value)) {
+            Declaration decl = (Declaration)declMap.get(name);
+            String formalType = decl.getJavaClass().getName();
+            String actualType = (value == null) ? "null" : value.getClass().getName(); //NOI18N
+            throw new JDOQueryException(
+                msg.msg("EXC_IncompatibleTypeOfQueryParameter", actualType, formalType)); //NOI18N
+        }
+    }
+}
+

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/SymbolTable.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/SymbolTable.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/SymbolTable.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/SymbolTable.java Sun May 22 11:08:57 2005
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+/*
+ * SymbolTable.java
+ *
+ * Created on August 28, 2001
+ */
+
+package org.apache.jdo.impl.jdoql.scope;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import org.apache.jdo.jdoql.tree.Declaration;
+
+
+/**
+ * The symbol table handling declared identifies.
+ *
+ * @author  Michael Bouschen
+ */
+public class SymbolTable
+{
+    /**
+     * The table of declared identifier (symbols).
+     */
+    protected Map symbols = new HashMap();
+
+	/**
+	 * This method adds the specified identifier to this SymbolTable. 
+     * The specified declaration node provides details anbout the declaration. 
+     * If this SymbolTable already defines an identifier with the same name, 
+     * the SymbolTable is not changed and the existing declaration is returned. 
+     * Otherwise <code>null</code> is returned.
+     * @param   ident   identifier to be declared
+     * @param   def     new definition of identifier
+     * @return  the old definition if the identifier was already declared; 
+     * <code>null</code> otherwise
+	 */
+    public Declaration declare(String ident, Declaration def)
+    {
+        Declaration old = (Declaration)symbols.get(ident);
+        if (old == null) {
+            symbols.put(ident, def);
+        }
+        return old;
+    }
+
+    /**
+     * Checks whether the specified identifier is declared.  
+     * @param ident the name of identifier to be tested
+     * @return <code>true</code> if the identifier is declared; 
+     * <code>false</code> otherwise.
+     */
+    public boolean isDeclared(String ident)
+    {
+        return (getDeclaration(ident) != null);
+    }
+
+    /**
+     * Checks the symbol table for the actual declaration of the specified 
+     * identifier. The method returns the declaration node if available or
+     * <code>null</code> for an undeclared identifier. 
+     * @param ident the name of identifier
+     * @return the declaration node if ident is declared;
+     * <code>null</code> otherise.
+     */
+    public Declaration getDeclaration(String ident)
+    {
+        return (Declaration)symbols.get(ident);
+    }
+	
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/TypeNames.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/TypeNames.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/TypeNames.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/TypeNames.java Sun May 22 11:08:57 2005
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+/*
+ * TypeNames.java
+ *
+ * Created on September 06, 2001
+ */
+
+package org.apache.jdo.impl.jdoql.scope;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.TypeSupport;
+import org.apache.jdo.model.java.JavaType;
+
+
+/**
+ * The table handling type names.
+ * <p>
+ * TBD:
+ * <ul>
+ * <li> check single type-import-on-demand on access
+ * </ul> 
+ * @author  Michael Bouschen
+ */
+public class TypeNames
+{
+    /**
+     * The corresponding type table.
+     **/
+    protected TypeSupport typeSupport;
+
+    /**
+     * Map of single-type-imports. 
+     * Key is the imported class name, value is the fully qualified class name.
+     */
+    protected Map imports = new HashMap();
+
+    /**
+     * Collection of type-imports-on-demand. 
+     * The collection stores the imported package names.
+     */
+    protected Set importOnDemands = new HashSet();
+
+    /**
+     * The package of the class of the current compilation unit.
+     */
+    protected String currentPackage = null;
+
+    /**
+     * Creates a new TypeNames instance.
+     */
+    public TypeNames(TypeSupport typeSupport)
+    {
+        this.typeSupport = typeSupport;
+    }
+
+    /**
+     * This method initializes the TypeNames table. It sets the currentPackage 
+     * as the package name of the specified compilation unit. It also adds the 
+     * package java.lang to the type-imports-on-demand.
+     */
+    public void init(String compilationUnit)
+    {
+        declareImport(compilationUnit);
+        declareImportOnDemand("java.lang"); //NOI18N
+        int index = compilationUnit.lastIndexOf('.');
+        currentPackage = index > 0 ? compilationUnit.substring(0, index) : ""; //NOI18N
+    }
+
+    /**
+     * Defines a single-type-import.
+     * @param typeName the fully qualified name of the type to be imported.
+     */
+    public String declareImport(String typeName)
+    {
+        int index = typeName.lastIndexOf('.');
+        String shortName = index>0 ? typeName.substring(index+1) : typeName;
+        String old = (String)imports.get(shortName);
+        if (old == null)
+            imports.put(shortName, typeName);
+        else if (old.equals(typeName))
+            // same import twice => no problem
+            old = null;
+        return old;
+    }
+
+    /**
+     * Defines a type-import-on-demand.
+     * @param packageName the package name to be imported.
+     */
+    public void declareImportOnDemand(String packageName)
+    {
+        importOnDemands.add(packageName);
+    }
+
+    /**
+     * Resolves a type name. If the specified type name is fully qualified 
+     * the method checks the type table for the type representation. If the 
+     * name is not fully qualified, the method first checks whether there is 
+     * a single-type-import importing the specified name. If not it checks 
+     * whether the current package defines this type. If not the method checks 
+     * whether there is a single type-import-on-demand for the spceified name. 
+     * @param name a type name
+     * @return the type representation for the type name.
+     */
+    public JavaType resolve(String name)
+    {
+        // check fully qulified class name
+        int index = name.indexOf('.');
+        if (index > -1) {
+            return typeSupport.checkType(name);
+        }
+        
+        // check single-type-import
+        String singleTypeImort = (String)imports.get(name);
+        if (singleTypeImort != null)
+            return typeSupport.checkType(singleTypeImort);
+        
+        // check current package
+        JavaType type = typeSupport.checkType(currentPackage + '.' + name);
+        if (type != null)
+            return type;
+
+        // check type-import-on-demand
+        // TBD: check single type-import-on-demand
+        for (Iterator i = importOnDemands.iterator(); i.hasNext();) {
+            String next = (String)i.next();
+            type = typeSupport.checkType(next + '.' + name);
+            if (type != null)
+                return type;
+        }
+
+        // not found
+        return null;
+    }
+
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/UNDEFINED.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/UNDEFINED.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/UNDEFINED.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/UNDEFINED.java Sun May 22 11:08:57 2005
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+/*
+ * UNDEFINED.java
+ *
+ * Created on September 11, 2001
+ */
+
+package org.apache.jdo.impl.jdoql.scope;
+
+/**
+ * An instance of this class represents an undefined value in a ValueTable
+ * (ParameterTable or VariableTable).
+ *
+ * @author  Michael Bouschen
+ */
+public class UNDEFINED
+{
+    /** The singleton UNDEFINED instance. */    
+    private static UNDEFINED undefined = new UNDEFINED();
+    
+    /** 
+     * Get an instance of UNDEFINED
+     * @return an instance of UNDEFINED
+     */    
+    public static UNDEFINED getInstance()
+    {
+        return undefined;
+    }
+
+    /**
+     * Creates new UNDEFINED. This constructor should not be 
+     * called directly; instead, the singleton access method 
+     * {@link #getInstance} should be used.
+     */
+    private UNDEFINED() {}
+
+    /**
+     * Returns a string representation of an UNDEFINED instance.
+     */
+    public String toString()
+    {
+        return "UNDEFINED"; //NOI18N
+    }
+    
+    
+}
+

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/VariableTable.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/VariableTable.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/VariableTable.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/scope/VariableTable.java Sun May 22 11:08:57 2005
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+/*
+ * VariableTable.java
+ *
+ * Created on September 11, 2001
+ */
+
+package org.apache.jdo.impl.jdoql.scope;
+
+import javax.jdo.JDOFatalInternalException;
+
+import org.apache.jdo.jdoql.JDOQueryException;
+import org.apache.jdo.jdoql.tree.Declaration;
+
+
+
+/**
+ * The variable table.
+ *
+ * @author  Michael Bouschen
+ * @version 0.1
+ */
+public class VariableTable
+    extends AbstractValueTable
+{
+    /**
+     * Returns a copy of this VariableTable.
+     * @return a copy of this VariableTable.
+     */
+    public VariableTable getCopy()
+    {
+        try {
+            return (VariableTable)clone();
+        }
+        catch (CloneNotSupportedException ex) {
+            throw new JDOFatalInternalException(
+                msg.msg("ERR_UnexpectedCloneProblems", ex)); //NOI18N
+        }
+    }
+ 
+    /**
+     * Internal method to check whether the specified identifier is declared. 
+     */
+    protected void checkDeclaredIdentifier(String name, Declaration decl)
+    {
+        if (decl == null)
+            throw new JDOQueryException(
+                msg.msg("EXC_UndefinedQueryVariable", name)); //NOI18N
+    }
+}
+

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/AndExpr.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/AndExpr.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/AndExpr.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/AndExpr.java Sun May 22 11:08:57 2005
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes;
+import org.apache.jdo.jdoql.tree.AndExpression;
+import org.apache.jdo.jdoql.tree.Expression;
+import org.apache.jdo.jdoql.tree.NodeVisitor;
+
+
+/**
+ * This node represents a logical and operator.
+ * A logical and operator is based on boolean types.
+ * The string representation of this operator is <code>&</code>.
+ *
+ * @author Michael Watzek
+ */
+public final class AndExpr extends BinaryExpr implements AndExpression
+{
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public AndExpr()
+    {}
+
+    /**
+     * The noarg constructor is needed for ANTLR support.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public AndExpr(antlr.Token token)
+    {   initialize( token );
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param left the first child
+     * @param right the second child
+     */
+    AndExpr(Expression left, Expression right)
+    {   super( JDOQLTokenTypes.BAND, "And", Boolean.class, left, right ); //NOI18N
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     */
+    public void arrive(NodeVisitor visitor)
+    {   visitor.arrive( this );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param results the result array
+     * @return the object returned by the visitor instance
+     */
+    public Object leave(NodeVisitor visitor, Object[] results)
+    {   return visitor.leave( this, results );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param resultOfPreviousChild the result computed by leaving the
+     * previous child node
+     * @param indexOfNextChild the index in the children array of the
+     * next child to walk
+     * @return the boolean value returned by the visitor instance
+     */
+    public boolean walkNextChild(NodeVisitor visitor,
+                                 Object resultOfPreviousChild,
+                                 int indexOfNextChild)
+    {   return visitor.walkNextChild( this, resultOfPreviousChild, 
+                                      indexOfNextChild );
+    }
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/AscendingOrderingExpr.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/AscendingOrderingExpr.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/AscendingOrderingExpr.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/AscendingOrderingExpr.java Sun May 22 11:08:57 2005
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes;
+import org.apache.jdo.jdoql.tree.AscendingOrderingExpression;
+import org.apache.jdo.jdoql.tree.Expression;
+import org.apache.jdo.jdoql.tree.NodeVisitor;
+
+
+/**
+ * This node represents an operator defining ascendent ordering of instances
+ * returned by a query execution. The order is determined by an expression
+ * such as <code>FieldAccessExpression</code>. This expression is this node's
+ * child.
+ *
+ * @author Michael Watzek
+ */
+public final class AscendingOrderingExpr 
+    extends OrderingExpr implements AscendingOrderingExpression
+{
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public AscendingOrderingExpr()
+    {}
+
+    /**
+     * The noarg constructor is needed for ANTLR support.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public AscendingOrderingExpr(antlr.Token token)
+    {   initialize( token );
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param expr the expression defining the order
+     */
+    AscendingOrderingExpr(Expression expr)
+    {   super( JDOQLTokenTypes.ASCENDING, "AscendingOrderingExpression", expr ); //NOI18N
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     */
+    public void arrive(NodeVisitor visitor)
+    {   visitor.arrive( this );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param results the result array
+     * @return the object returned by the visitor instance
+     */
+    public Object leave(NodeVisitor visitor, Object[] results)
+    {   return visitor.leave( this, results );
+    }
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/BinaryExpr.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/BinaryExpr.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/BinaryExpr.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/BinaryExpr.java Sun May 22 11:08:57 2005
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import org.apache.jdo.jdoql.JDOQueryException;
+import org.apache.jdo.jdoql.tree.BinaryExpression;
+import org.apache.jdo.jdoql.tree.EqualsExpression;
+import org.apache.jdo.jdoql.tree.Expression;
+import org.apache.jdo.jdoql.tree.NotEqualsExpression;
+
+/**
+ * This node represents a binary operator. All binary operators have exactly
+ * two children. Examples of binary operators
+ * are <code>AndExpression</code> and <code>EqualsExpression</code>.
+ *
+ * @author Michael Watzek
+ */
+public abstract class BinaryExpr extends Expr implements BinaryExpression
+{
+    transient Class commonOperandType;
+    String commonOperandTypeName; // needed for serialization support only
+
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public BinaryExpr()
+    {}
+
+    /**
+     * This constructor is called by specialized nodes.
+     * It calls <code>setChildren</code> in order to initialize the node's
+     * children <code>left</code> and <code>right</code>.
+     * @param tokenType the token type
+     * @param tokenName the name of this node
+     * @param clazz the Java type of this node
+     * @param left the first child
+     * @param right the second child
+     */
+    BinaryExpr(int tokenType, String tokenName, Class clazz, Expression left, Expression right)
+    {   super( tokenType, tokenName, clazz );
+        this.commonOperandType = computeJavaClass( left.getJavaClass(), right.getJavaClass() );
+        setChildren( new org.apache.jdo.jdoql.tree.Node[] {left, right} );
+    }
+
+    /**
+     * Returns the first child of this node.
+     * @return the first child
+     */
+    public Expression getLeftExpression()
+    {   ASTToChildren();
+        if( this.children==null ||
+            this.children.length<1 )
+            return null;
+        return (Expression) this.children[0];
+    }
+
+    /**
+     * Returns the second child of this node.
+     * @return the second child
+     */
+    public Expression getRightExpression()
+    {   ASTToChildren();
+        if( this.children==null ||
+            this.children.length<2 )
+            return null;
+        return (Expression) this.children[1];
+    }
+
+    /**
+     * Returns the class instance suiteable for implementing the result
+     * of this expression. In case of integral binary expressions
+     * that class instance is also the result type of the operation retrieved
+     * by method <code>getJavaClass</code>. In case of relational binary
+     * expressions, that class instance differs from the type retrieved by
+     * <code>getJavaClass</code>, because relational binary expressions
+     * have a boolean result type which does not depend of the operand types.
+     * @return the common operand type
+     */
+    public Class getCommonOperandType()
+    {   return this.commonOperandType;
+    }
+
+    /**
+     * Sets the common operand type for this binary expression.
+     * @param clazz the common operand type
+     */
+    public void setCommonOperandType(Class clazz)
+    {   this.commonOperandType = clazz;
+    }
+
+    Class computeJavaClass( Class left, Class right )
+    {   Class clazz = null;
+        if( left!=null && right!=null )
+        {   if( (BigDecimal.class.isAssignableFrom(left) &&
+                 Number.class.isAssignableFrom(right)) ||
+                (BigDecimal.class.isAssignableFrom(right) &&
+                 Number.class.isAssignableFrom(left)) ||
+                (BigInteger.class.isAssignableFrom(left) &&
+                 (right==Float.class || right==Double.class)) ||
+                (BigInteger.class.isAssignableFrom(right) &&
+                 (left==Float.class || left==Double.class)) )
+                clazz = BigDecimal.class;
+            else if( (BigInteger.class.isAssignableFrom(left) &&
+                      Number.class.isAssignableFrom(right)) ||
+                     (BigInteger.class.isAssignableFrom(right) &&
+                      Number.class.isAssignableFrom(left)) )
+                clazz = BigInteger.class;
+            else if( (Double.class.isAssignableFrom(left) &&
+                      Number.class.isAssignableFrom(right)) ||
+                     (Double.class.isAssignableFrom(right) &&
+                      Number.class.isAssignableFrom(left)) )
+                clazz = Double.class;
+            else if( (Float.class.isAssignableFrom(left) &&
+                      Number.class.isAssignableFrom(right)) ||
+                     (Float.class.isAssignableFrom(right) &&
+                      Number.class.isAssignableFrom(left)) )
+                clazz = Float.class;
+            else if( (Long.class.isAssignableFrom(left) &&
+                      Number.class.isAssignableFrom(right)) ||
+                     (Long.class.isAssignableFrom(right) &&
+                      Number.class.isAssignableFrom(left)) )
+                clazz = Long.class;
+            else if( (Integer.class.isAssignableFrom(left) &&
+                      Number.class.isAssignableFrom(right)) ||
+                     (Integer.class.isAssignableFrom(right) &&
+                      Number.class.isAssignableFrom(left)) ||
+                     (Short.class.isAssignableFrom(left) &&
+                      Number.class.isAssignableFrom(right)) ||
+                     (Short.class.isAssignableFrom(right) &&
+                      Number.class.isAssignableFrom(left)) ||
+                     (Byte.class.isAssignableFrom(left) &&
+                      Number.class.isAssignableFrom(right)) )
+                clazz = Integer.class;
+            else if( Boolean.class.isAssignableFrom(left) &&
+                     Boolean.class.isAssignableFrom(right) )
+                clazz = Boolean.class;
+            else if( this instanceof EqualsExpression ||
+                     this instanceof NotEqualsExpression )
+                clazz = Object.class;
+            else
+                throw new JDOQueryException( msg.msg("EXC_IncompatibleTypes", left, right, this) ); //NOI18N
+        }
+        return clazz;
+    }
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/BooleanLiteralExpr.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/BooleanLiteralExpr.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/BooleanLiteralExpr.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/BooleanLiteralExpr.java Sun May 22 11:08:57 2005
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes;
+import org.apache.jdo.jdoql.tree.BooleanLiteralExpression;
+import org.apache.jdo.jdoql.tree.NodeVisitor;
+
+
+/**
+ * This node represents a boolean literal such as <code>true</code> or
+ * <code>false</code>. It does not have any children.
+ *
+ * @author Michael Watzek
+ */
+public final class BooleanLiteralExpr 
+    extends ConstantExpr implements BooleanLiteralExpression
+{
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public BooleanLiteralExpr()
+    {}
+
+    /**
+     * The noarg constructor is needed for ANTLR support.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public BooleanLiteralExpr(antlr.Token token)
+    {   initialize( token );
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param b the boolean value
+     */
+    BooleanLiteralExpr(Boolean b)
+    {   super( JDOQLTokenTypes.BOOLEAN_LITERAL, b.toString(), b ); //NOI18N
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param b the boolean value
+     */
+    BooleanLiteralExpr(boolean b)
+    {   this( new Boolean(b) );
+    }
+
+    /**
+     * Returns the boolean value represented by this expression.
+     * @return the boolean value
+     */
+    public boolean getBoolean()
+    {   return ((Boolean)this.value).booleanValue();
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     */
+    public void arrive(NodeVisitor visitor)
+    {   visitor.arrive( this );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param results the result array
+     * @return the object returned by the visitor instance
+     */
+    public Object leave(NodeVisitor visitor, Object[] results)
+    {   return visitor.leave( this, results );
+    }
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ByteLiteralExpr.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ByteLiteralExpr.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ByteLiteralExpr.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ByteLiteralExpr.java Sun May 22 11:08:57 2005
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes;
+import org.apache.jdo.jdoql.tree.ByteLiteralExpression;
+import org.apache.jdo.jdoql.tree.NodeVisitor;
+
+
+/**
+ * This node represents a byte literal. It does not have any children.
+ *
+ * @author Michael Watzek
+ */
+public final class ByteLiteralExpr
+    extends ConstantExpr implements ByteLiteralExpression
+{
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public ByteLiteralExpr()
+    {}
+
+    /**
+     * The noarg constructor is needed for ANTLR support.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public ByteLiteralExpr(antlr.Token token)
+    {   initialize( token );
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param b the byte value
+     */
+    ByteLiteralExpr(Byte b)
+    {   super( JDOQLTokenTypes.BYTE_LITERAL, b.toString(), b ); //NOI18N
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param b the byte value
+     */
+    ByteLiteralExpr(byte b)
+    {   this( new Byte(b) );
+    }
+
+    /**
+     * Returns the byte value represented by this expression.
+     * @return the byte value
+     */
+    public byte getByte()
+    {   return ((Byte)this.value).byteValue();
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     */
+    public void arrive(NodeVisitor visitor)
+    {   visitor.arrive( this );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param results the result array
+     * @return the object returned by the visitor instance
+     */
+    public Object leave(NodeVisitor visitor, Object[] results)
+    {   return visitor.leave( this, results );
+    }
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CandidateClassImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CandidateClassImpl.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CandidateClassImpl.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CandidateClassImpl.java Sun May 22 11:08:57 2005
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes;
+import org.apache.jdo.jdoql.tree.CandidateClass;
+import org.apache.jdo.jdoql.tree.Node;
+import org.apache.jdo.jdoql.tree.NodeVisitor;
+
+
+/**
+ * This node represents the candidate class of a query.
+ * The candidate class defines the type of instances in the
+ * candidate collection on which the filter expression is applied.
+ *
+ * @author Michael Watzek
+ */
+public final class CandidateClassImpl extends NodeImpl implements CandidateClass
+{
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public CandidateClassImpl()
+    {}
+
+    /**
+     * The noarg constructor is needed for ANTLR support.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public CandidateClassImpl(antlr.Token token)
+    {   initialize( token );
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor and
+     * sets the specified candidate class.
+     * @param type the type instance wrapping the candidate class
+     */
+    CandidateClassImpl(TypeImpl type)
+    {   super( JDOQLTokenTypes.CANDIDATE_CLASS, "CandidateClass", 
+               type.getJavaClass() ); //NOI18N
+        setChildren( new Node[] {type} );
+    }
+
+    /**
+     * Sets the candidate class for this instance.
+     * This method is used by semantic analysis only.
+     * @param clazz the candidate clazz
+     */
+    public void setCandidateClass(Class clazz)
+    {   ASTToChildren();
+        if( this.children==null )
+            setChildren( new Node[] {new TypeImpl(clazz)} );
+        TypeImpl type = (TypeImpl) this.children[0];
+        type.clazz = clazz;
+        this.clazz = clazz;
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     */
+    public void arrive(NodeVisitor visitor)
+    {   visitor.arrive( this );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param results the result array
+     * @return the object returned by the visitor instance
+     */
+    public Object leave(NodeVisitor visitor, Object[] results)
+    {   return visitor.leave( this, results );
+    }
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CastExpr.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CastExpr.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CastExpr.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CastExpr.java Sun May 22 11:08:57 2005
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes;
+import org.apache.jdo.jdoql.JDOQueryException;
+import org.apache.jdo.jdoql.tree.CastExpression;
+import org.apache.jdo.jdoql.tree.Expression;
+import org.apache.jdo.jdoql.tree.Node;
+import org.apache.jdo.jdoql.tree.NodeVisitor;
+import org.apache.jdo.jdoql.tree.Type;
+
+
+
+/**
+ * This node represents a cast expression. It has a result type and a child
+ * which corresponds with the expression to cast.
+ *
+ * @author Michael Watzek
+ */
+public final class CastExpr extends Expr implements CastExpression
+{
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public CastExpr()
+    {}
+
+    /**
+     * The noarg constructor is needed for ANTLR support.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public CastExpr(antlr.Token token)
+    {   initialize( token );
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param type the type instance wrapping the Java class to which
+     * the argument <code>expr</code> is casted
+     * @param expr the expression to cast
+     * @exception JDOQueryException if the result type of expr cannot
+     * be casted to clazz
+     */
+    CastExpr(Type type, Expression expr)
+    {   super( JDOQLTokenTypes.CAST, "Cast", type.getJavaClass() ); //NOI18N
+        setChildren( new Node[] {type, expr} );
+        if( expr.getJavaClass()!=null &&
+            !clazz.isAssignableFrom(expr.getJavaClass()) &&
+            !expr.getJavaClass().isAssignableFrom(clazz) )
+            throw new JDOQueryException( 
+                msg.msg("EXC_IllegalCast", expr.getJavaClass().getName(), 
+                        clazz.getName(), this) ); //NOI18N
+    }
+
+    /**
+     * Returns the string representation of the Java class,
+     * to which this node's expression is casted.
+     * @return the Java type name
+     */
+    public String getTypeName()
+    {   ASTToChildren();
+        if( this.children==null ||
+            this.children.length<1 )
+            return null;
+        return ((Type)this.children[0]).getTypeName();
+    }
+
+    /**
+     * Returns the node's cast expression.
+     * @return the node's cast expression
+     */
+    public Expression getExpression()
+    {   ASTToChildren();
+        if( this.children==null ||
+            this.children.length<2 )
+            return null;
+        return (Expression) this.children[1];
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     */
+    public void arrive(NodeVisitor visitor)
+    {   visitor.arrive( this );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param results the result array
+     * @return the object returned by the visitor instance
+     */
+    public Object leave(NodeVisitor visitor, Object[] results)
+    {   return visitor.leave( this, results );
+    }
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CharLiteralExpr.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CharLiteralExpr.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CharLiteralExpr.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/CharLiteralExpr.java Sun May 22 11:08:57 2005
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes;
+import org.apache.jdo.jdoql.tree.CharLiteralExpression;
+import org.apache.jdo.jdoql.tree.NodeVisitor;
+
+
+/**
+ * This node represents a character literal. It does not have any children.
+ *
+ * @author Michael Watzek
+ */
+public final class CharLiteralExpr 
+    extends ConstantExpr implements CharLiteralExpression
+{
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public CharLiteralExpr()
+    {}
+
+    /**
+     * The noarg constructor is needed for ANTLR support.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public CharLiteralExpr(antlr.Token token)
+    {   initialize( token );
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param c the char value
+     */
+    CharLiteralExpr(Character c)
+    {   super( JDOQLTokenTypes.CHAR_LITERAL, c.toString(), c ); //NOI18N
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param c the char value
+     */
+    CharLiteralExpr(char c)
+    {   this( new Character(c) );
+    }
+
+    /**
+     * Returns the char value represented by this expression.
+     * @return the char value
+     */
+    public char getChar()
+    {   return ((Character)this.value).charValue();
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     */
+    public void arrive(NodeVisitor visitor)
+    {   visitor.arrive( this );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param results the result array
+     * @return the object returned by the visitor instance
+     */
+    public Object leave(NodeVisitor visitor, Object[] results)
+    {   return visitor.leave( this, results );
+    }
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ComplementExpr.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ComplementExpr.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ComplementExpr.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ComplementExpr.java Sun May 22 11:08:57 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes;
+import org.apache.jdo.jdoql.tree.ComplementExpression;
+import org.apache.jdo.jdoql.tree.Expression;
+import org.apache.jdo.jdoql.tree.NodeVisitor;
+
+
+/**
+ * This node represents a bitwise not operator.
+ * A bitwise not operator is a unary expression.
+ * The string representation of this operator is <code>~</code>.
+ *
+ * @author Michael Watzek
+ */
+public final class ComplementExpr 
+    extends UnaryExpr implements ComplementExpression
+{
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public ComplementExpr()
+    {}
+
+    /**
+     * The noarg constructor is needed for ANTLR support.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public ComplementExpr(antlr.Token token)
+    {   initialize( token );
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param expr the expression to compute the complement for
+     */
+    ComplementExpr(Expression expr)
+    {   super( JDOQLTokenTypes.BNOT, "Complement", expr ); //NOI18N
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     */
+    public void arrive(NodeVisitor visitor)
+    {   visitor.arrive( this );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param results the result array
+     * @return the object returned by the visitor instance
+     */
+    public Object leave(NodeVisitor visitor, Object[] results)
+    {   return visitor.leave( this, results );
+    }
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConditionalAndExpr.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConditionalAndExpr.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConditionalAndExpr.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConditionalAndExpr.java Sun May 22 11:08:57 2005
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes;
+import org.apache.jdo.jdoql.tree.ConditionalAndExpression;
+import org.apache.jdo.jdoql.tree.Expression;
+import org.apache.jdo.jdoql.tree.NodeVisitor;
+
+
+/**
+ * This node represents a conditional and operator.
+ * A conditional and operator is a binary expression.
+ * The string representation of this operator is <code>&&</code>.
+ *
+ * @author Michael Watzek
+ */
+public final class ConditionalAndExpr 
+    extends BinaryExpr implements ConditionalAndExpression
+{
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public ConditionalAndExpr()
+    {}
+
+    /**
+     * The noarg constructor is needed for ANTLR support.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public ConditionalAndExpr(antlr.Token token)
+    {   initialize( token );
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param left the left operand
+     * @param right the right operand
+     */
+    ConditionalAndExpr(Expression left, Expression right)
+    {   super( JDOQLTokenTypes.AND, "ConditionalAnd", Boolean.class, 
+               left, right ); //NOI18N
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     */
+    public void arrive(NodeVisitor visitor)
+    {   visitor.arrive( this );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param results the result array
+     * @return the object returned by the visitor instance
+     */
+    public Object leave(NodeVisitor visitor, Object[] results)
+    {   return visitor.leave( this, results );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param resultOfPreviousChild the result computed by leaving the 
+     * previous child node
+     * @param indexOfNextChild the index in the children array of the 
+     * next child to walk 
+     * @return the boolean value returned by the visitor instance
+     */
+    public boolean walkNextChild(NodeVisitor visitor, 
+                                 Object resultOfPreviousChild, 
+                                 int indexOfNextChild)
+    {   return visitor.walkNextChild( this, resultOfPreviousChild, 
+                                      indexOfNextChild );
+    }
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConditionalOrExpr.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConditionalOrExpr.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConditionalOrExpr.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConditionalOrExpr.java Sun May 22 11:08:57 2005
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes;
+import org.apache.jdo.jdoql.tree.ConditionalOrExpression;
+import org.apache.jdo.jdoql.tree.Expression;
+import org.apache.jdo.jdoql.tree.NodeVisitor;
+
+
+/**
+ * This node represents a conditional or operator.
+ * A conditional or operator is a binary expression.
+ * The string representation of this operator is <code>||</code>.
+ *
+ * @author Michael Watzek
+ */
+public final class ConditionalOrExpr
+    extends BinaryExpr implements ConditionalOrExpression
+{
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public ConditionalOrExpr()
+    {}
+
+    /**
+     * The noarg constructor is needed for ANTLR support.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public ConditionalOrExpr(antlr.Token token)
+    {   initialize( token );
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param left the first child
+     * @param right the second child
+     */
+    ConditionalOrExpr(Expression left, Expression right)
+    {   super( JDOQLTokenTypes.OR, "ConditionalOr", Boolean.class, 
+               left, right ); //NOI18N
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     */
+    public void arrive(NodeVisitor visitor)
+    {   visitor.arrive( this );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param results the result array
+     * @return the object returned by the visitor instance
+     */
+    public Object leave(NodeVisitor visitor, Object[] results)
+    {   return visitor.leave( this, results );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param resultOfPreviousChild the result computed by leaving the
+     * previous child node.
+     * @param indexOfNextChild the index in the children array of the
+     * next child to walk
+     * @return the boolean value returned by the visitor instance
+     */
+    public boolean walkNextChild(NodeVisitor visitor,
+                                 Object resultOfPreviousChild,
+                                 int indexOfNextChild)
+    {   return visitor.walkNextChild( this, resultOfPreviousChild,
+                                      indexOfNextChild );
+    }
+}

Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConstantExpr.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConstantExpr.java?rev=171353&view=auto
==============================================================================
--- incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConstantExpr.java (added)
+++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/ConstantExpr.java Sun May 22 11:08:57 2005
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * 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.
+ */
+
+package org.apache.jdo.impl.jdoql.tree;
+
+import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes;
+import org.apache.jdo.jdoql.tree.ConstantExpression;
+import org.apache.jdo.jdoql.tree.NodeVisitor;
+
+
+/**
+ * This node represents a constant expression.
+ * Examples of constant expressions are <code>BooleanLiteralExpression</code> or
+ * <code>ByteLiteralExpression</code>. It does not have any children.
+ *
+ * @author Michael Watzek
+ */
+public class ConstantExpr extends Expr implements ConstantExpression
+{
+    /**
+     * Returns an instance of <code>ConstantExpression</code>.
+     * This method handles <code>null</code> as a constant expression.
+     * @param value the object wrapped by the constant expression
+     * @return the constant expression
+     */
+    public static ConstantExpr newConstant(Object value)
+    {   ConstantExpr constant;
+        if( value instanceof Boolean )
+            constant = new BooleanLiteralExpr( (Boolean)value );
+        else if( value instanceof Byte )
+            constant = new ByteLiteralExpr( (Byte)value );
+        else if( value instanceof Character )
+            constant = new CharLiteralExpr( (Character)value );
+        else if( value instanceof Double )
+            constant = new DoubleLiteralExpr( (Double)value );
+        else if( value instanceof Float )
+            constant = new FloatLiteralExpr( (Float)value );
+        else if( value instanceof Integer )
+            constant = new IntLiteralExpr( (Integer)value );
+        else if( value instanceof Long )
+            constant = new LongLiteralExpr( (Long)value );
+        else if( value instanceof Short )
+            constant = new ShortLiteralExpr( (Short)value );
+        else
+            constant = new ConstantExpr( value );
+        return constant;
+    }
+
+    Object value = null;
+
+    /**
+     * The noarg constructor is needed for ANTLR support and deserialization.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public ConstantExpr()
+    {}
+
+    /**
+     * The noarg constructor is needed for ANTLR support.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     */
+    public ConstantExpr(antlr.Token token)
+    {   initialize( token );
+    }
+
+    /**
+     * This constructor is called by specialized nodes.
+     * The caller must make sure to set the ANTLR tree structure himself
+     * or, call <code>setChildren</code> optionally.
+     * @param tokenType the token tpye
+     * @param tokenName the name of this node
+     */
+    ConstantExpr(int tokenType, String tokenName, Object value)
+    {   super( tokenType, tokenName, value==null?null:value.getClass() );
+        this.value = value;
+    }
+
+    /**
+     * This constructor is called by the query tree instance.
+     * It delegates to the super class constructor.
+     * @param value the value represented by this expression
+     */
+    ConstantExpr(Object value)
+        {   this( JDOQLTokenTypes.CONSTANT, "Constant", value ); // NOI18N
+    }
+
+    /**
+     * Returns the value represented by this expression.
+     * @return the value
+     */
+    public Object getValue()
+    {   return this.value;
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     */
+    public void arrive(NodeVisitor visitor)
+    {   visitor.arrive( this );
+    }
+
+    /**
+     * Delegates to the argument <code>visitor</code>.
+     * @param visitor the node visitor
+     * @param results the result array
+     * @return the object returned by the visitor instance
+     */
+    public Object leave(NodeVisitor visitor, Object[] results)
+    {   return visitor.leave( this, results );
+    }
+}



Mime
View raw message