JAX-RPC
also allows the use of a
javax.xml.soap.SOAPElement
object as a parameter
value for a remote method. This object is intended for when you want
to bypass an existing datatype mapping or when a mapping
doesn’t exist for the data you are using. You can
also use it if you just want to plug in the element by hand.
Regardless of the reasons, whatever you place in the
SOAPElement
parameter becomes the request
envelope’s body.
If you recall the JAXM section, we used the
SOAPElement
like this:
// Add an element and content to the Header name = envelope.createName("From"); javax.xml.soap.SOAPElement childElement = headerElement.addChildElement (name); childElement.addTextNode ("Me");
In this code, we create the element as a side effect of appending the
name to the headerElement
. A more direct way to
create an element uses the SOAPElementFactory
to
create an element and populate its contents. To create a
SOAPElementFactory
, call its static method
newInstance( )
:
javax.xml.soap.SOAPElementFactory sef = javax.xml.soap.SOAPElementFactory.newInstance( ); javax.xml.soap.SOAPElement sel = sef.createElement(...);
The interface for the SOAPElementFactory
is:
package javax.xml.soap; public abstract class SOAPElementFactory{ public abstract SOAPElement create(Name name) throws SOAPException; public abstract SOAPElement create(String localName) throws SOAPException; public abstract SOAPElement create(String localName, String prefix,String uri) throws SOAPException; public static SOAPElementFactory newInstance( ) throws SOAPException; }
The first public draft of the JAX-RPC specification identifies some
problems with this approach, which may mean that
it’s likely to change in a future draft. One problem
is that the Name
object is created using the
Envelope
object, which is not available to the
JAX-RPC programmer. “Not available”
means that nothing exposed in the JAX-RPC client interface lets you
peek at the envelope that will eventually be sent. The lack of a
factory for a Name
is not that big of an issue in
itself. The Name
interface contains a local name,
a namespace prefix, and a URI. An alternate method signature lets you
create the SOAPElement
with the desired result.
More significant issues are probably also behind this problem.