1 package net.sf.saxon.style; 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.instruct.SlotManager; 6 import net.sf.saxon.trans.XPathException; 7 import net.sf.saxon.type.Type; 8 import net.sf.saxon.value.SequenceType; 9 import net.sf.saxon.value.Value; 10 11 import java.util.ArrayList ; 12 import java.util.Iterator ; 13 import java.util.List ; 14 15 16 19 20 public abstract class XSLVariableDeclaration 21 extends XSLGeneralVariable 22 implements VariableDeclaration, StylesheetProcedure { 23 24 28 private int slotNumber = -9876; 30 List references = new ArrayList (10); 32 33 38 39 public SlotManager getSlotManager() { 40 return slotManager; 41 } 42 43 44 public int getSlotNumber() { 45 return slotNumber; 46 } 47 48 public void setSlotNumber(int slot) { 49 slotNumber = slot; 50 } 51 52 55 56 public abstract SequenceType getRequiredType(); 57 58 62 63 public void registerReference(BindingReference ref) { 64 references.add(ref); 65 } 66 67 71 72 public List getReferences() { 73 return references; 74 } 75 76 80 81 public boolean isInstruction() { 82 return true; 83 } 84 85 88 89 public List getReferenceList() { 90 return references; 91 } 92 93 96 97 public void fixupReferences() throws XPathException { 98 SequenceType type = getRequiredType(); 99 Iterator iter = references.iterator(); 100 while (iter.hasNext()) { 101 Value constantValue = null; 102 int properties = 0; 103 if (this instanceof XSLVariable && !isAssignable()) { 104 if (select instanceof Value) { 105 int relation = Type.relationship(select.getItemType(), type.getPrimaryType()); 109 if (relation == Type.SAME_TYPE || relation == Type.SUBSUMED_BY) { 110 constantValue = (Value)select; 111 } 112 } 113 if (select != null) { 114 properties = select.getSpecialProperties(); 115 } 116 } 117 ((BindingReference)iter.next()).setStaticType(type, constantValue, properties); 118 } 119 super.fixupReferences(); 120 } 121 122 125 126 public void validate() throws XPathException { 127 super.validate(); 128 if (global) { 129 if (!redundant) { 130 slotNumber = getPrincipalStylesheet().allocateGlobalSlot(getVariableFingerprint()); 131 } 132 } else { 133 checkWithinTemplate(); 134 } 141 } 147 148 151 152 protected void fixupBinding(Binding binding) { 153 Iterator iter = references.iterator(); 154 while (iter.hasNext()) { 155 ((BindingReference)iter.next()).fixup(binding); 156 } 157 } 158 159 160 } 161 162 | Popular Tags |