01: package net.sf.saxon.instruct;
02:
03: /**
04: * A GlobalParameterSet is a set of parameters supplied when invoking a stylesheet or query.
05: * It is a collection of name-value pairs, the names being represented by numeric references
06: * to the NamePool. The values are objects, as supplied by the caller: conversion of the object
07: * to a required type takes place when the parameter is actually used.
08: */
09:
10: public class GlobalParameterSet {
11: private int[] keys = new int[10];
12: private Object[] values = new Object[10];
13: private int used = 0;
14:
15: /**
16: * Create an empty parameter set
17: */
18:
19: public GlobalParameterSet() {
20: }
21:
22: /**
23: * Create a parameter set as a copy of an existing parameter set
24: */
25:
26: public GlobalParameterSet(GlobalParameterSet existing) {
27: for (int i = 0; i < existing.used; i++) {
28: put(existing.keys[i], existing.values[i]);
29: }
30: }
31:
32: /**
33: * Add a parameter to the ParameterSet
34: *
35: * @param fingerprint The fingerprint of the parameter name.
36: * @param value The value of the parameter
37: */
38:
39: public void put(int fingerprint, Object value) {
40: for (int i = 0; i < used; i++) {
41: if (keys[i] == fingerprint) {
42: values[i] = value;
43: return;
44: }
45: }
46: if (used + 1 > keys.length) {
47: int[] newkeys = new int[used * 2];
48: Object[] newvalues = new Object[used * 2]; // was (incorrectly) Value[]
49: System.arraycopy(values, 0, newvalues, 0, used);
50: System.arraycopy(keys, 0, newkeys, 0, used);
51: values = newvalues;
52: keys = newkeys;
53: }
54: keys[used] = fingerprint;
55: values[used++] = value;
56: }
57:
58: /**
59: * Get a parameter
60: *
61: * @param fingerprint The fingerprint of the name.
62: * @return The value of the parameter, or null if not defined
63: */
64:
65: public Object get(int fingerprint) {
66: for (int i = 0; i < used; i++) {
67: if (keys[i] == fingerprint) {
68: return values[i];
69: }
70: }
71: return null;
72: }
73:
74: /**
75: * Clear all values
76: */
77:
78: public void clear() {
79: used = 0;
80: }
81:
82: }
83: //
84: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
85: // you may not use this file except in compliance with the License. You may obtain a copy of the
86: // License at http://www.mozilla.org/MPL/
87: //
88: // Software distributed under the License is distributed on an "AS IS" basis,
89: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
90: // See the License for the specific language governing rights and limitations under the License.
91: //
92: // The Original Code is: all this file.
93: //
94: // The Initial Developer of the Original Code is Michael H. Kay.
95: //
96: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
97: //
98: // Contributor(s): none.
99: //
|