109 * @since 1.6 110 */ 111 public abstract class XMLOutputFactory { 112 /** 113 * Property used to set prefix defaulting on the output side 114 */ 115 public static final String IS_REPAIRING_NAMESPACES= 116 "javax.xml.stream.isRepairingNamespaces"; 117 118 static final String DEFAULIMPL = "com.sun.xml.internal.stream.XMLOutputFactoryImpl"; 119 120 protected XMLOutputFactory(){} 121 122 /** 123 * Create a new instance of the factory. 124 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded 125 */ 126 public static XMLOutputFactory newInstance() 127 throws FactoryConfigurationError 128 { 129 return (XMLOutputFactory) FactoryFinder.find("javax.xml.stream.XMLOutputFactory", 130 DEFAULIMPL); 131 } 132 133 /** 134 * Create a new instance of the factory. 135 * This static method creates a new factory instance. This method uses the 136 * following ordered lookup procedure to determine the XMLOutputFactory 137 * implementation class to load: 138 * Use the javax.xml.stream.XMLOutputFactory system property. 139 * Use the properties file "lib/stax.properties" in the JRE directory. 140 * This configuration file is in standard java.util.Properties format 141 * and contains the fully qualified name of the implementation class 142 * with the key being the system property defined above. 143 * Use the Services API (as detailed in the JAR specification), if available, 144 * to determine the classname. The Services API will look for a classname 145 * in the file META-INF/services/javax.xml.stream.XMLOutputFactory in jars 146 * available to the runtime. 147 * Platform default XMLOutputFactory instance. 148 * 149 * Once an application has obtained a reference to a XMLOutputFactory it 150 * can use the factory to configure and obtain stream instances. 151 * 152 * Note that this is a new method that replaces the deprecated newInstance() method. 153 * No changes in behavior are defined by this replacement method relative to the 154 * deprecated method. 155 * 156 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded 157 */ 158 public static XMLOutputFactory newFactory() 159 throws FactoryConfigurationError 160 { 161 return (XMLOutputFactory) FactoryFinder.find("javax.xml.stream.XMLOutputFactory", 162 DEFAULIMPL); 163 } 164 165 /** 166 * Create a new instance of the factory. 167 * 168 * @param factoryId Name of the factory to find, same as 169 * a property name 170 * @param classLoader classLoader to use 171 * @return the factory implementation 172 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded 173 * 174 * @deprecated This method has been deprecated because it returns an 175 * instance of XMLInputFactory, which is of the wrong class. 176 * Use the new method {@link #newFactory(java.lang.String, 177 * java.lang.ClassLoader)} instead. 178 */ 179 public static XMLInputFactory newInstance(String factoryId, 180 ClassLoader classLoader) 181 throws FactoryConfigurationError { 182 try { 183 //do not fallback if given classloader can't find the class, throw exception 184 return (XMLInputFactory) FactoryFinder.find(factoryId, classLoader, null); 185 } catch (FactoryFinder.ConfigurationError e) { 186 throw new FactoryConfigurationError(e.getException(), 187 e.getMessage()); 188 } 189 } 190 191 /** 192 * Create a new instance of the factory. 193 * If the classLoader argument is null, then the ContextClassLoader is used. 194 * 195 * Note that this is a new method that replaces the deprecated 196 * newInstance(String factoryId, ClassLoader classLoader) method. 197 * 198 * No changes in behavior are defined by this replacement method relative 199 * to the deprecated method. 200 * 201 * 202 * @param factoryId Name of the factory to find, same as 203 * a property name 204 * @param classLoader classLoader to use 205 * @return the factory implementation 206 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded 207 */ 208 public static XMLOutputFactory newFactory(String factoryId, 209 ClassLoader classLoader) 210 throws FactoryConfigurationError { 211 try { 212 //do not fallback if given classloader can't find the class, throw exception 213 return (XMLOutputFactory) FactoryFinder.find(factoryId, classLoader, null); 214 } catch (FactoryFinder.ConfigurationError e) { 215 throw new FactoryConfigurationError(e.getException(), 216 e.getMessage()); 217 } 218 } 219 220 /** 221 * Create a new XMLStreamWriter that writes to a writer 222 * @param stream the writer to write to 223 * @throws XMLStreamException 224 */ 225 public abstract XMLStreamWriter createXMLStreamWriter(java.io.Writer stream) throws XMLStreamException; 226 227 /** 228 * Create a new XMLStreamWriter that writes to a stream 229 * @param stream the stream to write to 230 * @throws XMLStreamException 231 */ 232 public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream) throws XMLStreamException; 233 234 /** 235 * Create a new XMLStreamWriter that writes to a stream 236 * @param stream the stream to write to 237 * @param encoding the encoding to use | 109 * @since 1.6 110 */ 111 public abstract class XMLOutputFactory { 112 /** 113 * Property used to set prefix defaulting on the output side 114 */ 115 public static final String IS_REPAIRING_NAMESPACES= 116 "javax.xml.stream.isRepairingNamespaces"; 117 118 static final String DEFAULIMPL = "com.sun.xml.internal.stream.XMLOutputFactoryImpl"; 119 120 protected XMLOutputFactory(){} 121 122 /** 123 * Create a new instance of the factory. 124 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded 125 */ 126 public static XMLOutputFactory newInstance() 127 throws FactoryConfigurationError 128 { 129 return (XMLOutputFactory) FactoryFinder.find(XMLOutputFactory.class, 130 "javax.xml.stream.XMLOutputFactory", 131 DEFAULIMPL); 132 } 133 134 /** 135 * <p>Create a new instance of the factory. 136 * </p><p> 137 * This static method creates a new factory instance. This method uses the 138 * following ordered lookup procedure to determine the XMLOutputFactory 139 * implementation class to load: 140 * <ul> 141 * <li> 142 * Use the javax.xml.stream.XMLOutputFactory system property. 143 * </li> 144 * <li> 145 * Use the properties file "lib/stax.properties" in the JRE directory. 146 * This configuration file is in standard java.util.Properties format 147 * and contains the fully qualified name of the implementation class 148 * with the key being the system property defined above. 149 * </li> 150 * <li> 151 * <p>Uses the service-provider loading facilities, defined by the {@link java.util.ServiceLoader} class, to attempt 152 * to locate and load an implementation of the service. In case of multiple providers, the first non-default implementation 153 * shall be instantiated and returned. The default implementation is returned if it is the only one 154 * found by the service loader.</p> 155 * <p> 156 * If a misconfigured provider is encountered and {@link java.util.ServiceConfigurationError} is thrown, the error will be wrapped 157 * in a {@link javax.xml.stream.FactoryConfigurationError}.</p> 158 * </li> 159 * <li> 160 * Platform default XMLOutputFactory instance. 161 * </li> 162 * </ul> 163 * 164 * Once an application has obtained a reference to a XMLOutputFactory it 165 * can use the factory to configure and obtain stream instances. 166 *</p><p> 167 * Note that this is a new method that replaces the deprecated newInstance() method. 168 * No changes in behavior are defined by this replacement method relative to the 169 * deprecated method. 170 *</p> 171 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded 172 */ 173 public static XMLOutputFactory newFactory() 174 throws FactoryConfigurationError 175 { 176 return (XMLOutputFactory) FactoryFinder.find(XMLOutputFactory.class, 177 "javax.xml.stream.XMLOutputFactory", 178 DEFAULIMPL); 179 } 180 181 /** 182 * Create a new instance of the factory. 183 * 184 * @param factoryId Name of the factory to find, same as 185 * a property name 186 * @param classLoader classLoader to use 187 * @return the factory implementation 188 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded 189 * 190 * @deprecated This method has been deprecated because it returns an 191 * instance of XMLInputFactory, which is of the wrong class. 192 * Use the new method {@link #newFactory(java.lang.String, 193 * java.lang.ClassLoader)} instead. 194 */ 195 public static XMLInputFactory newInstance(String factoryId, 196 ClassLoader classLoader) 197 throws FactoryConfigurationError { 198 //do not fallback if given classloader can't find the class, throw exception 199 return (XMLInputFactory) FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null); 200 } 201 202 /** 203 * Create a new instance of the factory. 204 * If the classLoader argument is null, then the ContextClassLoader is used. 205 * 206 * Note that this is a new method that replaces the deprecated 207 * newInstance(String factoryId, ClassLoader classLoader) method. 208 * 209 * No changes in behavior are defined by this replacement method relative 210 * to the deprecated method. 211 * 212 * 213 * @param factoryId Name of the factory to find, same as 214 * a property name 215 * @param classLoader classLoader to use 216 * @return the factory implementation 217 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded 218 */ 219 public static XMLOutputFactory newFactory(String factoryId, 220 ClassLoader classLoader) 221 throws FactoryConfigurationError { 222 //do not fallback if given classloader can't find the class, throw exception 223 return (XMLOutputFactory) FactoryFinder.find(XMLOutputFactory.class, factoryId, classLoader, null); 224 } 225 226 /** 227 * Create a new XMLStreamWriter that writes to a writer 228 * @param stream the writer to write to 229 * @throws XMLStreamException 230 */ 231 public abstract XMLStreamWriter createXMLStreamWriter(java.io.Writer stream) throws XMLStreamException; 232 233 /** 234 * Create a new XMLStreamWriter that writes to a stream 235 * @param stream the stream to write to 236 * @throws XMLStreamException 237 */ 238 public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream) throws XMLStreamException; 239 240 /** 241 * Create a new XMLStreamWriter that writes to a stream 242 * @param stream the stream to write to 243 * @param encoding the encoding to use |