1 10 package mondrian.calc.impl; 11 12 import mondrian.olap.*; 13 import mondrian.olap.type.Type; 14 import mondrian.olap.type.ScalarType; 15 import mondrian.calc.*; 16 17 32 public class MemberValueCalc extends GenericCalc { 33 private final MemberCalc[] memberCalcs; 34 private final Member[] savedMembers; 35 36 public MemberValueCalc(Exp exp, MemberCalc[] memberCalcs) { 37 super(exp); 38 final Type type = exp.getType(); 39 assert type instanceof ScalarType : exp; 40 this.memberCalcs = memberCalcs; 41 this.savedMembers = new Member[memberCalcs.length]; 42 } 43 44 public Object evaluate(Evaluator evaluator) { 45 for (int i = 0; i < memberCalcs.length; i++) { 46 MemberCalc memberCalc = memberCalcs[i]; 47 final Member member = memberCalc.evaluateMember(evaluator); 48 if (member == null || 49 member.isNull()) { 50 for (int j = 0; j < i; j++) { 53 evaluator.setContext(savedMembers[j]); 54 } 55 return null; 56 } 57 savedMembers[i] = evaluator.setContext(member); 58 } 59 final Object o = evaluator.evaluateCurrent(); 60 evaluator.setContext(savedMembers); 61 return o; 62 } 63 64 public Calc[] getCalcs() { 65 return memberCalcs; 66 } 67 68 public boolean dependsOn(Dimension dimension) { 69 if (super.dependsOn(dimension)) { 70 return true; 71 } 72 for (MemberCalc memberCalc : memberCalcs) { 73 if (memberCalc.getType().usesDimension(dimension, true)) { 75 return false; 76 } 77 } 78 return true; 79 } 80 } 81 82 | Popular Tags |