1 package net.sf.saxon.xpath; 2 import net.sf.saxon.expr.Binding; 3 import net.sf.saxon.expr.BindingReference; 4 import net.sf.saxon.expr.VariableDeclaration; 5 import net.sf.saxon.expr.XPathContext; 6 import net.sf.saxon.trans.XPathException; 7 import net.sf.saxon.value.EmptySequence; 8 import net.sf.saxon.value.QNameValue; 9 import net.sf.saxon.value.SequenceType; 10 import net.sf.saxon.value.Value; 11 import net.sf.saxon.om.ValueRepresentation; 12 13 import javax.xml.namespace.QName ; 14 import javax.xml.xpath.XPathVariableResolver ; 15 16 17 37 38 public final class JAXPVariable implements VariableDeclaration, Binding { 39 40 private QNameValue name; 41 private XPathVariableResolver resolver; 42 43 46 47 public JAXPVariable(QNameValue name, XPathVariableResolver resolver) { 48 this.name = name; 49 this.resolver = resolver; 50 }; 51 52 56 57 public boolean isGlobal() { 58 return true; 59 } 60 61 66 67 public final boolean isAssignable() { 68 return false; 69 } 70 71 75 76 public int getLocalSlotNumber() { 77 return -1; 78 } 79 80 84 85 public String getVariableName() { 86 return name.getStringValue(); 87 } 88 89 94 95 public int getNameCode() { 96 return -1; 97 } 98 99 103 104 public void registerReference(BindingReference ref) { 105 ref.setStaticType(SequenceType.ANY_SEQUENCE, null, 0); 106 ref.fixup(this); 107 } 108 109 115 116 public ValueRepresentation evaluateVariable(XPathContext context) throws XPathException { 117 Object value = resolver.resolveVariable( 118 (QName )name.makeQName( 119 context.getController().getConfiguration())); 120 if (value == null) { 121 return EmptySequence.getInstance(); 122 } 123 return Value.convertJavaObjectToXPath( 124 value, SequenceType.ANY_SEQUENCE, context.getController().getConfiguration()); 125 } 126 127 QName makeQName(QNameValue in) { 128 return new QName (in.getNamespaceURI(), in.getLocalName(), in.getPrefix()); 129 } 130 } 131 132 | Popular Tags |