1 9 package javolution.xml.stream; 10 11 import java.io.InputStream ; 12 import java.io.Reader ; 13 import j2me.util.Map; 14 import javolution.context.ObjectFactory; 15 16 50 public abstract class XMLInputFactory { 51 52 56 public static final String IS_COALESCING = "javolution.xml.stream.isCoalescing"; 57 58 71 public static final String ENTITIES = "javolution.xml.stream.entities"; 72 73 76 protected XMLInputFactory() { 77 } 78 79 85 public static XMLInputFactory newInstance() { 86 return new Default(); 87 } 88 89 95 public abstract XMLStreamReader createXMLStreamReader(Reader reader) 96 throws XMLStreamException; 97 98 105 public abstract XMLStreamReader createXMLStreamReader(InputStream stream) 106 throws XMLStreamException; 107 108 116 public abstract XMLStreamReader createXMLStreamReader(InputStream stream, 117 String encoding) throws XMLStreamException; 118 119 130 public abstract void setProperty(String name, Object value) 131 throws IllegalArgumentException ; 132 133 140 public abstract Object getProperty(String name) 141 throws IllegalArgumentException ; 142 143 150 public abstract boolean isPropertySupported(String name); 151 152 155 private static class Default extends XMLInputFactory { 156 157 Map _entities = null; 158 159 public XMLStreamReader createXMLStreamReader(Reader reader) 161 throws XMLStreamException { 162 XMLStreamReaderImpl xmlReader = newReader(); 163 xmlReader.setInput(reader); 164 return xmlReader; 165 } 166 167 public XMLStreamReader createXMLStreamReader(InputStream stream) 169 throws XMLStreamException { 170 XMLStreamReaderImpl xmlReader = newReader(); 171 xmlReader.setInput(stream); 172 return xmlReader; 173 } 174 175 public XMLStreamReader createXMLStreamReader(InputStream stream, 177 String encoding) throws XMLStreamException { 178 XMLStreamReaderImpl xmlReader = newReader(); 179 xmlReader.setInput(stream, encoding); 180 return xmlReader; 181 } 182 183 public void setProperty(String name, Object value) 185 throws IllegalArgumentException { 186 if (name.equals(IS_COALESCING)) { 187 } else if (name.equals(ENTITIES)) { 189 _entities = (Map) value; 190 } else { 191 throw new IllegalArgumentException ("Property: " + name 192 + " not supported"); 193 } 194 } 195 196 public Object getProperty(String name) throws IllegalArgumentException { 198 if (name.equals(IS_COALESCING)) { 199 return new Boolean (true); 200 } else if (name.equals(ENTITIES)) { 201 return _entities; 202 } else { 203 throw new IllegalArgumentException ("Property: " + name 204 + " not supported"); 205 } 206 } 207 208 public boolean isPropertySupported(String name) { 210 return name.equals(IS_COALESCING) || 211 name.equals(ENTITIES); 212 } 213 214 private XMLStreamReaderImpl newReader() { 215 XMLStreamReaderImpl xmlReader 216 = (XMLStreamReaderImpl) XML_READER_FACTORY.object(); 217 if (_entities != null) { 218 xmlReader.setEntities(_entities); 219 } 220 xmlReader._objectFactory = XML_READER_FACTORY; 221 return xmlReader; 222 } 223 } 224 225 private static ObjectFactory XML_READER_FACTORY = new ObjectFactory() { 226 227 protected Object create() { 228 return new XMLStreamReaderImpl(); 229 } 230 231 protected void cleanup(Object obj) { 232 ((XMLStreamReaderImpl) obj).reset(); 233 } 234 }; 235 236 } | Popular Tags |