1 25 package org.objectweb.jonas_ejb.lib; 26 27 import java.util.Stack ; 28 29 import org.objectweb.jonas_ejb.deployment.ejbql.ASTEJBQL; 30 import org.objectweb.jonas_ejb.deployment.ejbql.ASTInputParameter; 31 import org.objectweb.jonas_ejb.deployment.ejbql.ASTIntegerLiteral; 32 import org.objectweb.jonas_ejb.deployment.ejbql.ASTLimitClause; 33 import org.objectweb.jonas_ejb.deployment.ejbql.ASTLimitExpression; 34 import org.objectweb.jonas_ejb.deployment.ejbql.ParseException; 35 import org.objectweb.jonas_ejb.deployment.ejbql.SimpleNode; 36 37 43 public class EjbqlLimitVisitor extends EjbqlAbstractVisitor { 44 45 48 private Class [] paramTypes; 49 50 53 private EjbqlLimiterRange[] ranges = new EjbqlLimiterRange[0]; 54 55 62 public EjbqlLimitVisitor(ASTEJBQL ejbql, Class [] paramTypes) throws Exception { 63 this.paramTypes = paramTypes; 64 visit(ejbql); 65 } 66 67 71 public EjbqlLimiterRange[] getLimiterRanges() { 72 return ranges; 73 } 74 75 81 public Object visit(ASTLimitClause node, Object data) { 82 visit((SimpleNode) node, data); 83 Stack s = (Stack ) data; 84 ranges = new EjbqlLimiterRange[s.size()]; 85 if (s.size() > 1) { 86 ranges[1] = (EjbqlLimiterRange) s.pop(); 88 } 89 ranges[0] = (EjbqlLimiterRange) s.pop(); 91 return null; 92 } 93 94 100 public Object visit(ASTLimitExpression node, Object data) { 101 visit((SimpleNode) node, data); 102 return null; 103 } 104 105 112 public Object visit(ASTIntegerLiteral node, Object data) { 113 ((Stack ) data).push(new EjbqlLimiterRange(EjbqlLimiterRange.KIND_LITERAL, ((Long ) node.value).intValue())); 114 return null; 115 } 116 117 124 public Object visit(ASTInputParameter node, Object data) { 125 try { 126 int pIndex = ((Integer ) node.value).intValue() - 1; 127 if (pIndex >= paramTypes.length) { 128 throw new ParseException("Parameter ?" + (pIndex + 1) + " is out of range (max=" + paramTypes.length 129 + ")"); 130 } 131 ((Stack ) data).push(new EjbqlLimiterRange(EjbqlLimiterRange.KIND_PARAMETER, pIndex)); 134 return null; 135 } catch (ParseException e) { 136 throw new VisitorException(e); 137 } 138 } 139 140 } | Popular Tags |