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: // $Id: JAXPVariableStack.java,v 1.1 2005/05/17 17:24:26 mkwan Exp $
17: package org.apache.xpath.jaxp;
18:
19: import javax.xml.transform.TransformerException;
20: import javax.xml.xpath.XPathVariableResolver;
21:
22: import org.apache.xml.utils.QName;
23: import org.apache.xpath.VariableStack;
24: import org.apache.xpath.XPathContext;
25: import org.apache.xpath.objects.XObject;
26:
27: import org.apache.xpath.res.XPATHErrorResources;
28: import org.apache.xalan.res.XSLMessages;
29:
30: /**
31: * Overrides {@link VariableStack} and delegates the call to
32: * {@link javax.xml.xpath.XPathVariableResolver}.
33: *
34: * @author Ramesh Mandava ( ramesh.mandava@sun.com )
35: */
36: public class JAXPVariableStack extends VariableStack {
37:
38: private final XPathVariableResolver resolver;
39:
40: public JAXPVariableStack(XPathVariableResolver resolver) {
41: this .resolver = resolver;
42: }
43:
44: public XObject getVariableOrParam(XPathContext xctxt, QName qname)
45: throws TransformerException, IllegalArgumentException {
46: if (qname == null) {
47: //JAXP 1.3 spec says that if variable name is null then
48: // we need to through IllegalArgumentException
49: String fmsg = XSLMessages.createXPATHMessage(
50: XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
51: new Object[] { "Variable qname" });
52: throw new IllegalArgumentException(fmsg);
53: }
54: javax.xml.namespace.QName name = new javax.xml.namespace.QName(
55: qname.getNamespace(), qname.getLocalPart());
56: Object varValue = resolver.resolveVariable(name);
57: if (varValue == null) {
58: String fmsg = XSLMessages
59: .createXPATHMessage(
60: XPATHErrorResources.ER_RESOLVE_VARIABLE_RETURNS_NULL,
61: new Object[] { name.toString() });
62: throw new TransformerException(fmsg);
63: }
64: return XObject.create(varValue, xctxt);
65: }
66:
67: }
|