001    /*
002    // $Id: //open/mondrian/src/main/mondrian/olap/MemberProperty.java#19 $
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) 2000-2002 Kana Software, Inc.
007    // Copyright (C) 2001-2006 Julian Hyde and others
008    // All Rights Reserved.
009    // You must accept the terms of that agreement to use this software.
010    //
011    // jhyde, 1 March, 2000
012    */
013    
014    package mondrian.olap;
015    import java.io.PrintWriter;
016    
017    /**
018     * Member property or solve order specification.
019     */
020    public 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