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) 2000-2005 Julian Hyde 008// Copyright (C) 2005-2006 Pentaho and others 009// All Rights Reserved. 010*/ 011package mondrian.olap; 012 013import java.io.PrintWriter; 014 015/** 016 * Member property or solve order specification. 017 * 018 * @author jhyde, 1 March, 2000 019 */ 020public class MemberProperty extends QueryPart { 021 022 private final String name; 023 private Exp exp; 024 025 public MemberProperty(String name, Exp exp) { 026 this.name = name; 027 this.exp = exp; 028 } 029 030 protected Object clone() { 031 return new MemberProperty(name, (Exp) exp.clone()); 032 } 033 034 static MemberProperty[] cloneArray(MemberProperty[] x) { 035 MemberProperty[] x2 = new MemberProperty[x.length]; 036 for (int i = 0; i < x.length; i++) { 037 x2[i] = (MemberProperty) x[i].clone(); 038 } 039 return x2; 040 } 041 042 void resolve(Validator validator) { 043 exp = validator.validate(exp, false); 044 } 045 046 public Exp getExp() { 047 return exp; 048 } 049 050 public String getName() { 051 return name; 052 } 053 054 public Object[] getChildren() { 055 return new Exp[] {exp}; 056 } 057 058 public void unparse(PrintWriter pw) { 059 pw.print(name + " = "); 060 exp.unparse(pw); 061 } 062 063 /** 064 * Retrieves a property by name from an array. 065 */ 066 static Exp get(MemberProperty[] a, String name) { 067 // TODO: Linear search may be a performance problem. 068 for (int i = 0; i < a.length; i++) { 069 if (Util.equalName(a[i].name, name)) { 070 return a[i].exp; 071 } 072 } 073 return null; 074 } 075} 076 077 078// End MemberProperty.java