KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xpath > internal > jaxp > JAXPVariableStack


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 // $Id: JAXPVariableStack.java,v 1.4 2004/07/10 21:39:19 rameshm Exp $
17

18 package com.sun.org.apache.xpath.internal.jaxp;
19
20 import javax.xml.transform.TransformerException JavaDoc;
21 import javax.xml.xpath.XPathVariableResolver JavaDoc;
22
23 import com.sun.org.apache.xml.internal.utils.QName;
24 import com.sun.org.apache.xpath.internal.VariableStack;
25 import com.sun.org.apache.xpath.internal.XPathContext;
26 import com.sun.org.apache.xpath.internal.objects.XObject;
27
28 import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
29 import com.sun.org.apache.xalan.internal.res.XSLMessages;
30
31
32 /**
33  * Overrides {@link VariableStack} and delegates the call to
34  * {@link javax.xml.xpath.XPathVariableResolver}.
35  *
36  * @author Ramesh Mandava ( ramesh.mandava@sun.com )
37  */

38 public class JAXPVariableStack extends VariableStack {
39         
40     private final XPathVariableResolver JavaDoc resolver;
41     
42     public JAXPVariableStack(XPathVariableResolver JavaDoc resolver) {
43         this.resolver = resolver;
44     }
45     
46     public XObject getVariableOrParam(XPathContext xctxt, QName qname)
47         throws TransformerException JavaDoc,IllegalArgumentException JavaDoc {
48         if ( qname == null ) {
49             //JAXP 1.3 spec says that if variable name is null then
50
// we need to through IllegalArgumentException
51
String JavaDoc fmsg = XSLMessages.createXPATHMessage(
52                 XPATHErrorResources.ER_ARG_CANNOT_BE_NULL,
53                 new Object JavaDoc[] {"Variable qname"} );
54             throw new IllegalArgumentException JavaDoc( fmsg );
55         }
56     javax.xml.namespace.QName JavaDoc name =
57         new javax.xml.namespace.QName JavaDoc(
58                 qname.getNamespace(),
59                 qname.getLocalPart());
60         Object JavaDoc varValue = resolver.resolveVariable( name );
61         if ( varValue == null ) {
62             String JavaDoc fmsg = XSLMessages.createXPATHMessage(
63                 XPATHErrorResources.ER_RESOLVE_VARIABLE_RETURNS_NULL,
64                 new Object JavaDoc[] { name.toString()} );
65             throw new TransformerException JavaDoc( fmsg );
66         }
67         return XObject.create( varValue, xctxt );
68     }
69
70 }
71
Popular Tags