KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > parser > FunctionDeclaration


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.xquery.parser;
24
25 import java.lang.reflect.Method JavaDoc;
26 import java.util.ArrayList JavaDoc;
27
28 import org.xquark.xquery.typing.TypeException;
29
30 public class FunctionDeclaration extends XQueryExpression implements Cloneable JavaDoc {
31
32     private static final String JavaDoc RCSRevision = "$Revision: 1.12 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34
35     // cannot be null
36
protected QName funcName = null;
37     protected ArrayList JavaDoc parameters = null;
38     // cannot be null
39
protected SequenceType returnType = null;
40     // cannot be null or empty
41
private ArrayList JavaDoc expressions = null;
42     // home module when imported
43
private XQueryModule homeModule = null;
44     
45     // for java functions
46
private Method JavaDoc method = null;
47
48     // #############################################################################
49
// VISITOR STUFF
50
// #############################################################################
51

52     public void accept(ParserVisitor visitor) throws XQueryException {
53         visitor.visit(this);
54     }
55
56     // #############################################################################
57
// CONSTRUCTOR STUFF
58
// #############################################################################
59

60     public FunctionDeclaration(QName name, ArrayList JavaDoc parameters, SequenceType returnType, ArrayList JavaDoc expressions, XQueryModule parentModule) throws TypeException, XQueryException {
61         setFuncName(name);
62         setParameters(parameters);
63         setReturnType(returnType);
64         setExpressions(expressions);
65         setParentModule(parentModule);
66         homeModule = parentModule;
67         if (parentModule != null && parentModule.getStaticContext().getTypeVisitor() != null)
68             accept(parentModule.getStaticContext().getTypeVisitor());
69     }
70
71     // #############################################################################
72
// ATTRIBUTE ACCESS STUFF
73
// #############################################################################
74

75     public XQueryModule getHomeModule() {
76         return homeModule;
77     }
78     
79     public QName getFuncName() {
80         return funcName;
81     }
82     public void setFuncName(QName funcName) throws XQueryException {
83         if (funcName == null || funcName.getName().equals(""))
84             throw new XQueryException("funcName of FunctionDefinition cannot be null or empty string");
85         this.funcName = funcName;
86         funcName.setParentModule(parentModule);
87     }
88
89     public SequenceType getReturnType() {
90         return returnType;
91     }
92     public void setReturnType(SequenceType returnType) {
93         this.returnType = returnType;
94         if (returnType != null) {
95             this.returnType.setParentExpression(this);
96             this.returnType.setParentModule(parentModule);
97         }
98     }
99
100     public ArrayList JavaDoc getParameters() {
101         return parameters;
102     }
103
104     public void setParameters(ArrayList JavaDoc parameters) {
105         this.parameters = parameters;
106         if (this.parameters != null)
107             for (int i = 0; i < this.parameters.size(); i++) {
108                 Variable param = (Variable) this.parameters.get(i);
109                 param.setParentExpression(this);
110                 param.setParentModule(parentModule);
111             }
112     }
113
114     public ArrayList JavaDoc getExpressions() {
115         return expressions;
116     }
117     public void setExpressions(ArrayList JavaDoc expressions) throws XQueryException {
118         this.expressions = expressions;
119         if (expressions != null)
120             for (int i = 0; i < this.expressions.size(); i++)
121                  ((XQueryExpression) this.expressions.get(i)).setParentModule(parentModule);
122     }
123
124     public Method JavaDoc getMethod() {
125         return method;
126     }
127     
128     public void setMethod(Method JavaDoc method) {
129         this.method = method;
130     }
131     
132     // #############################################################################
133
// PRINT STUFF
134
// #############################################################################
135
public void addParentExpression(XQueryExpression parentExpression) {
136         addParentExpression(parentExpression);
137         funcName.addParentExpression(parentExpression);
138         if (parameters != null)
139             for (int i = 0; i < parameters.size(); i++)
140                  ((Variable) parameters.get(i)).addParentExpression(parentExpression);
141         if (returnType != null)
142             returnType.addParentExpression(parentExpression);
143         if (expressions != null)
144             for (int i = 0; i < this.expressions.size(); i++)
145                  ((XQueryExpression) this.expressions.get(i)).addParentExpression(parentExpression);
146     }
147
148 }
149
Popular Tags