1 package com.icl.saxon.expr; 2 import com.icl.saxon.*; 3 4 5 import java.util.*; 6 7 8 11 12 public abstract class Function extends Expression { 13 14 protected Expression[] argument = new Expression[6]; 15 private int numberOfArguments = 0; 16 17 20 21 public void addArgument(Expression expr) { 22 if (numberOfArguments>=argument.length) { 23 Expression[] arg2 = new Expression[argument.length*2]; 24 System.arraycopy(argument, 0, arg2, 0, numberOfArguments); 25 argument = arg2; 26 } 27 argument[numberOfArguments++] = expr; 28 } 29 30 33 34 public int getNumberOfArguments() { 35 return numberOfArguments; 36 } 37 38 44 45 public abstract String getName(); 46 47 55 56 protected int checkArgumentCount(int min, int max) throws XPathException { 57 int numArgs = numberOfArguments; 58 if (min==max && numArgs != min) { 59 throw new XPathException("Function " + getName() + " must have " + min + pluralArguments(min)); 60 } 61 if (numArgs < min) { 62 throw new XPathException("Function " + getName() + " must have at least " + min + pluralArguments(min)); 63 } 64 if (numArgs > max) { 65 throw new XPathException("Function " + getName() + " must have no more than " + max + pluralArguments(max)); 66 } 67 return numArgs; 68 } 69 70 73 74 private String pluralArguments(int num) { 75 if (num==1) return " argument"; 76 return " arguments"; 77 } 78 79 82 83 public void display(int level) { 84 System.err.println(indent(level) + "function " + getName()); 85 for (int a=0; a<numberOfArguments; a++) { 86 argument[a].display(level+1); 87 } 88 } 89 90 } 91 92 | Popular Tags |