001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2001-2005 Julian Hyde 008// Copyright (C) 2005-2009 Pentaho and others 009// All Rights Reserved. 010*/ 011package mondrian.olap; 012 013import mondrian.olap.type.*; 014 015import org.apache.log4j.Logger; 016 017import java.util.Map; 018 019/** 020 * Skeleton implementation of {@link NamedSet} interface. 021 * 022 * @author jhyde 023 * @since 6 August, 2001 024 */ 025public class SetBase extends OlapElementBase implements NamedSet { 026 027 private static final Logger LOGGER = Logger.getLogger(SetBase.class); 028 029 private String name; 030 private Map<String, Annotation> annotationMap; 031 private String description; 032 private final String uniqueName; 033 private Exp exp; 034 private boolean validated; 035 036 /** 037 * Creates a SetBase. 038 * 039 * @param name Name 040 * @param caption Caption 041 * @param description Description 042 * @param exp Expression 043 * @param validated Whether has been validated 044 * @param annotationMap Annotations 045 */ 046 SetBase( 047 String name, 048 String caption, 049 String description, 050 Exp exp, 051 boolean validated, 052 Map<String, Annotation> annotationMap) 053 { 054 this.name = name; 055 this.annotationMap = annotationMap; 056 this.caption = caption; 057 this.description = description; 058 this.exp = exp; 059 this.validated = validated; 060 this.uniqueName = "[" + name + "]"; 061 } 062 063 public Map<String, Annotation> getAnnotationMap() { 064 return annotationMap; 065 } 066 067 public String getNameUniqueWithinQuery() { 068 return System.identityHashCode(this) + ""; 069 } 070 071 public boolean isDynamic() { 072 return false; 073 } 074 075 public Object clone() { 076 return new SetBase( 077 name, caption, description, exp.clone(), validated, annotationMap); 078 } 079 080 protected Logger getLogger() { 081 return LOGGER; 082 } 083 084 public String getUniqueName() { 085 return uniqueName; 086 } 087 088 public String getName() { 089 return name; 090 } 091 092 public String getQualifiedName() { 093 return null; 094 } 095 096 public String getDescription() { 097 return description; 098 } 099 100 public Hierarchy getHierarchy() { 101 return exp.getType().getHierarchy(); 102 } 103 104 public Dimension getDimension() { 105 return getHierarchy().getDimension(); 106 } 107 108 public OlapElement lookupChild( 109 SchemaReader schemaReader, Id.Segment s, MatchType matchType) 110 { 111 return null; 112 } 113 114 public void setName(String name) { 115 this.name = name; 116 } 117 118 public void setDescription(String description) { 119 this.description = description; 120 } 121 122 public void setAnnotationMap(Map<String, Annotation> annotationMap) { 123 this.annotationMap = annotationMap; 124 } 125 126 public Exp getExp() { 127 return exp; 128 } 129 130 public NamedSet validate(Validator validator) { 131 if (!validated) { 132 exp = validator.validate(exp, false); 133 validated = true; 134 } 135 return this; 136 } 137 138 public Type getType() { 139 Type type = exp.getType(); 140 if (type instanceof MemberType 141 || type instanceof TupleType) 142 { 143 // You can use a member or tuple as the expression for a set. It is 144 // implicitly converted to a set. The expression may not have been 145 // converted yet, so we wrap the type here. 146 type = new SetType(type); 147 } 148 return type; 149 } 150} 151 152// End SetBase.java