KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.instruct;
2
3
4 /**
5  * A GlobalParameterSet is a set of parameters supplied when invoking a stylesheet or query.
6  * It is a collection of name-value pairs, the names being represented by numeric references
7  * to the NamePool. The values are objects, as supplied by the caller: conversion of the object
8  * to a required type takes place when the parameter is actually used.
9  */

10
11 public class GlobalParameterSet
12 {
13     private int[] keys = new int[10];
14     private Object JavaDoc[] values = new Object JavaDoc[10];
15     private int used = 0;
16
17     /**
18      * Create an empty parameter set
19      */

20
21     public GlobalParameterSet() {}
22
23     /**
24      * Create a parameter set as a copy of an existing parameter set
25      */

26
27     public GlobalParameterSet(GlobalParameterSet existing) {
28         for (int i=0; i<existing.used; i++) {
29             put(existing.keys[i], existing.values[i]);
30         }
31     }
32
33     /**
34      * Add a parameter to the ParameterSet
35      *
36      * @param fingerprint The fingerprint of the parameter name.
37      * @param value The value of the parameter
38      */

39
40     public void put (int fingerprint, Object JavaDoc value) {
41         for (int i=0; i<used; i++) {
42             if (keys[i]==fingerprint) {
43                 values[i]=value;
44                 return;
45             }
46         }
47         if (used+1 > keys.length) {
48             int[] newkeys = new int[used*2];
49             Object JavaDoc[] newvalues = new Object JavaDoc[used*2]; // was (incorrectly) Value[]
50
System.arraycopy(values, 0, newvalues, 0, used);
51             System.arraycopy(keys, 0, newkeys, 0, used);
52             values = newvalues;
53             keys = newkeys;
54         }
55         keys[used] = fingerprint;
56         values[used++] = value;
57     }
58
59     /**
60      * Get a parameter
61      *
62      * @param fingerprint The fingerprint of the name.
63      * @return The value of the parameter, or null if not defined
64      */

65
66     public Object JavaDoc get (int fingerprint) {
67         for (int i=0; i<used; i++) {
68             if (keys[i]==fingerprint) {
69                 return values[i];
70             }
71         }
72         return null;
73     }
74
75     /**
76      * Clear all values
77      */

78
79     public void clear() {
80         used = 0;
81     }
82
83 }
84 //
85
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
86
// you may not use this file except in compliance with the License. You may obtain a copy of the
87
// License at http://www.mozilla.org/MPL/
88
//
89
// Software distributed under the License is distributed on an "AS IS" basis,
90
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
91
// See the License for the specific language governing rights and limitations under the License.
92
//
93
// The Original Code is: all this file.
94
//
95
// The Initial Developer of the Original Code is Michael H. Kay.
96
//
97
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
98
//
99
// Contributor(s): none.
100
//
Popular Tags