KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > fun > MultiResolver


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/MultiResolver.java#19 $
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) 2002-2005 Kana Software, Inc. and others
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 //
10 // jhyde, Feb 12, 2003
11 */

12 package mondrian.olap.fun;
13
14 import mondrian.olap.*;
15
16 /**
17  * A <code>MultiResolver</code> considers several overloadings of the same
18  * function. If one of these overloadings matches the actual arguments, it
19  * calls the factory method {@link #createFunDef}.
20  *
21  * @author jhyde
22  * @since Feb 12, 2003
23  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/MultiResolver.java#19 $
24  */

25 public abstract class MultiResolver extends FunUtil implements Resolver {
26     private final String JavaDoc name;
27     private final String JavaDoc signature;
28     private final String JavaDoc description;
29     private final String JavaDoc[] signatures;
30     private final Syntax syntax;
31
32     /**
33      * Creates a <code>MultiResolver</code>.
34      *
35      * @param name Name of function or operator
36      * @param signature Signature of function or operator
37      * @param description Description of function or operator
38      * @param signatures Array of possible signatures, each of which is an
39      * encoding of the syntactic type, return type, and parameter
40      * types of this operator. The "Members" operator has a syntactic
41      * type "pxd" which means "an operator with
42      * {@link Syntax#Property property} syntax (p) which returns a set
43      * (x) and takes a dimension (d) as its argument".
44      * See {@link FunUtil#decodeSyntacticType(String)},
45      * {@link FunUtil#decodeReturnCategory(String)},
46      * {@link FunUtil#decodeParameterCategories(String)}.
47      */

48     protected MultiResolver(
49             String JavaDoc name,
50             String JavaDoc signature,
51             String JavaDoc description,
52             String JavaDoc[] signatures) {
53         this.name = name;
54         this.signature = signature;
55         this.description = description;
56         this.signatures = signatures;
57         Util.assertTrue(signatures.length > 0);
58         this.syntax = decodeSyntacticType(signatures[0]);
59         for (int i = 1; i < signatures.length; i++) {
60             Util.assertTrue(decodeSyntacticType(signatures[i]) == syntax);
61         }
62     }
63
64     public String JavaDoc getName() {
65         return name;
66     }
67
68     public String JavaDoc getDescription() {
69         return description;
70     }
71
72     public String JavaDoc getSignature() {
73         return signature;
74     }
75
76     public Syntax getSyntax() {
77         return syntax;
78     }
79
80     public String JavaDoc[] getReservedWords() {
81         return emptyStringArray;
82     }
83
84     public String JavaDoc[] getSignatures() {
85         return signatures;
86     }
87
88     public FunDef getFunDef() {
89         return null;
90     }
91
92     public FunDef resolve(
93         Exp[] args, Validator validator, int[] conversionCount)
94     {
95 outer:
96         for (String JavaDoc signature : signatures) {
97             int[] parameterTypes = decodeParameterCategories(signature);
98             if (parameterTypes.length != args.length) {
99                 continue;
100             }
101             for (int i = 0; i < args.length; i++) {
102                 if (!validator.canConvert(
103                     args[i], parameterTypes[i], conversionCount)) {
104                     continue outer;
105                 }
106             }
107             int returnType = decodeReturnCategory(signature);
108             FunDef dummy = createDummyFunDef(this, returnType, args);
109             return createFunDef(args, dummy);
110         }
111         return null;
112     }
113
114     public boolean requiresExpression(int k) {
115         for (String JavaDoc signature : signatures) {
116             int[] parameterTypes = decodeParameterCategories(signature);
117             if ((k < parameterTypes.length) &&
118                 parameterTypes[k] == Category.Set) {
119                 return false;
120             }
121         }
122         return true;
123     }
124
125     protected abstract FunDef createFunDef(Exp[] args, FunDef dummyFunDef);
126 }
127
128 // End MultiResolver.java
129
Popular Tags