FileDocCategorySizeDatePackage
SerializerFactory.javaAPI DocJava SE 5 API6941Fri Aug 26 14:56:02 BST 2005com.sun.org.apache.xml.internal.serialize

SerializerFactory

public abstract class SerializerFactory extends Object
version
$Revision: 1.9 $ $Date: 2004/02/17 07:14:49 $
author
Scott Boag
author
Assaf Arkin

Fields Summary
public static final String
FactoriesProperty
private static Hashtable
_factories
Constructors Summary
Methods Summary
public static com.sun.org.apache.xml.internal.serialize.SerializerFactorygetSerializerFactory(java.lang.String method)
Register a serializer factory, keyed by the given method string.

        return (SerializerFactory) _factories.get( method );
    
protected abstract java.lang.StringgetSupportedMethod()
Returns the method supported by this factory and used to register the factory. This call is required so factories can be added from a properties file by knowing only the class name. This method is protected, it is only required by this class but must be implemented in derived classes.

public abstract com.sun.org.apache.xml.internal.serialize.SerializermakeSerializer(com.sun.org.apache.xml.internal.serialize.OutputFormat format)
Create a new serializer based on the {@link OutputFormat}. If this method is used to create the serializer, the {@link Serializer#setOutputByteStream} or {@link Serializer#setOutputCharStream} methods must be called before serializing a document.

public abstract com.sun.org.apache.xml.internal.serialize.SerializermakeSerializer(java.io.Writer writer, com.sun.org.apache.xml.internal.serialize.OutputFormat format)
Create a new serializer, based on the {@link OutputFormat} and using the writer as the output character stream. If this method is used, the encoding property will be ignored.

public abstract com.sun.org.apache.xml.internal.serialize.SerializermakeSerializer(java.io.OutputStream output, com.sun.org.apache.xml.internal.serialize.OutputFormat format)
Create a new serializer, based on the {@link OutputFormat} and using the output byte stream and the encoding specified in the output format.

throws
UnsupportedEncodingException The specified encoding is not supported

public static voidregisterSerializerFactory(com.sun.org.apache.xml.internal.serialize.SerializerFactory factory)
Register a serializer factory, keyed by the given method string.



    
    
        SerializerFactory factory;
        String            list;
        StringTokenizer   token;
        String            className;

        // The default factories are always registered first,
        // any factory specified in the properties file and supporting
        // the same method will override the default factory.
        factory =  new SerializerFactoryImpl( Method.XML );
        registerSerializerFactory( factory );
        factory =  new SerializerFactoryImpl( Method.HTML );
        registerSerializerFactory( factory );
        factory =  new SerializerFactoryImpl( Method.XHTML );
        registerSerializerFactory( factory );
        factory =  new SerializerFactoryImpl( Method.TEXT );
        registerSerializerFactory( factory );

        list = System.getProperty( FactoriesProperty );
        if ( list != null ) {
            token = new StringTokenizer( list, " ;,:" );
            while ( token.hasMoreTokens() ) {
                className = token.nextToken();
                try {
                    factory = (SerializerFactory) ObjectFactory.newInstance( className,
                        SerializerFactory.class.getClassLoader(), true);
                    if ( _factories.containsKey( factory.getSupportedMethod() ) )
                        _factories.put( factory.getSupportedMethod(), factory );
                } catch ( Exception except ) { }
            }
        }
    
        String method;

        synchronized ( _factories ) {
            method = factory.getSupportedMethod();
            _factories.put( method, factory );
        }