1 package net.sf.saxon.style; 2 import net.sf.saxon.expr.Expression; 3 import net.sf.saxon.instruct.*; 4 import net.sf.saxon.om.*; 5 import net.sf.saxon.trans.XPathException; 6 import net.sf.saxon.type.AnyItemType; 7 import net.sf.saxon.value.EmptySequence; 8 9 import java.util.ArrayList ; 10 import java.util.Iterator ; 11 import java.util.List ; 12 13 16 17 public class XSLAttributeSet extends StyleElement implements StylesheetProcedure { 18 19 private String nameAtt; 20 22 private String useAtt; 23 25 private SlotManager stackFrameMap; 26 28 private List attributeSetElements = null; 29 31 private AttributeSet[] useAttributeSets = null; 32 34 private AttributeSet procedure = new AttributeSet(); 35 37 private int referenceCount = 0; 38 40 private boolean validated = false; 41 42 public int getAttributeSetFingerprint() { 43 return getObjectFingerprint(); 44 } 45 46 public AttributeSet getInstruction() { 47 return procedure; 48 } 49 50 public void incrementReferenceCount() { 51 referenceCount++; 52 } 53 54 public void prepareAttributes() throws XPathException { 55 useAtt = null; 56 57 AttributeCollection atts = getAttributeList(); 58 59 for (int a=0; a<atts.getLength(); a++) { 60 int nc = atts.getNameCode(a); 61 String f = getNamePool().getClarkName(nc); 62 if (f==StandardNames.NAME) { 63 nameAtt = atts.getValue(a).trim(); 64 } else if (f==StandardNames.USE_ATTRIBUTE_SETS) { 65 useAtt = atts.getValue(a); 66 } else { 67 checkUnknownAttribute(nc); 68 } 69 } 70 71 if (nameAtt==null) { 72 reportAbsence("name"); 73 return; 74 } 75 76 try { 77 setObjectNameCode(makeNameCode(nameAtt.trim())); 78 } catch (NamespaceException err) { 79 compileError(err.getMessage(), "XTSE0280"); 80 } catch (XPathException err) { 81 compileError(err.getMessage(), "XTSE0280"); 82 } 83 84 } 85 86 public void validate() throws XPathException { 87 88 if (validated) return; 89 90 checkTopLevel(null); 91 92 stackFrameMap = getConfiguration().makeSlotManager(); 93 94 AxisIterator kids = iterateAxis(Axis.CHILD); 95 while (true) { 96 Item child = kids.next(); 97 if (child == null) { 98 break; 99 } 100 if (!(child instanceof XSLAttribute)) { 101 compileError("Only xsl:attribute is allowed within xsl:attribute-set", "XTSE0010"); 102 } 103 } 104 105 if (useAtt!=null) { 106 108 attributeSetElements = new ArrayList (5); 109 useAttributeSets = getAttributeSets(useAtt, attributeSetElements); 110 111 113 for (Iterator it=attributeSetElements.iterator(); it.hasNext();) { 114 ((XSLAttributeSet)it.next()).checkCircularity(this); 115 } 116 } 117 118 validated = true; 119 } 120 121 125 126 public void checkCircularity(XSLAttributeSet origin) throws XPathException { 127 if (this==origin) { 128 compileError("The definition of the attribute set is circular", "XTSE0720"); 129 } else { 130 if (!validated) { 131 return; 135 } 136 if (attributeSetElements != null) { 137 for (Iterator it=attributeSetElements.iterator(); it.hasNext();) { 138 ((XSLAttributeSet)it.next()).checkCircularity(origin); 139 } 140 } 141 } 142 } 143 144 147 148 public SlotManager getSlotManager() { 149 return stackFrameMap; 150 } 151 157 public Expression compile(Executable exec) throws XPathException { 158 if (referenceCount > 0 ) { 159 Expression body = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true); 160 if (body == null) { 161 body = EmptySequence.getInstance(); 162 } 163 164 try { 165 166 body = body.simplify(getStaticContext()); 167 if (getConfiguration().getTraceListener() != null) { 168 TraceWrapper trace = new TraceInstruction(body, this); 169 trace.setLocationId(allocateLocationId(getSystemId(), getLineNumber())); 170 trace.setParentExpression(procedure); 171 body = trace; 172 } 173 174 procedure.setUseAttributeSets(useAttributeSets); 175 procedure.setNameCode(getObjectNameCode()); 176 procedure.setBody(body); 177 procedure.setSystemId(getSystemId()); 178 procedure.setLineNumber(getLineNumber()); 179 procedure.setExecutable(exec); 180 181 Expression exp2 = body.optimize(getConfiguration().getOptimizer(), staticContext, AnyItemType.getInstance()); 182 if (body != exp2) { 183 procedure.setBody(exp2); 184 body = exp2; 185 } 186 187 super.allocateSlots(body); 188 procedure.setStackFrameMap(stackFrameMap); 189 } catch (XPathException e) { 190 compileError(e); 191 } 192 } 193 return null; 194 } 195 196 201 202 public int getConstructType() { 203 return StandardNames.XSL_ATTRIBUTE_SET; 204 } 205 206 207 } 208 209 | Popular Tags |