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