Previous section   Next section
SOAPFactory javax.xml.soap

SAAJ 1.1; JWSDP 1.0, J2EE 1.4
public abstract class SOAPFactory {
// Public Constructors
    public SOAPFactory(  ); 
// Public Class Methods
    public static SOAPFactory newInstance(  ) throws SOAPException; 
// Public Instance Methods
    public abstract Detail createDetail(  ) throws SOAPException; 
    public abstract SOAPElement createElement(String localName) throws SOAPException; 
    public abstract SOAPElement createElement(Name name) throws SOAPException; 
    public abstract SOAPElement createElement(String localName, String prefix, 
        String uri) throws SOAPException; 
    public abstract Name createName(String localName) throws SOAPException; 
    public abstract Name createName(String localName, String prefix, 
        String uri) throws SOAPException; 
}

SOAPFactory is an abstract factory that can be used to create Detail, Name, and SOAPElement objects. Although all of these elements can be created using methods provided by various objects that are part of a SOAP message (such as SOAPEnvelope), it is often convenient to be able to construct message parts without having a reference to a SOAPMessage. In such cases, you should use the SOAPFactory class.

To get a reference to a SOAPFactory object, use the static newInstance( ) method, which uses an algorithm similar to that described for the SOAPConnectionFactory class to locate a concrete implementation. By default, the reference implementation returns an object of type com.sun.xml.messaging.saaj.soap.SOAPFactoryImpl.

The createElement( ) method that accepts a single argument of type String returns a SOAPElement whose local name is given by the argument, and that does not have a namespace qualifier. An element created in this way is qualified by the default namespace, which can be designated by adding a suitable namespace declaration to the element itself or to one of its ancestors. You can create an element with an explicit namespace by using the three-argument variant of createElement( ), which requires the namespace URI and the namespace prefix in addition to the local part of the element name. Here's a typical example of the usage of this method:

SOAPElement element = factory.createElement("BookTitle", "book", 
                                               "urn:BookService");

The serialized form of this element, when incorporated into a SOAP message, is book:BookTitle xmlns:book="urn:BookService".

The variant of createElement( ) that accepts an argument of type Name returns a SOAPElement, the name of which is taken from the local part of the supplied argument. The element may or may not be explicitly namespace-qualified, depending on whether the Name contains a namespace.

The createName( ) methods return instances of the Name interface that have a specified local part and an optional namespace URI and namespace prefix. Refer to the description of the Name interface in this chapter for a discussion of the use of Name objects and namespaces.

Returned By

SOAPFactory.newInstance( )


  Previous section   Next section