1 22 23 package org.xquark.xquery.parser; 24 25 import java.lang.reflect.Method ; 26 import java.util.ArrayList ; 27 28 import org.xquark.xquery.typing.TypeException; 29 30 public class FunctionDeclaration extends XQueryExpression implements Cloneable { 31 32 private static final String RCSRevision = "$Revision: 1.12 $"; 33 private static final String RCSName = "$Name: $"; 34 35 protected QName funcName = null; 37 protected ArrayList parameters = null; 38 protected SequenceType returnType = null; 40 private ArrayList expressions = null; 42 private XQueryModule homeModule = null; 44 45 private Method method = null; 47 48 52 public void accept(ParserVisitor visitor) throws XQueryException { 53 visitor.visit(this); 54 } 55 56 60 public FunctionDeclaration(QName name, ArrayList parameters, SequenceType returnType, ArrayList 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 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 getParameters() { 101 return parameters; 102 } 103 104 public void setParameters(ArrayList 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 getExpressions() { 115 return expressions; 116 } 117 public void setExpressions(ArrayList 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 getMethod() { 125 return method; 126 } 127 128 public void setMethod(Method method) { 129 this.method = method; 130 } 131 132 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 |