1 13 package com.tonbeller.jpivot.test.olap; 14 15 import com.tonbeller.jpivot.olap.model.Dimension; 16 import com.tonbeller.jpivot.olap.model.Displayable; 17 import com.tonbeller.jpivot.olap.model.Expression; 18 import com.tonbeller.jpivot.olap.model.Hierarchy; 19 import com.tonbeller.jpivot.olap.model.Level; 20 import com.tonbeller.jpivot.olap.model.Member; 21 import com.tonbeller.jpivot.olap.navi.ExpressionParser; 22 23 public class TestExpressionParser extends TestExtensionSupport implements ExpressionParser { 24 25 public Expression parse(String name) throws InvalidSyntaxException { 26 Dimension[] dims = model().getDimensions(); 27 for (int i = 0; i < dims.length; i++) { 28 Dimension d = dims[i]; 29 if (name.equals(d.getLabel())) 30 return d; 31 Expression e = findHierarchies(name, d.getHierarchies()); 32 if (e != null) 33 return e; 34 } 35 TestMember tm = new TestMember(); 37 tm.setLabel(name); 38 return tm; 39 } 40 41 private Expression findHierarchies(String name, Hierarchy[] hiers) { 42 for (int i = 0; i < hiers.length; i++) { 43 Hierarchy h = hiers[i]; 44 if (name.equals(h.getLabel())) 45 return h; 46 Expression e = findLevels(name, h.getLevels()); 47 if (e != null) 48 return e; 49 } 50 return null; 51 } 52 53 private Expression findLevels(String name, Level[] levels) { 54 for (int i = 0; i < levels.length; i++) { 55 Level l = levels[i]; 56 if (name.equals(l.getLabel())) 57 return l; 58 } 59 return null; 60 } 61 62 public String unparse(Expression expr) { 63 return ((Displayable) expr).getLabel(); 64 } 65 66 public Member lookupMember(String uniqueName) throws InvalidSyntaxException { 67 Object obj = parse(uniqueName); 68 if (obj instanceof Member) 69 return (Member)obj; 70 return null; 71 } 72 73 public Level lookupLevel(String uniqueName) throws InvalidSyntaxException { 74 Object obj = parse(uniqueName); 75 if (obj instanceof Level) 76 return (Level)obj; 77 return null; 78 } 79 80 public Hierarchy lookupHierarchy(String uniqueName) throws InvalidSyntaxException { 81 Object obj = parse(uniqueName); 82 if (obj instanceof Hierarchy) 83 return (Hierarchy)obj; 84 return null; 85 } 86 87 public Dimension lookupDimension(String uniqueName) throws InvalidSyntaxException { 88 Object obj = parse(uniqueName); 89 if (obj instanceof Dimension) 90 return (Dimension)obj; 91 return null; 92 } 93 94 } | Popular Tags |