1 16 17 18 package org.apache.xml.serialize; 19 20 21 import java.io.OutputStream ; 22 import java.io.Writer ; 23 import java.io.UnsupportedEncodingException ; 24 import java.util.Hashtable ; 25 import java.util.StringTokenizer ; 26 27 34 public abstract class SerializerFactory 35 { 36 37 38 public static final String FactoriesProperty = "org.apache.xml.serialize.factories"; 39 40 41 private static Hashtable _factories = new Hashtable (); 42 43 44 static 45 { 46 SerializerFactory factory; 47 String list; 48 StringTokenizer token; 49 String className; 50 51 factory = new SerializerFactoryImpl( Method.XML ); 55 registerSerializerFactory( factory ); 56 factory = new SerializerFactoryImpl( Method.HTML ); 57 registerSerializerFactory( factory ); 58 factory = new SerializerFactoryImpl( Method.XHTML ); 59 registerSerializerFactory( factory ); 60 factory = new SerializerFactoryImpl( Method.TEXT ); 61 registerSerializerFactory( factory ); 62 63 list = System.getProperty( FactoriesProperty ); 64 if ( list != null ) { 65 token = new StringTokenizer ( list, " ;,:" ); 66 while ( token.hasMoreTokens() ) { 67 className = token.nextToken(); 68 try { 69 factory = (SerializerFactory) ObjectFactory.newInstance( className, 70 SerializerFactory.class.getClassLoader(), true); 71 if ( _factories.containsKey( factory.getSupportedMethod() ) ) 72 _factories.put( factory.getSupportedMethod(), factory ); 73 } catch ( Exception except ) { } 74 } 75 } 76 } 77 78 79 83 public static void registerSerializerFactory( SerializerFactory factory ) 84 { 85 String method; 86 87 synchronized ( _factories ) { 88 method = factory.getSupportedMethod(); 89 _factories.put( method, factory ); 90 } 91 } 92 93 94 98 public static SerializerFactory getSerializerFactory( String method ) 99 { 100 return (SerializerFactory) _factories.get( method ); 101 } 102 103 104 111 protected abstract String getSupportedMethod(); 112 113 114 120 public abstract Serializer makeSerializer(OutputFormat format); 121 122 123 128 public abstract Serializer makeSerializer( Writer writer, 129 OutputFormat format ); 130 131 132 140 public abstract Serializer makeSerializer( OutputStream output, 141 OutputFormat format ) 142 throws UnsupportedEncodingException ; 143 144 145 } 146 147 148 | Popular Tags |