1 16 17 package org.apache.xerces.impl.xs; 18 19 import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl; 20 21 33 public final class XSDeclarationPool { 34 35 private static final int CHUNK_SHIFT = 8; 37 38 private static final int CHUNK_SIZE = 1 << CHUNK_SHIFT; 39 40 41 private static final int CHUNK_MASK = CHUNK_SIZE - 1; 42 43 44 private static final int INITIAL_CHUNK_COUNT = (1 << (10 - CHUNK_SHIFT)); 46 47 private XSElementDecl fElementDecl[][] = new XSElementDecl[INITIAL_CHUNK_COUNT][]; 48 private int fElementDeclIndex = 0; 49 50 51 private XSParticleDecl fParticleDecl[][] = new XSParticleDecl[INITIAL_CHUNK_COUNT][]; 52 private int fParticleDeclIndex = 0; 53 54 55 private XSModelGroupImpl fModelGroup[][] = new XSModelGroupImpl[INITIAL_CHUNK_COUNT][]; 56 private int fModelGroupIndex = 0; 57 58 59 private XSAttributeDecl fAttrDecl[][] = new XSAttributeDecl[INITIAL_CHUNK_COUNT][]; 60 private int fAttrDeclIndex = 0; 61 62 63 private XSComplexTypeDecl fCTDecl[][] = new XSComplexTypeDecl[INITIAL_CHUNK_COUNT][]; 64 private int fCTDeclIndex = 0; 65 66 67 private XSSimpleTypeDecl fSTDecl[][] = new XSSimpleTypeDecl[INITIAL_CHUNK_COUNT][]; 68 private int fSTDeclIndex = 0; 69 70 71 private XSAttributeUseImpl fAttributeUse[][] = new XSAttributeUseImpl[INITIAL_CHUNK_COUNT][]; 72 private int fAttributeUseIndex = 0; 73 74 public final XSElementDecl getElementDecl(){ 75 int chunk = fElementDeclIndex >> CHUNK_SHIFT; 76 int index = fElementDeclIndex & CHUNK_MASK; 77 ensureElementDeclCapacity(chunk); 78 if (fElementDecl[chunk][index] == null) { 79 fElementDecl[chunk][index] = new XSElementDecl(); 80 } else { 81 fElementDecl[chunk][index].reset(); 82 } 83 fElementDeclIndex++; 84 return fElementDecl[chunk][index]; 85 } 86 87 public final XSAttributeDecl getAttributeDecl(){ 88 int chunk = fAttrDeclIndex >> CHUNK_SHIFT; 89 int index = fAttrDeclIndex & CHUNK_MASK; 90 ensureAttrDeclCapacity(chunk); 91 if (fAttrDecl[chunk][index] == null) { 92 fAttrDecl[chunk][index] = new XSAttributeDecl(); 93 } else { 94 fAttrDecl[chunk][index].reset(); 95 } 96 fAttrDeclIndex++; 97 return fAttrDecl[chunk][index]; 98 99 } 100 101 public final XSAttributeUseImpl getAttributeUse(){ 102 int chunk = fAttributeUseIndex >> CHUNK_SHIFT; 103 int index = fAttributeUseIndex & CHUNK_MASK; 104 ensureAttributeUseCapacity(chunk); 105 if (fAttributeUse[chunk][index] == null) { 106 fAttributeUse[chunk][index] = new XSAttributeUseImpl(); 107 } else { 108 fAttributeUse[chunk][index].reset(); 109 } 110 fAttributeUseIndex++; 111 return fAttributeUse[chunk][index]; 112 113 } 114 115 public final XSComplexTypeDecl getComplexTypeDecl(){ 116 int chunk = fCTDeclIndex >> CHUNK_SHIFT; 117 int index = fCTDeclIndex & CHUNK_MASK; 118 ensureCTDeclCapacity(chunk); 119 if (fCTDecl[chunk][index] == null) { 120 121 fCTDecl[chunk][index] = new XSComplexTypeDecl(); 122 } else { 123 fCTDecl[chunk][index].reset(); 124 } 125 fCTDeclIndex++; 126 return fCTDecl[chunk][index]; 127 } 128 129 public final XSSimpleTypeDecl getSimpleTypeDecl(){ 130 int chunk = fSTDeclIndex >> CHUNK_SHIFT; 131 int index = fSTDeclIndex & CHUNK_MASK; 132 ensureSTDeclCapacity(chunk); 133 if (fSTDecl[chunk][index] == null) { 134 fSTDecl[chunk][index] = new XSSimpleTypeDecl(); 135 } else { 136 fSTDecl[chunk][index].reset(); 137 } 138 fSTDeclIndex++; 139 return fSTDecl[chunk][index]; 140 141 } 142 143 public final XSParticleDecl getParticleDecl(){ 144 int chunk = fParticleDeclIndex >> CHUNK_SHIFT; 145 int index = fParticleDeclIndex & CHUNK_MASK; 146 ensureParticleDeclCapacity(chunk); 147 if (fParticleDecl[chunk][index] == null) { 148 fParticleDecl[chunk][index] = new XSParticleDecl(); 149 } else { 150 fParticleDecl[chunk][index].reset(); 151 } 152 fParticleDeclIndex++; 153 return fParticleDecl[chunk][index]; 154 } 155 156 public final XSModelGroupImpl getModelGroup(){ 157 int chunk = fModelGroupIndex >> CHUNK_SHIFT; 158 int index = fModelGroupIndex & CHUNK_MASK; 159 ensureModelGroupCapacity(chunk); 160 if (fModelGroup[chunk][index] == null) { 161 fModelGroup[chunk][index] = new XSModelGroupImpl(); 162 } else { 163 fModelGroup[chunk][index].reset(); 164 } 165 fModelGroupIndex++; 166 return fModelGroup[chunk][index]; 167 } 168 169 175 private boolean ensureElementDeclCapacity(int chunk) { 176 if (chunk >= fElementDecl.length) { 177 fElementDecl = resize(fElementDecl, fElementDecl.length * 2); 178 } else if (fElementDecl[chunk] != null) { 179 return false; 180 } 181 182 fElementDecl[chunk] = new XSElementDecl[CHUNK_SIZE]; 183 return true; 184 } 185 186 private static XSElementDecl[][] resize(XSElementDecl array[][], int newsize) { 187 XSElementDecl newarray[][] = new XSElementDecl[newsize][]; 188 System.arraycopy(array, 0, newarray, 0, array.length); 189 return newarray; 190 } 191 192 private boolean ensureParticleDeclCapacity(int chunk) { 193 if (chunk >= fParticleDecl.length) { 194 fParticleDecl = resize(fParticleDecl, fParticleDecl.length * 2); 195 } else if (fParticleDecl[chunk] != null) { 196 return false; 197 } 198 199 fParticleDecl[chunk] = new XSParticleDecl[CHUNK_SIZE]; 200 return true; 201 } 202 203 private boolean ensureModelGroupCapacity(int chunk) { 204 if (chunk >= fModelGroup.length) { 205 fModelGroup = resize(fModelGroup, fModelGroup.length * 2); 206 } else if (fModelGroup[chunk] != null) { 207 return false; 208 } 209 210 fModelGroup[chunk] = new XSModelGroupImpl[CHUNK_SIZE]; 211 return true; 212 } 213 214 private static XSParticleDecl[][] resize(XSParticleDecl array[][], int newsize) { 215 XSParticleDecl newarray[][] = new XSParticleDecl[newsize][]; 216 System.arraycopy(array, 0, newarray, 0, array.length); 217 return newarray; 218 } 219 220 private static XSModelGroupImpl[][] resize(XSModelGroupImpl array[][], int newsize) { 221 XSModelGroupImpl newarray[][] = new XSModelGroupImpl[newsize][]; 222 System.arraycopy(array, 0, newarray, 0, array.length); 223 return newarray; 224 } 225 226 private boolean ensureAttrDeclCapacity(int chunk) { 227 if (chunk >= fAttrDecl.length) { 228 fAttrDecl = resize(fAttrDecl, fAttrDecl.length * 2); 229 } else if (fAttrDecl[chunk] != null) { 230 return false; 231 } 232 233 fAttrDecl[chunk] = new XSAttributeDecl[CHUNK_SIZE]; 234 return true; 235 } 236 237 private static XSAttributeDecl[][] resize(XSAttributeDecl array[][], int newsize) { 238 XSAttributeDecl newarray[][] = new XSAttributeDecl[newsize][]; 239 System.arraycopy(array, 0, newarray, 0, array.length); 240 return newarray; 241 } 242 243 private boolean ensureAttributeUseCapacity(int chunk) { 244 if (chunk >= fAttributeUse.length) { 245 fAttributeUse = resize(fAttributeUse, fAttributeUse.length * 2); 246 } else if (fAttributeUse[chunk] != null) { 247 return false; 248 } 249 250 fAttributeUse[chunk] = new XSAttributeUseImpl[CHUNK_SIZE]; 251 return true; 252 } 253 254 private static XSAttributeUseImpl[][] resize(XSAttributeUseImpl array[][], int newsize) { 255 XSAttributeUseImpl newarray[][] = new XSAttributeUseImpl[newsize][]; 256 System.arraycopy(array, 0, newarray, 0, array.length); 257 return newarray; 258 } 259 260 private boolean ensureSTDeclCapacity(int chunk) { 261 if (chunk >= fSTDecl.length) { 262 fSTDecl = resize(fSTDecl, fSTDecl.length * 2); 263 } else if (fSTDecl[chunk] != null) { 264 return false; 265 } 266 267 fSTDecl[chunk] = new XSSimpleTypeDecl[CHUNK_SIZE]; 268 return true; 269 } 270 271 private static XSSimpleTypeDecl[][] resize(XSSimpleTypeDecl array[][], int newsize) { 272 XSSimpleTypeDecl newarray[][] = new XSSimpleTypeDecl[newsize][]; 273 System.arraycopy(array, 0, newarray, 0, array.length); 274 return newarray; 275 } 276 277 private boolean ensureCTDeclCapacity(int chunk) { 278 279 if (chunk >= fCTDecl.length) { 280 fCTDecl = resize(fCTDecl, fCTDecl.length * 2); 281 } else if (fCTDecl[chunk] != null){ 282 return false; 283 } 284 285 fCTDecl[chunk] = new XSComplexTypeDecl[CHUNK_SIZE]; 286 return true; 287 } 288 289 private static XSComplexTypeDecl[][] resize(XSComplexTypeDecl array[][], int newsize) { 290 XSComplexTypeDecl newarray[][] = new XSComplexTypeDecl[newsize][]; 291 System.arraycopy(array, 0, newarray, 0, array.length); 292 return newarray; 293 } 294 295 296 297 public void reset(){ 298 fElementDeclIndex = 0; 299 fParticleDeclIndex = 0; 300 fModelGroupIndex = 0; 301 fSTDeclIndex = 0; 302 fCTDeclIndex = 0; 303 fAttrDeclIndex = 0; 304 fAttributeUseIndex = 0; 305 } 306 307 308 } 309 | Popular Tags |