KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > udf > CurrentDateStringUdf


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/udf/CurrentDateStringUdf.java#3 $
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 and others
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.udf;
11
12 import mondrian.olap.Evaluator;
13 import mondrian.olap.Syntax;
14 import mondrian.olap.type.StringType;
15 import mondrian.olap.type.Type;
16 import mondrian.spi.UserDefinedFunction;
17 import mondrian.util.*;
18
19 import java.util.*;
20
21 /**
22  * User-defined function <code>CurrentDateString<code>, which returns the
23  * current date value as a formatted string, based on a format string passed in
24  * as a parameter. The format string conforms to the format string implemented
25  * by {@link Format}.
26  *
27  * @author Zelaine Fong
28  * @version $Id: //open/mondrian/src/main/mondrian/udf/CurrentDateStringUdf.java#3 $
29  */

30 public class CurrentDateStringUdf implements UserDefinedFunction {
31
32     public Object JavaDoc execute(Evaluator evaluator, Argument[] arguments) {
33         Object JavaDoc arg = arguments[0].evaluateScalar(evaluator);
34
35         final Locale locale = Locale.getDefault();
36         final Format format = new Format((((String JavaDoc) arg).toString()), locale);
37         Date currDate = new Date();
38         return format.format(currDate);
39     }
40
41     public String JavaDoc getDescription() {
42         return "Returns the current date formatted as specified by the format parameter.";
43     }
44
45     public String JavaDoc getName() {
46         return "CurrentDateString";
47     }
48
49     public Type[] getParameterTypes() {
50         return new Type[] { new StringType() };
51     }
52
53     public String JavaDoc[] getReservedWords() {
54         return null;
55     }
56
57     public Type getReturnType(Type[] parameterTypes) {
58         return new StringType();
59     }
60
61     public Syntax getSyntax() {
62         return Syntax.Function;
63     }
64
65 }
66
67 // End CurrentDateStringUdf.java
68
Popular Tags