KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > olap > model > impl > PropertyExprImpl


1 /*
2  * ====================================================================
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) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.olap.model.impl;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17
18 import com.tonbeller.jpivot.olap.model.Expression;
19 import com.tonbeller.jpivot.olap.model.FunCallExpr;
20 import com.tonbeller.jpivot.olap.model.PropertyExpr;
21 import com.tonbeller.jpivot.olap.model.StringExpr;
22 import com.tonbeller.jpivot.olap.model.Visitor;
23 import com.tonbeller.jpivot.olap.model.VisitorSupportSloppy;
24
25 /**
26  * PropertyExpr implementation
27  */

28 public class PropertyExprImpl implements PropertyExpr {
29
30   private Expression valueExpr;
31   private String JavaDoc name;
32
33   /**
34    * c'tor
35    * @param name
36    */

37   public PropertyExprImpl(String JavaDoc name, Expression valueExpr) {
38     this.name = name;
39     this.valueExpr = valueExpr;
40   }
41   
42   /**
43    * @return the value expression
44    * @see com.tonbeller.jpivot.olap.model.PropertyExpr#getValueExpr()
45    */

46   public Expression getValueExpr() {
47     return valueExpr;
48   }
49
50   /**
51    * @return the property name
52    * @see com.tonbeller.jpivot.olap.model.PropertyExpr#getName()
53    */

54   public String JavaDoc getName() {
55     return name;
56   }
57
58   /**
59    * walk expression tree and find possible choices
60    * @see com.tonbeller.jpivot.olap.model.PropertyExpr#getChoices()
61    */

62   public String JavaDoc[] getChoices() {
63
64     final List JavaDoc choices = new ArrayList JavaDoc();
65
66     this.accept(new VisitorSupportSloppy() {
67       // ParameterExpr not supported
68
public void visitStringExpr(StringExpr v) {
69         choices.add(v.getValue());
70       }
71
72       public void visitFunCallExpr(FunCallExpr v) {
73         Expression[] args = v.getArgs();
74         for (int i = 0; i < args.length; i++) {
75           args[i].accept(this);
76         }
77       }
78       
79       public void visitPropertyExpr(PropertyExpr v) {
80         Expression exp = v.getValueExpr();
81         exp.accept(this);
82       }
83       
84     });
85
86     return (String JavaDoc[]) choices.toArray(new String JavaDoc[0]);
87   }
88
89   /**
90    * visitor implementation
91    * @see com.tonbeller.jpivot.olap.model.Visitable#accept
92    */

93   public void accept(Visitor visitor) {
94     visitor.visitPropertyExpr(this);
95   }
96
97 } // PropertyExpr
98
Popular Tags