KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xpath > internal > functions > FuncCurrent


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: FuncCurrent.java,v 1.13 2004/02/17 04:34:01 minchau Exp $
18  */

19 package com.sun.org.apache.xpath.internal.functions;
20
21 import com.sun.org.apache.xml.internal.dtm.DTM;
22 import com.sun.org.apache.xml.internal.dtm.DTMIterator;
23 import com.sun.org.apache.xpath.internal.XPathContext;
24 import com.sun.org.apache.xpath.internal.axes.LocPathIterator;
25 import com.sun.org.apache.xpath.internal.axes.PredicatedNodeTest;
26 import com.sun.org.apache.xpath.internal.objects.XNodeSet;
27 import com.sun.org.apache.xpath.internal.objects.XObject;
28 import com.sun.org.apache.xpath.internal.axes.SubContextList;
29 import com.sun.org.apache.xpath.internal.patterns.StepPattern;
30 import com.sun.org.apache.xalan.internal.res.XSLMessages;
31 import com.sun.org.apache.xalan.internal.res.XSLTErrorResources;
32
33
34 /**
35  * Execute the current() function.
36  * @xsl.usage advanced
37  */

38 public class FuncCurrent extends Function
39 {
40
41   /**
42    * Execute the function. The function must return
43    * a valid object.
44    * @param xctxt The current execution context.
45    * @return A valid XObject.
46    *
47    * @throws javax.xml.transform.TransformerException
48    */

49   public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException JavaDoc
50   {
51    
52     SubContextList subContextList = xctxt.getCurrentNodeList();
53     int currentNode = DTM.NULL;
54
55     if (null != subContextList) {
56         if (subContextList instanceof PredicatedNodeTest) {
57             LocPathIterator iter = ((PredicatedNodeTest)subContextList)
58                                                           .getLocPathIterator();
59             currentNode = iter.getCurrentContextNode();
60          } else if(subContextList instanceof StepPattern) {
61            throw new RuntimeException JavaDoc(XSLMessages.createMessage(
62               XSLTErrorResources.ER_PROCESSOR_ERROR,null));
63          }
64     } else {
65         // not predicate => ContextNode == CurrentNode
66
currentNode = xctxt.getContextNode();
67     }
68     return new XNodeSet(currentNode, xctxt.getDTMManager());
69   }
70   
71   /**
72    * No arguments to process, so this does nothing.
73    */

74   public void fixupVariables(java.util.Vector JavaDoc vars, int globalsSize)
75   {
76     // no-op
77
}
78
79 }
80
Popular Tags