001: package net.sf.saxon.trans;
002:
003: import net.sf.saxon.expr.Expression;
004: import net.sf.saxon.instruct.InstructionDetails;
005: import net.sf.saxon.instruct.Procedure;
006: import net.sf.saxon.instruct.SlotManager;
007: import net.sf.saxon.pattern.Pattern;
008: import net.sf.saxon.style.StandardNames;
009: import net.sf.saxon.trace.InstructionInfo;
010: import net.sf.saxon.trace.InstructionInfoProvider;
011:
012: import java.io.Serializable;
013: import java.text.Collator;
014:
015: /**
016: * Corresponds to a single xsl:key declaration.<P>
017: * @author Michael H. Kay
018: */
019:
020: public class KeyDefinition extends Procedure implements Serializable,
021: InstructionInfoProvider {
022:
023: private Pattern match; // the match pattern
024: private Collator collation; // the collating sequence, when type=string
025: private String collationName; // the collation URI
026: private boolean backwardsCompatible = false;
027:
028: /**
029: * Constructor to create a key definition
030: */
031:
032: public KeyDefinition(Pattern match, Expression use,
033: String collationName, Collator collation) {
034: this .match = match;
035: setBody(use);
036: this .collation = collation;
037: this .collationName = collationName;
038: }
039:
040: /**
041: * Set backwards compatibility mode. The key definition is backwards compatible if ANY of the xsl:key
042: * declarations has version="1.0" in scope.
043: */
044:
045: public void setBackwardsCompatible(boolean bc) {
046: backwardsCompatible = bc;
047: }
048:
049: /**
050: * Test backwards compatibility mode
051: */
052:
053: public boolean isBackwardsCompatible() {
054: return backwardsCompatible;
055: }
056:
057: /**
058: * Set the map of local variables needed while evaluating the "use" expression
059: */
060:
061: public void setStackFrameMap(SlotManager map) {
062: if (map != null && map.getNumberOfVariables() > 0) {
063: super .setStackFrameMap(map);
064: }
065: }
066:
067: /**
068: * Set the system Id and line number of the source xsl:key definition
069: */
070:
071: public void setLocation(String systemId, int lineNumber) {
072: setSystemId(systemId);
073: setLineNumber(lineNumber);
074: }
075:
076: /**
077: * Get the match pattern for the key definition
078: * @return the pattern specified in the "match" attribute of the xsl:key declaration
079: */
080:
081: public Pattern getMatch() {
082: return match;
083: }
084:
085: /**
086: * Get the use expression for the key definition
087: * @return the expression specified in the "use" attribute of the xsl:key declaration
088: */
089:
090: public Expression getUse() {
091: return getBody();
092: }
093:
094: /**
095: * Get the collation name for this key definition.
096: * @return the collation name (the collation URI)
097: */
098:
099: public String getCollationName() {
100: return collationName;
101: }
102:
103: /**
104: * Get the collation.
105: * @return the collation
106: */
107:
108: public Collator getCollation() {
109: return collation;
110: }
111:
112: /**
113: * Get the InstructionInfo details about the construct. This information isn't used for tracing,
114: * but it is available when inspecting the context stack.
115: */
116:
117: public InstructionInfo getInstructionInfo() {
118: InstructionDetails details = new InstructionDetails();
119: details.setConstructType(StandardNames.XSL_KEY);
120: details.setSystemId(getSystemId());
121: details.setLineNumber(getLineNumber());
122: details.setProperty("key", this );
123: return details;
124: }
125: }
126:
127: //
128: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
129: // you may not use this file except in compliance with the License. You may obtain a copy of the
130: // License at http://www.mozilla.org/MPL/
131: //
132: // Software distributed under the License is distributed on an "AS IS" basis,
133: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
134: // See the License for the specific language governing rights and limitations under the License.
135: //
136: // The Original Code is: all this file
137: //
138: // The Initial Developer of the Original Code is Michael H. Kay.
139: //
140: // Contributor(s):
141: //
|