EjbqlLimitVisitor.java

00001 
00025 package org.objectweb.jonas_ejb.lib;
00026 
00027 import java.util.Stack;
00028 
00029 import org.objectweb.jonas_ejb.deployment.ejbql.ASTEJBQL;
00030 import org.objectweb.jonas_ejb.deployment.ejbql.ASTInputParameter;
00031 import org.objectweb.jonas_ejb.deployment.ejbql.ASTIntegerLiteral;
00032 import org.objectweb.jonas_ejb.deployment.ejbql.ASTLimitClause;
00033 import org.objectweb.jonas_ejb.deployment.ejbql.ASTLimitExpression;
00034 import org.objectweb.jonas_ejb.deployment.ejbql.ParseException;
00035 import org.objectweb.jonas_ejb.deployment.ejbql.SimpleNode;
00036 
00043 public class EjbqlLimitVisitor extends EjbqlAbstractVisitor {
00044 
00048     private Class[] paramTypes;
00049 
00053     private EjbqlLimiterRange[] ranges = new EjbqlLimiterRange[0];
00054 
00062     public EjbqlLimitVisitor(ASTEJBQL ejbql, Class[] paramTypes) throws Exception {
00063         this.paramTypes = paramTypes;
00064         visit(ejbql);
00065     }
00066 
00071     public EjbqlLimiterRange[] getLimiterRanges() {
00072         return ranges;
00073     }
00074 
00081     public Object visit(ASTLimitClause node, Object data) {
00082         visit((SimpleNode) node, data);
00083         Stack s = (Stack) data;
00084         ranges = new EjbqlLimiterRange[s.size()];
00085         if (s.size() > 1) {
00086             // s = [row, nbr]
00087             ranges[1] = (EjbqlLimiterRange) s.pop();
00088         }
00089         // s = [row]
00090         ranges[0] = (EjbqlLimiterRange) s.pop();
00091         return null;
00092     }
00093 
00100     public Object visit(ASTLimitExpression node, Object data) {
00101         visit((SimpleNode) node, data);
00102         return null;
00103     }
00104 
00112     public Object visit(ASTIntegerLiteral node, Object data) {
00113         ((Stack) data).push(new EjbqlLimiterRange(EjbqlLimiterRange.KIND_LITERAL, ((Long) node.value).intValue()));
00114         return null;
00115     }
00116 
00124     public Object visit(ASTInputParameter node, Object data) {
00125         try {
00126             int pIndex = ((Integer) node.value).intValue() - 1;
00127             if (pIndex >= paramTypes.length) {
00128                 throw new ParseException("Parameter ?" + (pIndex + 1) + " is out of range (max=" + paramTypes.length
00129                         + ")");
00130             }
00131             // TODO : check if the associated parameter type is compatible to
00132             // integer
00133             ((Stack) data).push(new EjbqlLimiterRange(EjbqlLimiterRange.KIND_PARAMETER, pIndex));
00134             return null;
00135         } catch (ParseException e) {
00136             throw new VisitorException(e);
00137         }
00138     }
00139 
00140 }

Generated on Tue Feb 15 15:05:48 2005 for JOnAS by  doxygen 1.3.9.1