1 package net.sf.saxon.instruct; 2 3 import net.sf.saxon.event.LocationProvider; 4 5 import java.io.Serializable ; 6 7 12 13 public class LocationMap implements LocationProvider, Serializable { 14 15 private String [] modules = new String [10]; 16 private int numberOfModules = 0; 17 18 public LocationMap() {} 19 20 23 24 public int allocateLocationId(String module, int lineNumber) { 25 if (module == null) { 26 module = "*module with no systemId*"; 28 } 29 int mod = -1; 30 for (int m=numberOfModules-1; m>=0; m--) { 31 if (modules[m].equals(module)) { 32 mod = m; 33 } 34 } 35 if (mod == -1) { 36 if (numberOfModules >= modules.length) { 37 String [] m2 = new String [numberOfModules*2]; 38 System.arraycopy(modules, 0, m2, 0, numberOfModules); 39 modules = m2; 40 } 41 mod = numberOfModules; 42 modules[numberOfModules++] = module; 43 } 44 if (mod >= 1024) { 45 modules[mod] = "*unknown module*"; 46 mod = 1023; 47 } 48 if (lineNumber > 999999) { 49 lineNumber = 999999; 50 } 51 return (mod<<20) + lineNumber; 52 } 53 54 57 58 public String getSystemId(int locationId) { 59 int m = locationId>>20; 60 if (m < 0 || m >= numberOfModules) { 61 return null; 62 } 63 return modules[m]; 64 } 65 66 69 70 public int getLineNumber(int locationId) { 71 return locationId & 0xfffff; 72 } 73 74 } 75 76 | Popular Tags |