KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > rolap > RolapProperty


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/rolap/RolapProperty.java#14 $
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) 2001-2002 Kana Software, Inc.
7 // Copyright (C) 2001-2006 Julian Hyde and others
8 // All Rights Reserved.
9 // You must accept the terms of that agreement to use this software.
10 //
11 // jhyde, 10 August, 2001
12 */

13 package mondrian.rolap;
14
15 import java.lang.reflect.Constructor JavaDoc;
16
17 import mondrian.olap.MondrianDef;
18 import mondrian.olap.Property;
19 import mondrian.olap.PropertyFormatter;
20 import mondrian.olap.Util;
21
22 import org.apache.log4j.Logger;
23
24 /**
25  * <code>RolapProperty</code> is the definition of a member property.
26  */

27 class RolapProperty extends Property {
28
29     private static final Logger LOGGER = Logger.getLogger(RolapProperty.class);
30
31     /** Array of RolapProperty of length 0. */
32     static final RolapProperty[] emptyArray = new RolapProperty[0];
33
34     private final PropertyFormatter formatter;
35     private final String JavaDoc caption;
36
37     /** The column or expression which yields the property's value. */
38     private final MondrianDef.Expression exp;
39
40
41     /**
42      * Creates a RolapProperty.
43      */

44     RolapProperty(
45             String JavaDoc name,
46             Datatype type,
47             MondrianDef.Expression exp,
48             String JavaDoc formatterDef,
49             String JavaDoc caption) {
50         super(name, type, -1, false, false, false, null);
51         this.exp = exp;
52         this.caption = caption;
53         this.formatter = makePropertyFormatter(formatterDef);
54
55     }
56     private PropertyFormatter makePropertyFormatter(String JavaDoc formatterDef) {
57         if (!Util.isEmpty(formatterDef)) {
58             // there is a special property formatter class
59
try {
60                 Class JavaDoc<PropertyFormatter> clazz =
61                     (Class JavaDoc<PropertyFormatter>) Class.forName(formatterDef);
62                 Constructor JavaDoc<PropertyFormatter> ctor = clazz.getConstructor();
63                 return ctor.newInstance();
64             } catch (Exception JavaDoc e) {
65                 StringBuilder JavaDoc buf = new StringBuilder JavaDoc(64);
66                 buf.append("RolapProperty.makePropertyFormatter: ");
67                 buf.append("Could not create PropertyFormatter from");
68                 buf.append("formatterDef \"");
69                 buf.append(formatterDef);
70                 buf.append("\"");
71                 LOGGER.error(buf.toString(), e);
72             }
73         }
74         return null;
75     }
76
77     MondrianDef.Expression getExp() {
78         return exp;
79     }
80
81     public PropertyFormatter getFormatter() {
82         return formatter;
83     }
84
85     /**
86      * @return Returns the caption.
87      */

88     public String JavaDoc getCaption() {
89         if (caption == null) {
90             return getName();
91         }
92         return caption;
93     }
94 }
95
96 // End RolapProperty.java
97
Popular Tags