author | joehw |
Thu, 21 Dec 2017 17:08:05 -0800 | |
changeset 48412 | d4412e380f6b |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
6 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
5 |
/* |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* 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
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* 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
|
10 |
* (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
|
11 |
* the License. You may obtain a copy of the License at |
6 | 12 |
* |
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
6 | 14 |
* |
15 |
* Unless required by applicable law or agreed to in writing, software |
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 |
* See the License for the specific language governing permissions and |
|
19 |
* limitations under the License. |
|
20 |
*/ |
|
21 |
||
22 |
package com.sun.org.apache.xpath.internal.jaxp; |
|
23 |
||
24 |
import javax.xml.transform.TransformerException; |
|
25 |
import javax.xml.xpath.XPathVariableResolver; |
|
26 |
||
27 |
import com.sun.org.apache.xml.internal.utils.QName; |
|
28 |
import com.sun.org.apache.xpath.internal.VariableStack; |
|
29 |
import com.sun.org.apache.xpath.internal.XPathContext; |
|
30 |
import com.sun.org.apache.xpath.internal.objects.XObject; |
|
31 |
||
32 |
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; |
|
33 |
import com.sun.org.apache.xalan.internal.res.XSLMessages; |
|
34 |
||
35 |
||
36 |
/** |
|
37 |
* Overrides {@link VariableStack} and delegates the call to |
|
38 |
* {@link javax.xml.xpath.XPathVariableResolver}. |
|
39 |
* |
|
48412 | 40 |
* @author Ramesh Mandava |
6 | 41 |
*/ |
42 |
public class JAXPVariableStack extends VariableStack { |
|
43 |
||
44 |
private final XPathVariableResolver resolver; |
|
45 |
||
46 |
public JAXPVariableStack(XPathVariableResolver resolver) { |
|
47 |
this.resolver = resolver; |
|
48 |
} |
|
49 |
||
50 |
public XObject getVariableOrParam(XPathContext xctxt, QName qname) |
|
51 |
throws TransformerException,IllegalArgumentException { |
|
52 |
if ( qname == null ) { |
|
53 |
//JAXP 1.3 spec says that if variable name is null then |
|
54 |
// we need to through IllegalArgumentException |
|
55 |
String fmsg = XSLMessages.createXPATHMessage( |
|
56 |
XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, |
|
57 |
new Object[] {"Variable qname"} ); |
|
58 |
throw new IllegalArgumentException( fmsg ); |
|
59 |
} |
|
60 |
javax.xml.namespace.QName name = |
|
61 |
new javax.xml.namespace.QName( |
|
62 |
qname.getNamespace(), |
|
63 |
qname.getLocalPart()); |
|
64 |
Object varValue = resolver.resolveVariable( name ); |
|
65 |
if ( varValue == null ) { |
|
66 |
String fmsg = XSLMessages.createXPATHMessage( |
|
67 |
XPATHErrorResources.ER_RESOLVE_VARIABLE_RETURNS_NULL, |
|
68 |
new Object[] { name.toString()} ); |
|
69 |
throw new TransformerException( fmsg ); |
|
70 |
} |
|
71 |
return XObject.create( varValue, xctxt ); |
|
72 |
} |
|
73 |
||
74 |
} |