KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > olap > model > impl > CellBase


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13
14 package com.tonbeller.jpivot.olap.model.impl;
15
16 import java.util.ArrayList JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
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 /**
28  * Cell base for both XMLA and Mondrian
29  */

30 public abstract class CellBase implements Cell {
31
32   static Logger logger = Logger.getLogger(CellBase.class);
33
34   protected String JavaDoc formattedValue;
35   private List JavaDoc properties = null;
36
37   /**
38    * @see com.tonbeller.jpivot.olap.model.Cell#getValue()
39    */

40   public abstract Object JavaDoc getValue();
41
42   /**
43    * @see com.tonbeller.jpivot.olap.model.Cell#getFormat()
44    */

45   public abstract NumberFormat getFormat();
46
47   /**
48    * @return the formatted value String
49    * @see com.tonbeller.jpivot.olap.model.Cell#getFormattedValue()
50    */

51   public String JavaDoc getFormattedValue() {
52     return formattedValue;
53   }
54
55   /**
56    * @see com.tonbeller.jpivot.olap.model.Cell#isNull()
57    */

58   public abstract boolean isNull();
59
60   /**
61    * @see com.tonbeller.jpivot.olap.model.PropertyHolder#getProperties()
62    */

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   /**
71    * @see com.tonbeller.jpivot.olap.model.PropertyHolder#getProperty(String)
72    */

73   public Property getProperty(String JavaDoc name) {
74
75     if (properties == null)
76       return null;
77
78     for (Iterator JavaDoc 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   /**
88    * @see com.tonbeller.jpivot.olap.model.Visitable#accept(Visitor)
89    */

90   public void accept(Visitor visitor) {
91     visitor.visitCell(this);
92   }
93
94   /**
95    * @see com.tonbeller.jpivot.olap.model.Decorator#getRootDecoree()
96    */

97   public Object JavaDoc getRootDecoree() {
98     return this;
99   }
100
101   /**
102    * @param string
103    */

104   public void setFormattedValue(String JavaDoc 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 JavaDoc();
110       properties.addAll(res.getProperties());
111     }
112   }
113
114   /**
115    * add property to cell
116    *
117    * @param prop
118    * @param value
119    */

120   public void addProperty(String JavaDoc prop, String JavaDoc 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 JavaDoc();
131       properties.add(pi);
132     }
133   }
134
135 } // CellBase
136
Popular Tags