1 package net.sf.saxon.trans; 2 import net.sf.saxon.Configuration; 3 import net.sf.saxon.expr.Binding; 4 import net.sf.saxon.expr.BindingReference; 5 import net.sf.saxon.expr.VariableDeclaration; 6 import net.sf.saxon.expr.XPathContext; 7 import net.sf.saxon.om.ValueRepresentation; 8 import net.sf.saxon.value.EmptySequence; 9 import net.sf.saxon.value.QNameValue; 10 import net.sf.saxon.value.SequenceType; 11 import net.sf.saxon.value.Value; 12 13 14 18 19 public final class Variable implements VariableDeclaration, Binding { 20 21 private QNameValue name; 22 private ValueRepresentation value; 23 private Configuration config; 24 25 28 29 private Variable() {}; 30 31 34 35 public static Variable make(QNameValue name, Configuration config) { 36 Variable v = new Variable(); 37 v.name = name; 38 v.config = config; 39 return v; 40 } 41 42 47 48 public static Variable make(String qname, Configuration config) throws XPathException { 49 Variable v = new Variable(); 50 int colon = qname.indexOf(':'); 51 if (colon < 0) { 52 v.name = new QNameValue("", "", qname); 53 } else { 54 v.name = new QNameValue(qname.substring(0, colon), "http://saxon.sf.net/", qname.substring(colon+1)); 55 } 56 v.config = config; 57 return v; 58 } 59 60 61 65 66 public boolean isGlobal() { 67 return true; 68 } 69 70 75 76 public final boolean isAssignable() { 77 return false; 78 } 79 80 84 85 public int getLocalSlotNumber() { 86 return -1; 87 } 88 89 93 94 public String getVariableName() { 95 return name.toString(); 96 } 97 98 102 103 public int getNameCode() { 104 return name.allocateNameCode(config.getNamePool()); 105 } 106 107 114 115 public void setValue(Object value) throws XPathException { 116 this.value = Value.convertJavaObjectToXPath(value, SequenceType.ANY_SEQUENCE, config); 117 if (this.value==null) { 118 this.value = EmptySequence.getInstance(); 119 } 120 } 121 122 128 129 public void setXPathValue(ValueRepresentation value) { 130 this.value = value; 131 if (this.value==null) { 132 this.value = EmptySequence.getInstance(); 133 } 134 } 135 136 140 141 public void registerReference(BindingReference ref) { 142 ref.setStaticType(SequenceType.ANY_SEQUENCE, null, 0); 143 ref.fixup(this); 144 } 145 146 152 153 public ValueRepresentation evaluateVariable(XPathContext context) { 154 return value; 155 } 156 } 157 158 | Popular Tags |