KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > mdx > UnresolvedFunCall


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/mdx/UnresolvedFunCall.java#8 $
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) 2006-2006 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.mdx;
11
12 import mondrian.olap.*;
13 import mondrian.olap.fun.*;
14 import mondrian.olap.type.Type;
15 import mondrian.calc.Calc;
16 import mondrian.calc.ExpCompiler;
17
18 import java.io.PrintWriter JavaDoc;
19
20 /**
21  * An expression consisting of a named function or operator
22  * applied to a set of arguments. The syntax determines whether this is
23  * called infix, with function call syntax, and so forth.
24  *
25  * @author jhyde
26  * @version $Id: //open/mondrian/src/main/mondrian/mdx/UnresolvedFunCall.java#8 $
27  * @since Sep 28, 2005
28  */

29 public class UnresolvedFunCall extends ExpBase implements FunCall {
30     private final String JavaDoc name;
31     private final Syntax syntax;
32     private final Exp[] args;
33
34     /**
35      * Creates a function call with {@link Syntax#Function} syntax.
36      */

37     public UnresolvedFunCall(String JavaDoc name, Exp[] args) {
38         this(name, Syntax.Function, args);
39     }
40
41     /**
42      * Creates a function call.
43      */

44     public UnresolvedFunCall(String JavaDoc name, Syntax syntax, Exp[] args) {
45         assert name != null;
46         assert syntax != null;
47         assert args != null;
48         this.name = name;
49         this.syntax = syntax;
50         this.args = args;
51         if (syntax == Syntax.Braces) {
52             Util.assertTrue(name.equals("{}"));
53         } else if (syntax == Syntax.Parentheses) {
54             Util.assertTrue(name.equals("()"));
55         } else if (syntax == Syntax.Internal) {
56             Util.assertTrue(name.startsWith("$"));
57         } else {
58             Util.assertTrue(!name.startsWith("$") &&
59                         !name.equals("{}") &&
60                         !name.equals("()"));
61         }
62     }
63
64     public UnresolvedFunCall clone() {
65         return new UnresolvedFunCall(name, syntax, ExpBase.cloneArray(args));
66     }
67
68     public int getCategory() {
69         throw new UnsupportedOperationException JavaDoc();
70     }
71
72     public Type getType() {
73         throw new UnsupportedOperationException JavaDoc();
74     }
75
76     public void unparse(PrintWriter JavaDoc pw) {
77         syntax.unparse(name, args, pw);
78     }
79
80     public Object JavaDoc accept(MdxVisitor visitor) {
81         final Object JavaDoc o = visitor.visit(this);
82         // visit the call's arguments
83
for (Exp arg : args) {
84             arg.accept(visitor);
85         }
86         return o;
87     }
88
89     public Exp accept(Validator validator) {
90         Exp[] newArgs = new Exp[args.length];
91         FunDef funDef =
92             FunUtil.resolveFunArgs(validator, args, newArgs, name, syntax);
93         return funDef.createCall(validator, newArgs);
94     }
95
96     public Calc accept(ExpCompiler compiler) {
97         throw new UnsupportedOperationException JavaDoc();
98     }
99
100     /**
101      * Returns the function name.
102      *
103      * @return function name
104      */

105     public String JavaDoc getFunName() {
106         return name;
107     }
108
109     /**
110      * Returns the syntax of this function call.
111      *
112      * @return the syntax of the call
113      */

114     public Syntax getSyntax() {
115         return syntax;
116     }
117
118     /**
119      * Returns the Exp argument at the specified index.
120      *
121      * @param index the index of the Exp.
122      * @return the Exp at the specified index of this array of Exp.
123      * The first Exp is at index <code>0</code>.
124      * @see #getArgs()
125      */

126     public Exp getArg(int index) {
127         return args[index];
128     }
129
130     /**
131      * Returns the internal array of Exp arguments.
132      *
133      * <p>Note: this does NOT do a copy.
134      *
135      * @return the array of expressions
136      */

137     public Exp[] getArgs() {
138         return args;
139     }
140
141     /**
142      * Returns the number of arguments.
143      *
144      * @return number of arguments.
145      * @see #getArgs()
146      */

147     public final int getArgCount() {
148         return args.length;
149     }
150
151     public Object JavaDoc[] getChildren() {
152         return args;
153     }
154 }
155
156 // End UnresolvedFunCall.java
157
Popular Tags