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 FactoryFinder.find(XMLOutputFactory.class, DEFAULIMPL); 130 } 131 132 /** 133 * Create a new instance of the factory. 134 * <p> 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 * </p> 139 * <ul> 140 * <li> 141 * Use the javax.xml.stream.XMLOutputFactory system property. 142 * </li> 143 * <li> 144 * Use the properties file "lib/stax.properties" in the JRE directory. 145 * This configuration file is in standard java.util.Properties format 146 * and contains the fully qualified name of the implementation class 147 * with the key being the system property defined above. 148 * </li> 149 * <li> 150 * Use the service-provider loading facilities, defined by the 151 * {@link java.util.ServiceLoader} class, to attempt to locate and load an 152 * implementation of the service. 153 * </li> 154 * <li> 155 * Otherwise, the system-default implementation is returned. 156 * </li> 157 * <p> 158 * Once an application has obtained a reference to a XMLOutputFactory it 159 * can use the factory to configure and obtain stream instances. 160 * </p> 161 * <p> 162 * Note that this is a new method that replaces the deprecated newInstance() method. 163 * No changes in behavior are defined by this replacement method relative to the 164 * deprecated method. 165 * </p> 166 * @throws FactoryConfigurationError in case of {@linkplain 167 * java.util.ServiceConfigurationError service configuration error} or if 168 * the implementation is not available or cannot be instantiated. 169 */ 170 public static XMLOutputFactory newFactory() 171 throws FactoryConfigurationError 172 { 173 return FactoryFinder.find(XMLOutputFactory.class, DEFAULIMPL); 174 } 175 176 /** 177 * Create a new instance of the factory. 178 * 179 * @param factoryId Name of the factory to find, same as 180 * a property name 181 * @param classLoader classLoader to use 182 * @return the factory implementation 183 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded 184 * 185 * @deprecated This method has been deprecated because it returns an 186 * instance of XMLInputFactory, which is of the wrong class. 187 * Use the new method {@link #newFactory(java.lang.String, 188 * java.lang.ClassLoader)} instead. 189 */ 190 public static XMLInputFactory newInstance(String factoryId, 191 ClassLoader classLoader) 192 throws FactoryConfigurationError { 193 //do not fallback if given classloader can't find the class, throw exception 194 return FactoryFinder.find(XMLInputFactory.class, factoryId, classLoader, null); 195 } 196 197 /** 198 * Create a new instance of the factory. 199 * If the classLoader argument is null, then the ContextClassLoader is used. 200 * 201 * Note that this is a new method that replaces the deprecated 202 * newInstance(String factoryId, ClassLoader classLoader) method. 203 * 204 * No changes in behavior are defined by this replacement method relative 205 * to the deprecated method. 206 * 207 * 208 * @param factoryId Name of the factory to find, same as 209 * a property name 210 * @param classLoader classLoader to use 211 * @return the factory implementation 212 * @throws FactoryConfigurationError if an instance of this factory cannot be loaded 213 */ 214 public static XMLOutputFactory newFactory(String factoryId, 215 ClassLoader classLoader) 216 throws FactoryConfigurationError { 217 //do not fallback if given classloader can't find the class, throw exception 218 return FactoryFinder.find(XMLOutputFactory.class, factoryId, classLoader, null); 219 } 220 221 /** 222 * Create a new XMLStreamWriter that writes to a writer 223 * @param stream the writer to write to 224 * @throws XMLStreamException 225 */ 226 public abstract XMLStreamWriter createXMLStreamWriter(java.io.Writer stream) throws XMLStreamException; 227 228 /** 229 * Create a new XMLStreamWriter that writes to a stream 230 * @param stream the stream to write to 231 * @throws XMLStreamException 232 */ 233 public abstract XMLStreamWriter createXMLStreamWriter(java.io.OutputStream stream) throws XMLStreamException; 234 235 /** 236 * Create a new XMLStreamWriter that writes to a stream 237 * @param stream the stream to write to 238 * @param encoding the encoding to use |