KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > trans > KeyDefinition


1 package net.sf.saxon.trans;
2 import net.sf.saxon.expr.Expression;
3 import net.sf.saxon.instruct.InstructionDetails;
4 import net.sf.saxon.instruct.Procedure;
5 import net.sf.saxon.instruct.SlotManager;
6 import net.sf.saxon.pattern.Pattern;
7 import net.sf.saxon.style.StandardNames;
8 import net.sf.saxon.trace.InstructionInfo;
9 import net.sf.saxon.trace.InstructionInfoProvider;
10
11 import java.io.Serializable JavaDoc;
12 import java.text.Collator JavaDoc;
13
14 /**
15   * Corresponds to a single xsl:key declaration.<P>
16   * @author Michael H. Kay
17   */

18
19 public class KeyDefinition extends Procedure implements Serializable JavaDoc, InstructionInfoProvider {
20
21     private Pattern match; // the match pattern
22
private Collator JavaDoc collation; // the collating sequence, when type=string
23
private String JavaDoc collationName; // the collation URI
24
private boolean backwardsCompatible = false;
25
26     /**
27     * Constructor to create a key definition
28     */

29
30     public KeyDefinition(Pattern match, Expression use, String JavaDoc collationName, Collator JavaDoc collation) {
31         this.match = match;
32         setBody(use);
33         this.collation = collation;
34         this.collationName = collationName;
35     }
36
37     /**
38      * Set backwards compatibility mode. The key definition is backwards compatible if ANY of the xsl:key
39      * declarations has version="1.0" in scope.
40      */

41
42     public void setBackwardsCompatible(boolean bc) {
43         backwardsCompatible = bc;
44     }
45
46     /**
47      * Test backwards compatibility mode
48      */

49
50     public boolean isBackwardsCompatible() {
51         return backwardsCompatible;
52     }
53
54     /**
55      * Set the map of local variables needed while evaluating the "use" expression
56      */

57
58     public void setStackFrameMap(SlotManager map) {
59         if (map != null && map.getNumberOfVariables() > 0) {
60             super.setStackFrameMap(map);
61         }
62     }
63
64     /**
65      * Set the system Id and line number of the source xsl:key definition
66      */

67
68     public void setLocation(String JavaDoc systemId, int lineNumber) {
69         setSystemId(systemId);
70         setLineNumber(lineNumber);
71     }
72
73     /**
74     * Get the match pattern for the key definition
75      * @return the pattern specified in the "match" attribute of the xsl:key declaration
76     */

77
78     public Pattern getMatch() {
79         return match;
80     }
81
82     /**
83     * Get the use expression for the key definition
84      * @return the expression specified in the "use" attribute of the xsl:key declaration
85     */

86
87     public Expression getUse() {
88         return getBody();
89     }
90
91     /**
92     * Get the collation name for this key definition.
93     * @return the collation name (the collation URI)
94     */

95
96     public String JavaDoc getCollationName() {
97         return collationName;
98     }
99
100     /**
101     * Get the collation.
102      * @return the collation
103     */

104
105     public Collator JavaDoc getCollation() {
106         return collation;
107     }
108
109     /**
110      * Get the InstructionInfo details about the construct. This information isn't used for tracing,
111      * but it is available when inspecting the context stack.
112      */

113
114     public InstructionInfo getInstructionInfo() {
115         InstructionDetails details = new InstructionDetails();
116         details.setConstructType(StandardNames.XSL_KEY);
117         details.setSystemId(getSystemId());
118         details.setLineNumber(getLineNumber());
119         details.setProperty("key", this);
120         return details;
121     }
122 }
123
124 //
125
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
126
// you may not use this file except in compliance with the License. You may obtain a copy of the
127
// License at http://www.mozilla.org/MPL/
128
//
129
// Software distributed under the License is distributed on an "AS IS" basis,
130
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
131
// See the License for the specific language governing rights and limitations under the License.
132
//
133
// The Original Code is: all this file
134
//
135
// The Initial Developer of the Original Code is Michael H. Kay.
136
//
137
// Contributor(s):
138
//
139
Popular Tags