1 61 62 package org.jaxen.function; 63 64 import java.util.List ; 65 66 import org.jaxen.Context; 67 import org.jaxen.Function; 68 import org.jaxen.FunctionCallException; 69 70 79 public class CountFunction implements Function 80 { 81 82 85 public CountFunction() {} 86 87 99 public Object call(Context context, 100 List args) throws FunctionCallException 101 { 102 if (args.size() == 1) 103 { 104 return evaluate( args.get(0) ); 105 } 106 107 throw new FunctionCallException( "count() requires one argument." ); 108 } 109 110 119 public static Double evaluate(Object obj) throws FunctionCallException 120 { 121 122 if (obj instanceof List ) 123 { 124 return new Double ( ((List ) obj).size() ); 125 } 126 127 throw new FunctionCallException("count() function can only be used for node-sets"); 128 129 } 130 131 } 132 | Popular Tags |