1 13 14 package com.tonbeller.jpivot.olap.model.impl; 15 16 import java.util.ArrayList ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 20 import org.apache.log4j.Logger; 21 22 import com.tonbeller.jpivot.olap.model.Cell; 23 import com.tonbeller.jpivot.olap.model.NumberFormat; 24 import com.tonbeller.jpivot.olap.model.Property; 25 import com.tonbeller.jpivot.olap.model.Visitor; 26 27 30 public abstract class CellBase implements Cell { 31 32 static Logger logger = Logger.getLogger(CellBase.class); 33 34 protected String formattedValue; 35 private List properties = null; 36 37 40 public abstract Object getValue(); 41 42 45 public abstract NumberFormat getFormat(); 46 47 51 public String getFormattedValue() { 52 return formattedValue; 53 } 54 55 58 public abstract boolean isNull(); 59 60 63 public Property[] getProperties() { 64 if (properties == null) 65 return new Property[0]; 66 else 67 return (Property[]) properties.toArray(new Property[0]); 68 } 69 70 73 public Property getProperty(String name) { 74 75 if (properties == null) 76 return null; 77 78 for (Iterator iter = properties.iterator(); iter.hasNext();) { 79 Property prop = (Property) iter.next(); 80 if (prop.getName().equalsIgnoreCase(name)) 81 return prop; 82 83 } 84 return null; 85 } 86 87 90 public void accept(Visitor visitor) { 91 visitor.visitCell(this); 92 } 93 94 97 public Object getRootDecoree() { 98 return this; 99 } 100 101 104 public void setFormattedValue(String string, FormatStringParser parser) { 105 FormatStringParser.Result res = parser.parse(this, string); 106 formattedValue = res.getFormattedValue(); 107 if (res.getProperties().size() > 0) { 108 if (properties == null) 109 properties = new ArrayList (); 110 properties.addAll(res.getProperties()); 111 } 112 } 113 114 120 public void addProperty(String prop, String value) { 121 Property p = this.getProperty(prop); 122 if (p != null) { 123 ((PropertyImpl) p).setValue(value); 124 } else { 125 PropertyImpl pi = new PropertyImpl(); 126 pi.setName(prop); 127 pi.setLabel(prop); 128 pi.setValue(value); 129 if (properties == null) 130 properties = new ArrayList (); 131 properties.add(pi); 132 } 133 } 134 135 } | Popular Tags |