1 10 package mondrian.rolap; 11 12 import mondrian.olap.*; 13 import mondrian.olap.type.Type; 14 import mondrian.calc.ParameterCompilable; 15 import mondrian.calc.Calc; 16 import mondrian.calc.ExpCompiler; 17 import mondrian.calc.impl.GenericCalc; 18 import mondrian.resource.MondrianResource; 19 20 27 public class RolapSchemaParameter implements Parameter, ParameterCompilable { 28 private final RolapSchema schema; 29 private final String name; 30 private String description; 31 private String defaultExpString; 32 private Type type; 33 private final boolean modifiable; 34 private Object value; 35 private Object cachedDefaultValue; 36 37 RolapSchemaParameter( 38 RolapSchema schema, 39 String name, 40 String defaultExpString, 41 String description, 42 Type type, 43 boolean modifiable) 44 { 45 assert defaultExpString != null; 46 assert name != null; 47 assert schema != null; 48 assert type != null; 49 this.schema = schema; 50 this.name = name; 51 this.defaultExpString = defaultExpString; 52 this.description = description; 53 this.type = type; 54 this.modifiable = modifiable; 55 schema.parameterList.add(this); 56 } 57 58 RolapSchema getSchema() { 59 return schema; 60 } 61 62 public boolean isModifiable() { 63 return modifiable; 64 } 65 66 public Scope getScope() { 67 return Scope.Schema; 68 } 69 70 public Type getType() { 71 return type; 72 } 73 74 public Exp getDefaultExp() { 75 throw new UnsupportedOperationException (); 76 } 77 78 public String getName() { 79 return name; 80 } 81 82 public String getDescription() { 83 return description; 84 } 85 86 public Object getValue() { 87 return value; 88 } 89 90 public void setValue(Object value) { 91 if (!modifiable) { 92 throw MondrianResource.instance().ParameterIsNotModifiable.ex( 93 getName(), getScope().name()); 94 } 95 this.value = value; 96 } 97 98 public Calc compile(ExpCompiler compiler) { 99 Exp defaultExp = compiler.getValidator() 101 .getQuery() 102 .getConnection() 103 .parseExpression(defaultExpString); 104 defaultExp = compiler.getValidator().validate(defaultExp, true); 105 final Calc defaultCalc = defaultExp.accept(compiler); 106 107 return new GenericCalc(defaultExp) { 110 public Calc[] getCalcs() { 111 return new Calc[] {defaultCalc}; 112 } 113 114 public Object evaluate(Evaluator evaluator) { 115 if (value != null) { 116 return value; 117 } 118 if (cachedDefaultValue == null) { 119 cachedDefaultValue = defaultCalc.evaluate(evaluator); 120 } 121 return cachedDefaultValue; 122 } 123 }; 124 } 125 } 126 127 | Popular Tags |