Discussion:
odd reflective stuff
WJCarpenter
2005-08-06 01:26:24 UTC
Permalink
I happened across this stuff in org.apache.soap.encoding.SOAPMappingRegistry.
Those Class.forName() calls struck me as a little odd. It's mainly
curiosity, but I wonder why those things were instantiated
reflectively instead of just via new like so many other serializers in
that same source file.


try {
Class XMISerializer =
Class.forName("org.apache.soap.util.xml.XMISerializer");
Class XMIParameterSerializer =
Class.forName("org.apache.soap.encoding.xmi.XMIParameterSerializer");

// Register default serializers for XMI encoding style.
mapTypes(Constants.NS_URI_XMI_ENC, null, null,
(Serializer)XMISerializer.newInstance(),
(Deserializer)XMIParameterSerializer.newInstance());

// Register serializer for Parameter class - not deserializer!
mapTypes(Constants.NS_URI_XMI_ENC, null, Parameter.class,
(Serializer)XMIParameterSerializer.newInstance(), null);
} catch (IllegalAccessException iae) {
} catch (InstantiationException ie) {
} catch (ClassNotFoundException cnfe) {
} catch (NoClassDefFoundError ncdfe) {
// If the class can't be loaded, continue without it...
}
--
bill-***@carpenter.ORG (WJCarpenter) PGP 0x91865119
38 95 1B 69 C9 C6 3D 25 73 46 32 04 69 D6 ED F3
Scott Nichol
2005-08-06 04:34:18 UTC
Permalink
The following is my assumption. I was not a developer on Apache SOAP when the code was written.

The XMI serializers depend on an XMI jar from IBM. The ant build file allows Apache SOAP to be built without that jar, but Apache SOAP will then not have the XMI serializer classes as part of it. This code is a way to handle the absence of those classes at run time when using a version of Apache SOAP built that way.

Scott Nichol

Do not send e-mail directly to this e-mail address,
because it is filtered to accept only mail from
specific mail lists.
----- Original Message -----
From: "WJCarpenter" <bill-***@carpenter.ORG>
To: "soap-dev" <soap-***@ws.apache.org>
Sent: Friday, August 05, 2005 9:26 PM
Subject: odd reflective stuff
Post by WJCarpenter
I happened across this stuff in org.apache.soap.encoding.SOAPMappingRegistry.
Those Class.forName() calls struck me as a little odd. It's mainly
curiosity, but I wonder why those things were instantiated
reflectively instead of just via new like so many other serializers in
that same source file.
try {
Class XMISerializer =
Class.forName("org.apache.soap.util.xml.XMISerializer");
Class XMIParameterSerializer =
Class.forName("org.apache.soap.encoding.xmi.XMIParameterSerializer");
// Register default serializers for XMI encoding style.
mapTypes(Constants.NS_URI_XMI_ENC, null, null,
(Serializer)XMISerializer.newInstance(),
(Deserializer)XMIParameterSerializer.newInstance());
// Register serializer for Parameter class - not deserializer!
mapTypes(Constants.NS_URI_XMI_ENC, null, Parameter.class,
(Serializer)XMIParameterSerializer.newInstance(), null);
} catch (IllegalAccessException iae) {
} catch (InstantiationException ie) {
} catch (ClassNotFoundException cnfe) {
} catch (NoClassDefFoundError ncdfe) {
// If the class can't be loaded, continue without it...
}
--
38 95 1B 69 C9 C6 3D 25 73 46 32 04 69 D6 ED F3
WJCarpenter
2005-08-06 04:37:31 UTC
Permalink
Post by Scott Nichol
The XMI serializers depend on an XMI jar from IBM. The ant build file allows Apache SOAP to
be built without that jar, but Apache SOAP will then not have the XMI serializer classes as
part of it. This code is a way to handle the absence of those classes at run time when using
a version of Apache SOAP built that way.
Thanks. That makes sense. I wasn't thinking about the conditional builds, and both those
classes are present in my (standard) Apache SOAP build. I guess they would fail at runtime
without the IBM JAR on the classpath (didn't try that).
Sanjiva Weerawarana
2005-08-06 06:40:45 UTC
Permalink
Post by WJCarpenter
I happened across this stuff in org.apache.soap.encoding.SOAPMappingRegistry.
Those Class.forName() calls struck me as a little odd. It's mainly
curiosity, but I wonder why those things were instantiated
reflectively instead of just via new like so many other serializers in
that same source file.
Hi Bill - it was done to avoid having to require users to have the XMI
jars in the classpath. This way if it failed a ClassNotFoundException
would be thrown and none of the code will execute. Users who don't care
about XMI won't know the difference.

Sanjiva.

Loading...