1 25 package org.objectweb.jonas_ejb.lib; 26 27 28 import java.util.ArrayList ; 29 import java.util.Iterator ; 30 import java.util.Map ; 31 import java.util.Stack ; 32 33 import org.objectweb.jonas_ejb.deployment.ejbql.ASTEJBQL; 34 import org.objectweb.jonas_ejb.deployment.ejbql.ASTCmpPathExpression; 35 import org.objectweb.jonas_ejb.deployment.ejbql.ASTOrderByClause; 36 import org.objectweb.jonas_ejb.deployment.ejbql.ASTOrderByItem; 37 import org.objectweb.jonas_ejb.deployment.ejbql.ASTPath; 38 import org.objectweb.jonas_ejb.deployment.ejbql.SimpleNode; 39 40 import org.objectweb.medor.api.Field; 41 import org.objectweb.medor.query.api.OrderField; 42 import org.objectweb.medor.query.api.QueryTreeField; 43 import org.objectweb.medor.query.lib.BasicOrderField; 44 45 51 public class EjbqlOrderByVisitor extends EjbqlAbstractVisitor { 52 53 Map fields; 54 ArrayList orderFields; 55 56 61 public EjbqlOrderByVisitor(ASTEJBQL ejbql, Map _fields) throws Exception { 62 orderFields = new ArrayList (); 63 fields = _fields; 64 visit(ejbql); 65 } 66 67 70 public OrderField[] getOrderFields() { 71 OrderField[] ofs = new OrderField[orderFields.size()]; 72 Iterator itr = orderFields.iterator(); 73 for (int i=0; itr.hasNext(); i++) { 74 ofs[i] = (OrderField) itr.next(); 75 } 76 return ofs; 77 } 78 79 80 84 public Object visit(ASTOrderByClause node, Object data) { 85 visit((SimpleNode) node, data); 86 return null; 87 } 88 89 92 public Object visit(ASTOrderByItem node, Object data) { 93 visit((SimpleNode) node, data); 94 QueryTreeField qtf = (QueryTreeField) ((Stack ) data).pop(); 95 orderFields.add(new BasicOrderField(qtf, !node.asc)); 96 return null; 97 } 98 99 105 public Object visit(ASTCmpPathExpression node, Object data) { 106 visit((SimpleNode) node, data); 107 try { 108 String path = (String ) ((ASTPath) ((Stack ) data).pop()).value; 109 ((Stack ) data).push((Field) fields.get(path)); 111 } catch (Exception e) { 112 throw new VisitorException(e); 113 } 114 return null; 115 } 116 117 120 public Object visit(ASTPath node, Object data) { 121 ((Stack ) data).push(node); 122 return null; 123 } 124 125 } 126 | Popular Tags |