KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > instruct > SlotManager


1 package net.sf.saxon.instruct;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.ArrayList JavaDoc;
6
7
8 /**
9  * A SlotManager supports functions, templates, etc: specifically, any executable code that
10  * requires a stack frame containing local variables. In XSLT a SlotManager underpins any
11  * top-level element that can contain local variable declarations,
12  * specifically, a top-level xsl:template, xsl:variable, xsl:param, or xsl:function element
13  * or an xsl:attribute-set element or xsl:key element. In XQuery it underpins functions and
14  * global variables. The purpose of the SlotManager is to allocate slot numbers to variables
15  * in the stack, and to record how many slots are needed. A Debugger may define a subclass
16  * with additional functionality.
17 */

18
19 public class SlotManager implements Serializable JavaDoc {
20
21     private ArrayList JavaDoc variableMap = new ArrayList JavaDoc(10);
22     private int numberOfVariables = 0;
23
24     /**
25      * The constructor should not be called directly. A new SlotManager should be obtained using
26      * the factory method in the Configuration object.
27      */

28
29     public SlotManager(){}
30
31     /**
32     * Get number of variables (size of stack frame)
33     */

34
35     public int getNumberOfVariables() {
36         return numberOfVariables;
37     }
38
39     /**
40      * Set the number of variables
41      * @param numberOfVariables
42      */

43
44     public void setNumberOfVariables(int numberOfVariables) {
45         this.numberOfVariables = numberOfVariables;
46         variableMap.trimToSize();
47     }
48
49     /**
50     * Allocate a slot number for a variable
51     */

52
53     public int allocateSlotNumber(int fingerprint) {
54         variableMap.add(new Integer JavaDoc(fingerprint));
55         return numberOfVariables++;
56     }
57
58     /**
59      * Get the variable map (simply a list of fingerprints of the variable names). Note that it
60      * is possible for several variables to have the same name.
61      */

62
63     public List JavaDoc getVariableMap() {
64         return variableMap;
65     }
66
67 }
68
69 //
70
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
71
// you may not use this file except in compliance with the License. You may obtain a copy of the
72
// License at http://www.mozilla.org/MPL/
73
//
74
// Software distributed under the License is distributed on an "AS IS" basis,
75
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
76
// See the License for the specific language governing rights and limitations under the License.
77
//
78
// The Original Code is: all this file.
79
//
80
// The Initial Developer of the Original Code is Michael H. Kay.
81
//
82
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
83
//
84
// Contributor(s): none.
85
//
86
Popular Tags