001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License. You may obtain a copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied. See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    package javax.xml.soap;
020    
021    /**
022     * A factory for creating <code>SOAPConnection</code> objects. Implementation of this class is
023     * optional. If <code>SOAPConnectionFactory.newInstance()</code> throws an
024     * <code>UnsupportedOperationException</code> then the implementation does not support the SAAJ
025     * communication infrastructure. Otherwise <code>SOAPConnection</code> objects can be created by
026     * calling <code>createConnection()</code> on the newly created <code>SOAPConnectionFactory</code>
027     * object.
028     */
029    public abstract class SOAPConnectionFactory {
030    
031        public SOAPConnectionFactory() {
032        }
033    
034        /**
035         * Creates an instance of the default <CODE> SOAPConnectionFactory</CODE> object.
036         *
037         * @return a new instance of a default <CODE> SOAPConnectionFactory</CODE> object
038         * @throws SOAPException                 if there was an error creating the <CODE>SOAPConnectionFactory
039         * @throws UnsupportedOperationException if newInstance is not supported.
040         */
041        public static SOAPConnectionFactory newInstance()
042                throws SOAPException, UnsupportedOperationException {
043    
044            try {
045                return (SOAPConnectionFactory)FactoryFinder.find(SF_PROPERTY,
046                                                                 DEFAULT_SOAP_CONNECTION_FACTORY);
047            } catch (Exception exception) {
048                throw new SOAPException("Unable to create SOAP connection factory: "
049                        + exception.getMessage());
050            }
051        }
052    
053        /**
054         * Create a new <CODE>SOAPConnection</CODE>.
055         *
056         * @return the new <CODE>SOAPConnection</CODE> object.
057         * @throws SOAPException if there was an exception creating the <CODE>SOAPConnection</CODE>
058         *                       object.
059         */
060        public abstract SOAPConnection createConnection() throws SOAPException;
061    
062        private static final String DEFAULT_SOAP_CONNECTION_FACTORY =
063                "org.apache.axis2.saaj.SOAPConnectionFactoryImpl";
064    
065        private static final String SF_PROPERTY =
066                "javax.xml.soap.SOAPConnectionFactory";
067    }