1 package net.sf.saxon.instruct; 2 import net.sf.saxon.expr.*; 3 import net.sf.saxon.om.ValueRepresentation; 4 import net.sf.saxon.style.StandardNames; 5 import net.sf.saxon.trans.XPathException; 6 import net.sf.saxon.value.Closure; 7 import net.sf.saxon.value.SequenceExtent; 8 import net.sf.saxon.value.SequenceType; 9 import net.sf.saxon.value.Value; 10 11 17 18 public class Assign extends GeneralVariable implements BindingReference { 19 20 21 private Binding binding; 23 public Assign() {} 24 25 public void setStaticType(SequenceType type, Value constantValue, int properties) {} 26 27 public void fixup(Binding binding) { 28 this.binding = binding; 29 } 30 31 36 37 public final boolean createsNewNodes() { 38 return true; 39 } 40 41 53 54 public Expression promote(PromotionOffer offer) throws XPathException { 55 switch (offer.action) { 56 case PromotionOffer.RANGE_INDEPENDENT: 57 case PromotionOffer.FOCUS_INDEPENDENT: 58 return this; 59 60 case PromotionOffer.REPLACE_CURRENT: 61 case PromotionOffer.INLINE_VARIABLE_REFERENCES: 62 case PromotionOffer.UNORDERED: 63 return super.promote(offer); 64 65 default: 66 throw new UnsupportedOperationException ("Unknown promotion action " + offer.action); 67 } 68 } 69 70 71 72 75 76 public int getInstructionNameCode() { 77 return StandardNames.SAXON_ASSIGN; 78 } 79 80 81 public TailCall processLeavingTail(XPathContext context) throws XPathException { 82 if (binding==null) { 83 throw new IllegalStateException ("saxon:assign binding has not been fixed up"); 84 } 85 ValueRepresentation value = getSelectValue(context); 86 if (value instanceof Closure) { 87 value = SequenceExtent.makeSequenceExtent(((Closure)value).iterate(null)); 88 } 89 if (binding instanceof GeneralVariable) { 90 if (binding.isGlobal()) { 91 context.getController().getBindery().assignGlobalVariable((GlobalVariable)binding, value); 92 } else { 93 throw new UnsupportedOperationException ("Local variables are not assignable"); 94 } 95 } else { 96 97 } 98 return null; 99 } 100 101 104 105 public ValueRepresentation evaluateVariable(XPathContext context) throws XPathException { 106 throw new UnsupportedOperationException (); 107 } 108 } 109 110 | Popular Tags |