1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 1999-2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 /* 21 * $Id: FuncCount.java,v 1.2.4.1 2005/09/14 19:53:45 jeffsuttor Exp $ 22 */ 23 package com.sun.org.apache.xpath.internal.functions; 24 25 import com.sun.org.apache.xml.internal.dtm.DTMIterator; 26 import com.sun.org.apache.xpath.internal.XPathContext; 27 import com.sun.org.apache.xpath.internal.objects.XNumber; 28 import com.sun.org.apache.xpath.internal.objects.XObject; 29 30 /** 31 * Execute the Count() function. 32 * @xsl.usage advanced 33 */ 34 public class FuncCount extends FunctionOneArg 35 { 36 static final long serialVersionUID = -7116225100474153751L; 37 38 /** 39 * Execute the function. The function must return 40 * a valid object. 41 * @param xctxt The current execution context. 42 * @return A valid XObject. 43 * 44 * @throws javax.xml.transform.TransformerException 45 */ execute(XPathContext xctxt)46 public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException 47 { 48 49 // DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode()); 50 51 // // We should probably make a function on the iterator for this, 52 // // as a given implementation could optimize. 53 // int i = 0; 54 // 55 // while (DTM.NULL != nl.nextNode()) 56 // { 57 // i++; 58 // } 59 // nl.detach(); 60 DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode()); 61 int i = nl.getLength(); 62 nl.detach(); 63 64 return new XNumber((double) i); 65 } 66 } 67