KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > tree > SystemIdMap


1 package net.sf.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 Michael H. Kay
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         if (allocated==0) return null;
55         // could use a binary chop, but it's not important
56
for (int i=1; i<allocated; i++) {
57             if (sequenceNumbers[i] > sequence) {
58                 return uris[i-1];
59             }
60         }
61         return uris[allocated-1];
62     }
63             
64        
65 }
66
67 //
68
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
69
// you may not use this file except in compliance with the License. You may obtain a copy of the
70
// License at http://www.mozilla.org/MPL/
71
//
72
// Software distributed under the License is distributed on an "AS IS" basis,
73
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
74
// See the License for the specific language governing rights and limitations under the License.
75
//
76
// The Original Code is: all this file.
77
//
78
// The Initial Developer of the Original Code is Michael H. Kay.
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