001 /* 002 // $Id: //open/mondrian/src/main/mondrian/rolap/RolapProperty.java#15 $ 003 // This software is subject to the terms of the Common Public License 004 // Agreement, available at the following URL: 005 // http://www.opensource.org/licenses/cpl.html. 006 // Copyright (C) 2001-2002 Kana Software, Inc. 007 // Copyright (C) 2001-2007 Julian Hyde and others 008 // All Rights Reserved. 009 // You must accept the terms of that agreement to use this software. 010 */ 011 package mondrian.rolap; 012 013 import java.lang.reflect.Constructor; 014 015 import mondrian.olap.MondrianDef; 016 import mondrian.olap.Property; 017 import mondrian.olap.PropertyFormatter; 018 import mondrian.olap.Util; 019 020 import org.apache.log4j.Logger; 021 022 /** 023 * <code>RolapProperty</code> is the definition of a member property. 024 * 025 * @version $Id: //open/mondrian/src/main/mondrian/rolap/RolapProperty.java#15 $ 026 * @author jhyde 027 */ 028 class RolapProperty extends Property { 029 030 private static final Logger LOGGER = Logger.getLogger(RolapProperty.class); 031 032 /** Array of RolapProperty of length 0. */ 033 static final RolapProperty[] emptyArray = new RolapProperty[0]; 034 035 private final PropertyFormatter formatter; 036 private final String caption; 037 038 /** The column or expression which yields the property's value. */ 039 private final MondrianDef.Expression exp; 040 041 042 /** 043 * Creates a RolapProperty. 044 * 045 * @param name Name of property 046 * @param type Datatype 047 * @param exp Expression for property's value; often a literal 048 * @param formatterDef Name of formatter class (must implement 049 * {@link PropertyFormatter}), or null 050 * @param caption Caption 051 * @param internal Whether property is internal 052 */ 053 RolapProperty( 054 String name, 055 Datatype type, 056 MondrianDef.Expression exp, 057 String formatterDef, 058 String caption, 059 boolean internal) 060 { 061 super(name, type, -1, internal, false, false, null); 062 this.exp = exp; 063 this.caption = caption; 064 this.formatter = makePropertyFormatter(formatterDef); 065 } 066 067 private PropertyFormatter makePropertyFormatter(String formatterDef) { 068 if (!Util.isEmpty(formatterDef)) { 069 // there is a special property formatter class 070 try { 071 Class<PropertyFormatter> clazz = 072 (Class<PropertyFormatter>) Class.forName(formatterDef); 073 Constructor<PropertyFormatter> ctor = clazz.getConstructor(); 074 return ctor.newInstance(); 075 } catch (Exception e) { 076 StringBuilder buf = new StringBuilder(64); 077 buf.append("RolapProperty.makePropertyFormatter: "); 078 buf.append("Could not create PropertyFormatter from"); 079 buf.append("formatterDef \""); 080 buf.append(formatterDef); 081 buf.append("\""); 082 LOGGER.error(buf.toString(), e); 083 } 084 } 085 return null; 086 } 087 088 MondrianDef.Expression getExp() { 089 return exp; 090 } 091 092 public PropertyFormatter getFormatter() { 093 return formatter; 094 } 095 096 /** 097 * @return Returns the caption. 098 */ 099 public String getCaption() { 100 if (caption == null) { 101 return getName(); 102 } 103 return caption; 104 } 105 } 106 107 // End RolapProperty.java