XMLEncoderFactorypublic class XMLEncoderFactory extends Object
Fields Summary |
---|
protected static Log | log | public static final String | ENCODING_UTF_8 | public static final String | ENCODING_UTF_16 | public static final String | DEFAULT_ENCODING | private static Map | encoderMap | private static final String | PLUGABLE_PROVIDER_FILENAME |
Methods Summary |
---|
public static XMLEncoder | getDefaultEncoder()Returns the default encoder
encoderMap.put(ENCODING_UTF_8, new UTF8Encoder());
encoderMap.put(ENCODING_UTF_16, new UTF16Encoder());
encoderMap.put(ENCODING_UTF_8.toLowerCase(), new UTF8Encoder());
encoderMap.put(ENCODING_UTF_16.toLowerCase(), new UTF16Encoder());
try {
loadPluggableEncoders();
} catch (Throwable t){
String msg=t + JavaUtils.LS + JavaUtils.stackToString(t);
log.info(Messages.getMessage("exception01",msg));
}
try {
return getEncoder(DEFAULT_ENCODING);
} catch (UnsupportedEncodingException e) {
// as far I know J++ VMs will throw this exception
throw new IllegalStateException(Messages.getMessage("unsupportedDefaultEncoding00", DEFAULT_ENCODING));
}
| public static XMLEncoder | getEncoder(java.lang.String encoding)Returns the requested encoder
XMLEncoder encoder = (XMLEncoder) encoderMap.get(encoding);
if (encoder == null) {
encoder = new DefaultXMLEncoder(encoding);
encoderMap.put(encoding, encoder);
}
return encoder;
| private static void | loadPluggableEncoders()Look for file META-INF/services/org.apache.axis.components.encoding.XMLEncoder
in all the JARS, get the classes listed in those files and add them to
encoders list if they are valid encoders.
Here is how the scheme would work.
A company providing a new encoder will jar up their encoder related
classes in a JAR file. The following file containing the name of the new
encoder class is also made part of this JAR file.
META-INF/services/org.apache.axis.components.encoding.XMLEncoder
By making this JAR part of the webapp, the new encoder will be
automatically discovered.
ClassLoader clzLoader = XMLEncoder.class.getClassLoader();
ClassLoaders loaders = new ClassLoaders();
loaders.put(clzLoader);
DiscoverServiceNames dsn = new DiscoverServiceNames(loaders);
ResourceNameIterator iter = dsn.findResourceNames(PLUGABLE_PROVIDER_FILENAME);
while (iter.hasNext()) {
String className = iter.nextResourceName();
try {
Object o = Class.forName(className).newInstance();
if (o instanceof XMLEncoder) {
XMLEncoder encoder = (XMLEncoder) o;
encoderMap.put(encoder.getEncoding(), encoder);
encoderMap.put(encoder.getEncoding().toLowerCase(), encoder);
}
} catch (Exception e) {
String msg = e + JavaUtils.LS + JavaUtils.stackToString(e);
log.info(Messages.getMessage("exception01", msg));
continue;
}
}
|
|