01: /*
02: * Copyright 1999-2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.14 2004/08/17 19:25:36 jycli Exp $
18: */
19: package org.apache.xpath.functions;
20:
21: import org.apache.xml.dtm.DTM;
22: import org.apache.xml.dtm.DTMIterator;
23: import org.apache.xpath.XPathContext;
24: import org.apache.xpath.axes.LocPathIterator;
25: import org.apache.xpath.axes.PredicatedNodeTest;
26: import org.apache.xpath.objects.XNodeSet;
27: import org.apache.xpath.objects.XObject;
28: import org.apache.xpath.axes.SubContextList;
29: import org.apache.xpath.patterns.StepPattern;
30: import org.apache.xalan.res.XSLMessages;
31: import org.apache.xalan.res.XSLTErrorResources;
32:
33: /**
34: * Execute the current() function.
35: * @xsl.usage advanced
36: */
37: public class FuncCurrent extends Function {
38: static final long serialVersionUID = 5715316804877715008L;
39:
40: /**
41: * Execute the function. The function must return
42: * a valid object.
43: * @param xctxt The current execution context.
44: * @return A valid XObject.
45: *
46: * @throws javax.xml.transform.TransformerException
47: */
48: public XObject execute(XPathContext xctxt)
49: throws javax.xml.transform.TransformerException {
50:
51: SubContextList subContextList = xctxt.getCurrentNodeList();
52: int currentNode = DTM.NULL;
53:
54: if (null != subContextList) {
55: if (subContextList instanceof PredicatedNodeTest) {
56: LocPathIterator iter = ((PredicatedNodeTest) subContextList)
57: .getLocPathIterator();
58: currentNode = iter.getCurrentContextNode();
59: } else if (subContextList instanceof StepPattern) {
60: throw new RuntimeException(XSLMessages.createMessage(
61: XSLTErrorResources.ER_PROCESSOR_ERROR, null));
62: }
63: } else {
64: // not predicate => ContextNode == CurrentNode
65: currentNode = xctxt.getContextNode();
66: }
67: return new XNodeSet(currentNode, xctxt.getDTMManager());
68: }
69:
70: /**
71: * No arguments to process, so this does nothing.
72: */
73: public void fixupVariables(java.util.Vector vars, int globalsSize) {
74: // no-op
75: }
76:
77: }
|