1 13 package com.tonbeller.jpivot.mondrian; 14 15 import mondrian.olap.SchemaReader; 16 17 import com.tonbeller.jpivot.olap.model.Alignable; 18 import com.tonbeller.jpivot.olap.model.Level; 19 import com.tonbeller.jpivot.olap.model.Member; 20 import com.tonbeller.jpivot.olap.model.Property; 21 import com.tonbeller.jpivot.olap.model.Visitor; 22 import com.tonbeller.jpivot.olap.model.impl.PropertyImpl; 23 import com.tonbeller.jpivot.olap.query.MDXMember; 24 25 28 public class MondrianMember implements Member, MDXMember { 29 30 private mondrian.olap.Member monMember; 31 private MondrianLevel level; 32 private MondrianModel model; 33 private Property[] properties = null; 34 35 40 protected MondrianMember( 41 mondrian.olap.Member monMember, 42 MondrianLevel level, 43 MondrianModel model) { 44 this.monMember = monMember; 45 this.level = level; 46 this.model = model; 47 level.addMember(this); 48 49 mondrian.olap.Property[] props = monMember.getLevel().getProperties(); 50 if (props != null) { 51 properties = new Property[props.length]; 52 for (int i = 0; i < props.length; i++) { 53 MondrianProp prop = new MondrianProp(); 54 if (props[i].getType() == mondrian.olap.Property.Datatype.TYPE_NUMERIC) 55 prop.setAlignment(Alignable.Alignment.RIGHT); 56 String propName = props[i].getName(); 57 prop.setName(propName); 58 String caption = props[i].getCaption(); 59 if (caption != null && !caption.equals(propName)){ 60 prop.setLabel(caption); 63 prop.setMondrianName(propName); 64 prop.setNormalizable(false); 67 } else { 68 prop.setLabel(propName); 69 } 70 String propValue = monMember.getPropertyFormattedValue(propName); 71 prop.setValue(propValue); 72 properties[i] = prop; 73 } 74 } 75 76 } 77 78 public String getLabel() { 79 return monMember.getCaption(); 80 } 81 82 85 public int getRootDistance() { 86 SchemaReader scr = model.getMonConnection().getSchemaReader(); 87 mondrian.olap.Member m = monMember; 88 int rootDistance = 0; 89 while (true) { 90 m = scr.getMemberParent(m); 91 if (m == null) 92 return rootDistance; 93 rootDistance += 1; 94 } 95 } 96 97 100 public Level getLevel() { 101 return level; 102 } 103 104 107 public Property[] getProperties() { 108 109 if (properties == null || properties.length == 0) 110 return new Property[0]; 112 return properties; 113 } 114 115 119 public Member getParent() { 120 mondrian.olap.Member monParent = monMember.getParentMember(); 121 MondrianMember parent = model.addMember(monParent); 122 return parent; 123 } 124 125 129 public String getParentUniqueName() { 130 return monMember.getParentUniqueName(); 131 } 132 133 136 public boolean isAll() { 137 return monMember.isAll(); 138 } 139 140 141 144 public Property getProperty(String name) { 145 146 if (properties == null || properties.length == 0) 147 return null; 148 149 for (int i = 0; i < properties.length; i++) { 150 if (name.equals(properties[i].getName())) 151 return properties[i]; 152 } 153 154 return null; } 156 157 160 public void accept(Visitor visitor) { 161 visitor.visitMember(this); 162 } 163 164 168 public mondrian.olap.Member getMonMember() { 169 return monMember; 170 } 171 172 175 public String getUniqueName() { 176 return monMember.getUniqueName(); 177 } 178 181 public boolean isCalculated() { 182 return monMember.isCalculated(); 183 } 184 185 public Object getRootDecoree() { 186 return this; 187 } 188 189 192 public boolean equals(Object obj) { 193 if (!(obj instanceof MondrianMember)) 194 return false; 195 mondrian.olap.Member mm = ((MondrianMember) obj).getMonMember(); 196 return monMember.equals(mm); 197 } 198 199 202 public int hashCode() { 203 return monMember.hashCode(); 204 } 205 206 210 public static class MondrianProp extends PropertyImpl { 211 String mondrianName = null; 213 216 public String getMondrianName() { 217 return mondrianName; 218 } 219 220 223 public void setMondrianName(String mondrianName) { 224 this.mondrianName = mondrianName; 225 } 226 } 228 229 } | Popular Tags |