1 57 58 59 package org.enhydra.apache.xml.serialize; 60 61 62 import java.io.OutputStream ; 63 import java.io.UnsupportedEncodingException ; 64 import java.io.Writer ; 65 import java.util.Hashtable ; 66 import java.util.StringTokenizer ; 67 68 69 76 public abstract class SerializerFactory 77 { 78 79 80 public static final String FactoriesProperty = "org.enhydra.apache.xml.serialize.factories"; 81 82 83 private static Hashtable _factories = new Hashtable (); 84 85 86 static 87 { 88 SerializerFactory factory; 89 String list; 90 StringTokenizer token; 91 String className; 92 93 factory = new SerializerFactoryImpl( Method.XML ); 97 registerSerializerFactory( factory ); 98 factory = new SerializerFactoryImpl( Method.HTML ); 99 registerSerializerFactory( factory ); 100 factory = new SerializerFactoryImpl( Method.XHTML ); 101 registerSerializerFactory( factory ); 102 factory = new SerializerFactoryImpl( Method.TEXT ); 103 registerSerializerFactory( factory ); 104 105 list = System.getProperty( FactoriesProperty ); 106 if ( list != null ) { 107 token = new StringTokenizer ( list, " ;,:" ); 108 while ( token.hasMoreTokens() ) { 109 className = token.nextToken(); 110 try { 111 factory = (SerializerFactory) Class.forName( className ).newInstance(); 112 if ( _factories.containsKey( factory.getSupportedMethod() ) ) 113 _factories.put( factory.getSupportedMethod(), factory ); 114 } catch ( Exception except ) { } 115 } 116 } 117 } 118 119 120 124 public static void registerSerializerFactory( SerializerFactory factory ) 125 { 126 String method; 127 128 synchronized ( _factories ) { 129 method = factory.getSupportedMethod(); 130 _factories.put( method, factory ); 131 } 132 } 133 134 135 139 public static SerializerFactory getSerializerFactory( String method ) 140 { 141 return (SerializerFactory) _factories.get( method ); 142 } 143 144 145 152 protected abstract String getSupportedMethod(); 153 154 155 161 public abstract Serializer makeSerializer(OutputFormat format); 162 163 164 169 public abstract Serializer makeSerializer( Writer writer, 170 OutputFormat format ); 171 172 173 181 public abstract Serializer makeSerializer( OutputStream output, 182 OutputFormat format ) 183 throws UnsupportedEncodingException ; 184 185 186 } 187 188 189 | Popular Tags |