1 57 58 package com.sun.org.apache.xerces.internal.impl.xs; 59 60 import com.sun.org.apache.xerces.internal.impl.dv.xs.XSSimpleTypeDecl; 61 62 72 public final class XSDeclarationPool { 73 74 private static final int CHUNK_SHIFT = 8; 76 77 private static final int CHUNK_SIZE = 1 << CHUNK_SHIFT; 78 79 80 private static final int CHUNK_MASK = CHUNK_SIZE - 1; 81 82 83 private static final int INITIAL_CHUNK_COUNT = (1 << (10 - CHUNK_SHIFT)); 85 86 private XSElementDecl fElementDecl[][] = new XSElementDecl[INITIAL_CHUNK_COUNT][]; 87 private int fElementDeclIndex = 0; 88 89 90 private XSParticleDecl fParticleDecl[][] = new XSParticleDecl[INITIAL_CHUNK_COUNT][]; 91 private int fParticleDeclIndex = 0; 92 93 94 private XSModelGroupImpl fModelGroup[][] = new XSModelGroupImpl[INITIAL_CHUNK_COUNT][]; 95 private int fModelGroupIndex = 0; 96 97 98 private XSAttributeDecl fAttrDecl[][] = new XSAttributeDecl[INITIAL_CHUNK_COUNT][]; 99 private int fAttrDeclIndex = 0; 100 101 102 private XSComplexTypeDecl fCTDecl[][] = new XSComplexTypeDecl[INITIAL_CHUNK_COUNT][]; 103 private int fCTDeclIndex = 0; 104 105 106 private XSSimpleTypeDecl fSTDecl[][] = new XSSimpleTypeDecl[INITIAL_CHUNK_COUNT][]; 107 private int fSTDeclIndex = 0; 108 109 110 private XSAttributeUseImpl fAttributeUse[][] = new XSAttributeUseImpl[INITIAL_CHUNK_COUNT][]; 111 private int fAttributeUseIndex = 0; 112 113 public final XSElementDecl getElementDecl(){ 114 int chunk = fElementDeclIndex >> CHUNK_SHIFT; 115 int index = fElementDeclIndex & CHUNK_MASK; 116 ensureElementDeclCapacity(chunk); 117 if (fElementDecl[chunk][index] == null) { 118 fElementDecl[chunk][index] = new XSElementDecl(); 119 } else { 120 fElementDecl[chunk][index].reset(); 121 } 122 fElementDeclIndex++; 123 return fElementDecl[chunk][index]; 124 } 125 126 public final XSAttributeDecl getAttributeDecl(){ 127 int chunk = fAttrDeclIndex >> CHUNK_SHIFT; 128 int index = fAttrDeclIndex & CHUNK_MASK; 129 ensureAttrDeclCapacity(chunk); 130 if (fAttrDecl[chunk][index] == null) { 131 fAttrDecl[chunk][index] = new XSAttributeDecl(); 132 } else { 133 fAttrDecl[chunk][index].reset(); 134 } 135 fAttrDeclIndex++; 136 return fAttrDecl[chunk][index]; 137 138 } 139 140 public final XSAttributeUseImpl getAttributeUse(){ 141 int chunk = fAttributeUseIndex >> CHUNK_SHIFT; 142 int index = fAttributeUseIndex & CHUNK_MASK; 143 ensureAttributeUseCapacity(chunk); 144 if (fAttributeUse[chunk][index] == null) { 145 fAttributeUse[chunk][index] = new XSAttributeUseImpl(); 146 } else { 147 fAttributeUse[chunk][index].reset(); 148 } 149 fAttributeUseIndex++; 150 return fAttributeUse[chunk][index]; 151 152 } 153 154 public final XSComplexTypeDecl getComplexTypeDecl(){ 155 int chunk = fCTDeclIndex >> CHUNK_SHIFT; 156 int index = fCTDeclIndex & CHUNK_MASK; 157 ensureCTDeclCapacity(chunk); 158 if (fCTDecl[chunk][index] == null) { 159 160 fCTDecl[chunk][index] = new XSComplexTypeDecl(); 161 } else { 162 fCTDecl[chunk][index].reset(); 163 } 164 fCTDeclIndex++; 165 return fCTDecl[chunk][index]; 166 } 167 168 public final XSSimpleTypeDecl getSimpleTypeDecl(){ 169 int chunk = fSTDeclIndex >> CHUNK_SHIFT; 170 int index = fSTDeclIndex & CHUNK_MASK; 171 ensureSTDeclCapacity(chunk); 172 if (fSTDecl[chunk][index] == null) { 173 fSTDecl[chunk][index] = new XSSimpleTypeDecl(); 174 } else { 175 fSTDecl[chunk][index].reset(); 176 } 177 fSTDeclIndex++; 178 return fSTDecl[chunk][index]; 179 180 } 181 182 public final XSParticleDecl getParticleDecl(){ 183 int chunk = fParticleDeclIndex >> CHUNK_SHIFT; 184 int index = fParticleDeclIndex & CHUNK_MASK; 185 ensureParticleDeclCapacity(chunk); 186 if (fParticleDecl[chunk][index] == null) { 187 fParticleDecl[chunk][index] = new XSParticleDecl(); 188 } else { 189 fParticleDecl[chunk][index].reset(); 190 } 191 fParticleDeclIndex++; 192 return fParticleDecl[chunk][index]; 193 } 194 195 public final XSModelGroupImpl getModelGroup(){ 196 int chunk = fModelGroupIndex >> CHUNK_SHIFT; 197 int index = fModelGroupIndex & CHUNK_MASK; 198 ensureModelGroupCapacity(chunk); 199 if (fModelGroup[chunk][index] == null) { 200 fModelGroup[chunk][index] = new XSModelGroupImpl(); 201 } else { 202 fModelGroup[chunk][index].reset(); 203 } 204 fModelGroupIndex++; 205 return fModelGroup[chunk][index]; 206 } 207 208 214 private boolean ensureElementDeclCapacity(int chunk) { 215 if (chunk >= fElementDecl.length) { 216 fElementDecl = resize(fElementDecl, fElementDecl.length * 2); 217 } else if (fElementDecl[chunk] != null) { 218 return false; 219 } 220 221 fElementDecl[chunk] = new XSElementDecl[CHUNK_SIZE]; 222 return true; 223 } 224 225 private static XSElementDecl[][] resize(XSElementDecl array[][], int newsize) { 226 XSElementDecl newarray[][] = new XSElementDecl[newsize][]; 227 System.arraycopy(array, 0, newarray, 0, array.length); 228 return newarray; 229 } 230 231 private boolean ensureParticleDeclCapacity(int chunk) { 232 if (chunk >= fParticleDecl.length) { 233 fParticleDecl = resize(fParticleDecl, fParticleDecl.length * 2); 234 } else if (fParticleDecl[chunk] != null) { 235 return false; 236 } 237 238 fParticleDecl[chunk] = new XSParticleDecl[CHUNK_SIZE]; 239 return true; 240 } 241 242 private boolean ensureModelGroupCapacity(int chunk) { 243 if (chunk >= fModelGroup.length) { 244 fModelGroup = resize(fModelGroup, fModelGroup.length * 2); 245 } else if (fModelGroup[chunk] != null) { 246 return false; 247 } 248 249 fModelGroup[chunk] = new XSModelGroupImpl[CHUNK_SIZE]; 250 return true; 251 } 252 253 private static XSParticleDecl[][] resize(XSParticleDecl array[][], int newsize) { 254 XSParticleDecl newarray[][] = new XSParticleDecl[newsize][]; 255 System.arraycopy(array, 0, newarray, 0, array.length); 256 return newarray; 257 } 258 259 private static XSModelGroupImpl[][] resize(XSModelGroupImpl array[][], int newsize) { 260 XSModelGroupImpl newarray[][] = new XSModelGroupImpl[newsize][]; 261 System.arraycopy(array, 0, newarray, 0, array.length); 262 return newarray; 263 } 264 265 private boolean ensureAttrDeclCapacity(int chunk) { 266 if (chunk >= fAttrDecl.length) { 267 fAttrDecl = resize(fAttrDecl, fAttrDecl.length * 2); 268 } else if (fAttrDecl[chunk] != null) { 269 return false; 270 } 271 272 fAttrDecl[chunk] = new XSAttributeDecl[CHUNK_SIZE]; 273 return true; 274 } 275 276 private static XSAttributeDecl[][] resize(XSAttributeDecl array[][], int newsize) { 277 XSAttributeDecl newarray[][] = new XSAttributeDecl[newsize][]; 278 System.arraycopy(array, 0, newarray, 0, array.length); 279 return newarray; 280 } 281 282 private boolean ensureAttributeUseCapacity(int chunk) { 283 if (chunk >= fAttributeUse.length) { 284 fAttributeUse = resize(fAttributeUse, fAttributeUse.length * 2); 285 } else if (fAttributeUse[chunk] != null) { 286 return false; 287 } 288 289 fAttributeUse[chunk] = new XSAttributeUseImpl[CHUNK_SIZE]; 290 return true; 291 } 292 293 private static XSAttributeUseImpl[][] resize(XSAttributeUseImpl array[][], int newsize) { 294 XSAttributeUseImpl newarray[][] = new XSAttributeUseImpl[newsize][]; 295 System.arraycopy(array, 0, newarray, 0, array.length); 296 return newarray; 297 } 298 299 private boolean ensureSTDeclCapacity(int chunk) { 300 if (chunk >= fSTDecl.length) { 301 fSTDecl = resize(fSTDecl, fSTDecl.length * 2); 302 } else if (fSTDecl[chunk] != null) { 303 return false; 304 } 305 306 fSTDecl[chunk] = new XSSimpleTypeDecl[CHUNK_SIZE]; 307 return true; 308 } 309 310 private static XSSimpleTypeDecl[][] resize(XSSimpleTypeDecl array[][], int newsize) { 311 XSSimpleTypeDecl newarray[][] = new XSSimpleTypeDecl[newsize][]; 312 System.arraycopy(array, 0, newarray, 0, array.length); 313 return newarray; 314 } 315 316 private boolean ensureCTDeclCapacity(int chunk) { 317 318 if (chunk >= fCTDecl.length) { 319 fCTDecl = resize(fCTDecl, fCTDecl.length * 2); 320 } else if (fCTDecl[chunk] != null){ 321 return false; 322 } 323 324 fCTDecl[chunk] = new XSComplexTypeDecl[CHUNK_SIZE]; 325 return true; 326 } 327 328 private static XSComplexTypeDecl[][] resize(XSComplexTypeDecl array[][], int newsize) { 329 XSComplexTypeDecl newarray[][] = new XSComplexTypeDecl[newsize][]; 330 System.arraycopy(array, 0, newarray, 0, array.length); 331 return newarray; 332 } 333 334 335 336 public void reset(){ 337 fElementDeclIndex = 0; 338 fParticleDeclIndex = 0; 339 fModelGroupIndex = 0; 340 fSTDeclIndex = 0; 341 fCTDeclIndex = 0; 342 fAttrDeclIndex = 0; 343 fAttributeUseIndex = 0; 344 } 345 346 347 } 348 | Popular Tags |