author | joehw |
Thu, 21 Dec 2017 09:29:24 -0800 | |
changeset 48409 | 5ab69533994b |
parent 47359 | e1a6c0168741 |
permissions | -rw-r--r-- |
6 | 1 |
/* |
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
6 | 3 |
*/ |
4 |
/* |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
5 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* the License. You may obtain a copy of the License at |
6 | 11 |
* |
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
6 | 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 |
*/ |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
20 |
|
6 | 21 |
package com.sun.org.apache.xpath.internal.functions; |
22 |
||
23 |
import com.sun.org.apache.xml.internal.dtm.DTMIterator; |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
24 |
import com.sun.org.apache.xml.internal.utils.QName; |
6 | 25 |
import com.sun.org.apache.xpath.internal.XPathContext; |
26 |
import com.sun.org.apache.xpath.internal.axes.SubContextList; |
|
27 |
import com.sun.org.apache.xpath.internal.compiler.Compiler; |
|
28 |
import com.sun.org.apache.xpath.internal.objects.XNumber; |
|
29 |
import com.sun.org.apache.xpath.internal.objects.XObject; |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
30 |
import java.util.List; |
6 | 31 |
|
32 |
||
33 |
/** |
|
34 |
* Execute the Last() function. |
|
35 |
* @xsl.usage advanced |
|
48409 | 36 |
* @LastModified: Oct 2017 |
6 | 37 |
*/ |
38 |
public class FuncLast extends Function |
|
39 |
{ |
|
40 |
static final long serialVersionUID = 9205812403085432943L; |
|
41 |
||
42 |
private boolean m_isTopLevel; |
|
43 |
||
44 |
/** |
|
45 |
* Figure out if we're executing a toplevel expression. |
|
46 |
* If so, we can't be inside of a predicate. |
|
47 |
*/ |
|
48 |
public void postCompileStep(Compiler compiler) |
|
49 |
{ |
|
50 |
m_isTopLevel = compiler.getLocationPathDepth() == -1; |
|
51 |
} |
|
52 |
||
53 |
/** |
|
54 |
* Get the position in the current context node list. |
|
55 |
* |
|
56 |
* @param xctxt non-null reference to XPath runtime context. |
|
57 |
* |
|
58 |
* @return The number of nodes in the list. |
|
59 |
* |
|
60 |
* @throws javax.xml.transform.TransformerException |
|
61 |
*/ |
|
62 |
public int getCountOfContextNodeList(XPathContext xctxt) |
|
63 |
throws javax.xml.transform.TransformerException |
|
64 |
{ |
|
65 |
||
66 |
// assert(null != m_contextNodeList, "m_contextNodeList must be non-null"); |
|
67 |
// If we're in a predicate, then this will return non-null. |
|
68 |
SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList(); |
|
69 |
||
70 |
// System.out.println("iter: "+iter); |
|
71 |
if (null != iter) |
|
72 |
return iter.getLastPos(xctxt); |
|
73 |
||
74 |
DTMIterator cnl = xctxt.getContextNodeList(); |
|
75 |
int count; |
|
76 |
if(null != cnl) |
|
77 |
{ |
|
78 |
count = cnl.getLength(); |
|
79 |
// System.out.println("count: "+count); |
|
80 |
} |
|
81 |
else |
|
82 |
count = 0; |
|
83 |
return count; |
|
84 |
} |
|
85 |
||
86 |
/** |
|
87 |
* Execute the function. The function must return |
|
88 |
* a valid object. |
|
89 |
* @param xctxt The current execution context. |
|
90 |
* @return A valid XObject. |
|
91 |
* |
|
92 |
* @throws javax.xml.transform.TransformerException |
|
93 |
*/ |
|
94 |
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException |
|
95 |
{ |
|
96 |
XNumber xnum = new XNumber((double) getCountOfContextNodeList(xctxt)); |
|
97 |
// System.out.println("last: "+xnum.num()); |
|
98 |
return xnum; |
|
99 |
} |
|
100 |
||
101 |
/** |
|
102 |
* No arguments to process, so this does nothing. |
|
103 |
*/ |
|
47359
e1a6c0168741
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents:
47216
diff
changeset
|
104 |
public void fixupVariables(List<QName> vars, int globalsSize) |
6 | 105 |
{ |
106 |
// no-op |
|
107 |
} |
|
108 |
||
109 |
} |