001: package net.sf.saxon.instruct;
002:
003: import net.sf.saxon.expr.XPathContext;
004: import net.sf.saxon.expr.XPathContextMajor;
005: import net.sf.saxon.style.StandardNames;
006: import net.sf.saxon.trace.InstructionInfo;
007: import net.sf.saxon.trace.InstructionInfoProvider;
008: import net.sf.saxon.trans.XPathException;
009:
010: /**
011: * The compiled form of an xsl:attribute-set element in the stylesheet.
012: */
013:
014: // Note, there is no run-time check for circularity. This is checked at compile time.
015: public class AttributeSet extends Procedure implements
016: InstructionInfoProvider {
017:
018: int nameCode;
019:
020: private AttributeSet[] useAttributeSets;
021:
022: public AttributeSet() {
023: }
024:
025: public void setNameCode(int nameCode) {
026: this .nameCode = nameCode;
027: }
028:
029: public int getNameCode() {
030: return nameCode;
031: }
032:
033: public void setUseAttributeSets(AttributeSet[] useAttributeSets) {
034: this .useAttributeSets = useAttributeSets;
035: }
036:
037: public void setStackFrameMap(SlotManager stackFrameMap) {
038: if (stackFrameMap != null
039: && stackFrameMap.getNumberOfVariables() > 0) {
040: super .setStackFrameMap(stackFrameMap);
041: }
042: }
043:
044: public void expand(XPathContext context) throws XPathException {
045: // apply the content of any attribute sets mentioned in use-attribute-sets
046:
047: if (useAttributeSets != null) {
048: AttributeSet.expand(useAttributeSets, context);
049: }
050:
051: if (getStackFrameMap() != null) {
052: XPathContextMajor c2 = context.newContext();
053: c2.setOrigin(this );
054: c2.openStackFrame(getStackFrameMap());
055: getBody().process(c2);
056: } else {
057: getBody().process(context);
058: }
059: }
060:
061: /**
062: * Get the InstructionInfo details about the construct. This information isn't used for tracing,
063: * but it is available when inspecting the context stack.
064: */
065:
066: public InstructionInfo getInstructionInfo() {
067: InstructionDetails details = new InstructionDetails();
068: details.setConstructType(StandardNames.XSL_ATTRIBUTE_SET);
069: details.setSystemId(getSystemId());
070: details.setLineNumber(getLineNumber());
071: details.setProperty("attribute-set", this );
072: return details;
073: }
074:
075: /**
076: * Expand an array of attribute sets
077: * @param asets the attribute sets to be expanded
078: * @param context the run-time context to use
079: * @throws XPathException
080: */
081:
082: protected static void expand(AttributeSet[] asets,
083: XPathContext context) throws XPathException {
084: for (int i = 0; i < asets.length; i++) {
085: asets[i].expand(context);
086: }
087: }
088: }
089:
090: //
091: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
092: // you may not use this file except in compliance with the License. You may obtain a copy of the
093: // License at http://www.mozilla.org/MPL/
094: //
095: // Software distributed under the License is distributed on an "AS IS" basis,
096: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
097: // See the License for the specific language governing rights and limitations under the License.
098: //
099: // The Original Code is: all this file.
100: //
101: // The Initial Developer of the Original Code is Michael H. Kay.
102: //
103: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
104: //
105: // Contributor(s): none.
106: //
|