1 17 package org.eclipse.emf.ecore.xmi.impl; 18 19 20 import org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.Escape; 21 22 23 29 public class ConfigurationCache 30 { 31 public static final ConfigurationCache INSTANCE = new ConfigurationCache(); 32 33 protected static final int SIZE = 100; 34 35 protected XMLString printers[] = new XMLString [SIZE]; 36 37 protected Escape escapes[] = new Escape [SIZE]; 38 39 protected int freePrinterIndex = -1; 40 41 protected int freeEscapeIndex = -1; 42 43 protected int currentSize = SIZE; 44 45 protected ConfigurationCache() 46 { 47 } 48 49 protected synchronized XMLString getPrinter() 50 { 51 if (freePrinterIndex < 0) 52 { 53 return new XMLString(); 54 } 55 XMLString printer = printers[freePrinterIndex]; 56 printers[freePrinterIndex--] = null; 57 return printer; 58 } 59 60 protected synchronized void releasePrinter(XMLString printer) 61 { 62 ++freePrinterIndex; 63 if (printers.length == freePrinterIndex) 64 { 65 currentSize += SIZE; 66 XMLString newarray[] = new XMLString [currentSize]; 67 System.arraycopy(printers, 0, newarray, 0, printers.length); 68 printers = newarray; 69 } 70 printers[freePrinterIndex] = printer; 71 } 72 73 protected synchronized Escape getEscape() 74 { 75 if (freeEscapeIndex < 0) 76 { 77 return new Escape(); 78 } 79 Escape escape = escapes[freeEscapeIndex]; 80 escapes[freeEscapeIndex--] = null; 81 return escape; 82 } 83 84 protected synchronized void releaseEscape(Escape escape) 85 { 86 ++freeEscapeIndex; 87 if (escapes.length == freeEscapeIndex) 88 { 89 currentSize += SIZE; 90 Escape newarray[] = new Escape [currentSize]; 91 System.arraycopy(escapes, 0, newarray, 0, escapes.length); 92 escapes = newarray; 93 } 94 escapes[freeEscapeIndex] = escape; 95 } 96 97 public synchronized void release() 98 { 99 freeEscapeIndex = -1; 100 freePrinterIndex = -1; 101 for (int i = 0; i < printers.length; i++) 102 { 103 printers[i] = null; 104 } 105 for (int i = 0; i < escapes.length; i++) 106 { 107 escapes[i] = null; 108 } 109 } 110 111 } 112 | Popular Tags |