1 package com.genimen.djeneric.repository.oql.core.util; 2 3 import java.util.StringTokenizer ; 4 5 import com.genimen.djeneric.repository.DjAssociation; 6 import com.genimen.djeneric.repository.DjValueObject; 7 import com.genimen.djeneric.repository.exceptions.DjenericException; 8 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException; 9 import com.genimen.djeneric.repository.oql.core.MatchException; 10 import com.genimen.djeneric.repository.oql.core.SimpleNode; 11 import com.genimen.djeneric.repository.oql.core.nodes.MatchingContext; 12 13 public class ObjectPath 14 { 15 public final static Object evaluateProperty(String path, MatchingContext context, SimpleNode contextNode) 16 throws MatchException 17 { 18 StringTokenizer st = new StringTokenizer (path, "."); 19 20 String curId = st.nextToken(); 21 Object obj; 22 try 23 { 24 obj = context.getObject().get(curId); 25 } 26 catch (DjenericException e) 27 { 28 throw new MatchException(e.getMessage(), contextNode.beginLine, contextNode.beginColumn); 29 } 30 31 return evaluatePath(contextNode, st, curId, obj); 32 } 33 34 private static Object evaluatePath(SimpleNode contextNode, StringTokenizer st, String curId, Object obj) 35 throws MatchException 36 { 37 try 38 { 39 while (st.hasMoreElements()) 40 { 41 if (!(obj instanceof DjValueObject)) throw new MatchException("Identifier " + curId + " is not a model object", 42 contextNode.beginLine, contextNode.beginColumn); 43 DjValueObject djo = (DjValueObject) obj; 44 curId = st.nextToken(); 45 try 46 { 47 obj = djo.get(curId); 48 } 49 catch (ObjectNotDefinedException onde) 50 { 51 if (st.hasMoreElements()) throw onde; 53 try 55 { 56 DjAssociation assoc = djo.getDetailAssociationByName(curId); 57 return assoc.getObjects(); 59 } 60 catch (ObjectNotDefinedException discard) 61 { 62 throw onde; 63 } 64 } 65 if (obj == null) return null; 66 } 67 return obj; 68 } 69 catch (DjenericException onde) 70 { 71 throw new MatchException(onde.getMessage(), contextNode.beginLine, contextNode.beginColumn); 72 } 73 } 74 } | Popular Tags |