001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package javax.xml.stream;
031:
032: import javax.xml.transform.Result;
033: import java.util.WeakHashMap;
034: import java.io.OutputStream;
035: import java.io.Writer;
036:
037: public abstract class XMLOutputFactory {
038: public static final String IS_REPAIRING_NAMESPACES = "javax.xml.stream.isRepairingNamespaces";
039:
040: private static final WeakHashMap<ClassLoader, Class> _factoryMap = new WeakHashMap<ClassLoader, Class>();
041:
042: protected XMLOutputFactory() {
043: }
044:
045: public abstract XMLEventWriter createXMLEventWriter(
046: OutputStream stream) throws XMLStreamException;
047:
048: public abstract XMLEventWriter createXMLEventWriter(
049: OutputStream stream, String encoding)
050: throws XMLStreamException;
051:
052: public abstract XMLEventWriter createXMLEventWriter(Result result)
053: throws XMLStreamException;
054:
055: public abstract XMLEventWriter createXMLEventWriter(Writer stream)
056: throws XMLStreamException;
057:
058: public abstract XMLStreamWriter createXMLStreamWriter(
059: OutputStream stream) throws XMLStreamException;
060:
061: public abstract XMLStreamWriter createXMLStreamWriter(
062: OutputStream stream, String encoding)
063: throws XMLStreamException;
064:
065: public abstract XMLStreamWriter createXMLStreamWriter(Result result)
066: throws XMLStreamException;
067:
068: public abstract XMLStreamWriter createXMLStreamWriter(Writer stream)
069: throws XMLStreamException;
070:
071: public abstract Object getProperty(String name)
072: throws IllegalArgumentException;
073:
074: public abstract boolean isPropertySupported(String name);
075:
076: public static XMLOutputFactory newInstance()
077: throws FactoryConfigurationError {
078: return newInstance("javax.xml.stream.XMLOutputFactory", Thread
079: .currentThread().getContextClassLoader());
080: }
081:
082: public static XMLOutputFactory newInstance(String factoryId,
083: ClassLoader classLoader) throws FactoryConfigurationError {
084: Class cl = _factoryMap.get(classLoader);
085:
086: if (cl == null) {
087: cl = FactoryLoader.getFactoryLoader(factoryId).newClass(
088: classLoader);
089:
090: if (cl != null)
091: _factoryMap.put(classLoader, cl);
092: }
093:
094: if (cl == null)
095: throw new FactoryConfigurationError();
096:
097: try {
098: return (XMLOutputFactory) cl.newInstance();
099: } catch (FactoryConfigurationError e) {
100: throw e;
101: } catch (RuntimeException e) {
102: throw e;
103: } catch (Exception e) {
104: throw new FactoryConfigurationError(e);
105: }
106: }
107:
108: public abstract void setProperty(String name, Object value)
109: throws IllegalArgumentException;
110:
111: }
|