KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > spi > UserDefinedFunction


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

10 package mondrian.spi;
11
12 import mondrian.olap.*;
13 import mondrian.olap.type.Type;
14
15 import org.apache.log4j.*;
16 import org.apache.log4j.Category;
17
18 /**
19  * Definition of a user-defined function.
20  *
21  * <p>The class must have a public, zero-arguments constructor, be on
22  * Mondrian's runtime class-path, and be referenced from the schema file:
23  *
24  * <blockquote><code>
25  * &lt;Schema&gt;<br/>
26  * &nbsp;&nbsp;&nbsp;&nbsp;....<br/>
27  * &nbsp;&nbsp;&nbsp;&nbsp;&lt;UserDefinedFunction name="MyFun" class="com.acme.MyFun"&gt;<br/>
28  * &lt;/Schema&gt;</code></blockquote>
29  *
30  * @author jhyde
31  * @version $Id: //open/mondrian/src/main/mondrian/spi/UserDefinedFunction.java#7 $
32  */

33 public interface UserDefinedFunction {
34     /**
35      * Returns the name with which the user-defined function will be used
36      * from within MDX expressions.
37      */

38     public String JavaDoc getName();
39
40     /**
41      * Returns a description of the user-defined function.
42      */

43     public String JavaDoc getDescription();
44
45     /**
46      * Returns the syntactic type of the user-defined function.
47      * Usually {@link Syntax#Function}.
48      */

49     public Syntax getSyntax();
50
51     /**
52      * Returns an array of the types of the parameters of this function.
53      */

54     public Type[] getParameterTypes();
55
56     /**
57      * Returns the return-type of this function.
58      * @param parameterTypes
59      */

60     public Type getReturnType(Type[] parameterTypes);
61
62     /**
63      * Applies this function to a set of arguments, and returns a result.
64      *
65      * @param evaluator Evaluator containts the runtime context, in particular
66      * the current member of each dimension.
67      * @param arguments Expressions which yield the arguments of this function.
68      * Most user-defined functions will evaluate all arguments before using
69      * them. Functions such as <code>IIf</code> do not evaluate all
70      * arguments; this technique is called <dfn>lazy evaluation</dfn>.
71      * @return The result value.
72      */

73     public Object JavaDoc execute(Evaluator evaluator, Argument[] arguments);
74
75     /**
76      * Returns a list of reserved words used by this function.
77      * May return an empty array or null if this function does not require
78      * any reserved words.
79      */

80     public String JavaDoc[] getReservedWords();
81
82     interface Argument {
83
84         Object JavaDoc evaluateScalar(Evaluator evaluator);
85
86         Object JavaDoc evaluate(Evaluator evaluator);
87
88         Type getType();
89     }
90 }
91
92 // UserDefinedFunction.java
93
Popular Tags