KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > tree > SystemIdMap


1 package com.icl.saxon.tree;
2
3 /**
4   * System IDs are not held in nodes in the tree, because they are usually the same
5   * for a whole document.
6   * This class provides a map from element sequence numbers to System IDs: it is
7   * linked to the root node of the tree.
8   * Note that the System ID is not necessarily the same as the Base URI. The System ID relates
9   * to the external entity in which a node was physically located; this provides a default for
10   * the Base URI, but this may be modified by specifying an xml:base attribute
11   *
12   * @author <A HREF="mailto:mhkay@iclway.co.uk>Michael H. Kay</A>
13   */

14
15 public class SystemIdMap {
16
17     private int[] sequenceNumbers;
18     private String JavaDoc[] uris;
19     private int allocated;
20
21     public SystemIdMap() {
22         sequenceNumbers = new int[10];
23         uris = new String JavaDoc[10];
24         allocated = 0;
25     }
26
27     /**
28     * Set the system ID corresponding to a given sequence number
29     */

30
31     public void setSystemId(int sequence, String JavaDoc uri) {
32         // ignore it if same as previous
33
if (allocated>0 && uri.equals(uris[allocated-1])) {
34             return;
35         }
36         if (sequenceNumbers.length <= allocated + 1) {
37             int[] s = new int[allocated * 2];
38             String JavaDoc[] u = new String JavaDoc[allocated * 2];
39             System.arraycopy(sequenceNumbers, 0, s, 0, allocated);
40             System.arraycopy(uris, 0, u, 0, allocated);
41             sequenceNumbers = s;
42             uris = u;
43         }
44         sequenceNumbers[allocated] = sequence;
45         uris[allocated] = uri;
46         allocated++;
47     }
48
49     /**
50     * Get the system ID corresponding to a given sequence number
51     */

52
53     public String JavaDoc getSystemId(int sequence) {
54         // could use a binary chop, but it's not important
55
for (int i=1; i<allocated; i++) {
56             if (sequenceNumbers[i] > sequence) {
57                 return uris[i-1];
58             }
59         }
60         return uris[allocated-1];
61     }
62             
63        
64 }
65
66 //
67
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
68
// you may not use this file except in compliance with the License. You may obtain a copy of the
69
// License at http://www.mozilla.org/MPL/
70
//
71
// Software distributed under the License is distributed on an "AS IS" basis,
72
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
73
// See the License for the specific language governing rights and limitations under the License.
74
//
75
// The Original Code is: all this file.
76
//
77
// The Initial Developer of the Original Code is
78
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
79
//
80
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
81
//
82
// Contributor(s): none.
83
//
84
Popular Tags