Source Code Cross Referenced for MessageFactory.java in  » 6.0-JDK-Core » xml » javax » xml » soap » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » xml » javax.xml.soap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * $Id: MessageFactory.java,v 1.9 2004/04/02 01:24:17 ofung Exp $
003         * $Revision: 1.9 $
004         * $Date: 2004/04/02 01:24:17 $
005         */
006
007        /*
008         * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
009         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
010         *
011         * This code is free software; you can redistribute it and/or modify it
012         * under the terms of the GNU General Public License version 2 only, as
013         * published by the Free Software Foundation.  Sun designates this
014         * particular file as subject to the "Classpath" exception as provided
015         * by Sun in the LICENSE file that accompanied this code.
016         *
017         * This code is distributed in the hope that it will be useful, but WITHOUT
018         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
019         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
020         * version 2 for more details (a copy is included in the LICENSE file that
021         * accompanied this code).
022         *
023         * You should have received a copy of the GNU General Public License version
024         * 2 along with this work; if not, write to the Free Software Foundation,
025         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
026         *
027         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
028         * CA 95054 USA or visit www.sun.com if you need additional information or
029         * have any questions.
030         */
031        package javax.xml.soap;
032
033        import java.io.IOException;
034        import java.io.InputStream;
035
036        /**
037         * A factory for creating <code>SOAPMessage</code> objects.
038         * <P>
039         * A SAAJ client can create a <code>MessageFactory</code> object
040         * using the method <code>newInstance</code>, as shown in the following
041         * lines of code.
042         * <PRE>
043         *       MessageFactory mf = MessageFactory.newInstance();
044         *       MessageFactory mf12 = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
045         * </PRE>
046         * <P>
047         * All <code>MessageFactory</code> objects, regardless of how they are
048         * created, will produce <code>SOAPMessage</code> objects that
049         * have the following elements by default:
050         * <UL>
051         *  <LI>A <code>SOAPPart</code> object
052         *  <LI>A <code>SOAPEnvelope</code> object
053         *  <LI>A <code>SOAPBody</code> object
054         *  <LI>A <code>SOAPHeader</code> object
055         * </UL>
056         * In some cases, specialized MessageFactory objects may be obtained that produce messages 
057         * prepopulated with additional entries in the <code>SOAPHeader</code> object and the  
058         * <code>SOAPBody</code> object. 
059         * The content of a new <code>SOAPMessage</code> object depends on which of the two
060         * <code>MessageFactory</code> methods is used to create it.
061         * <UL>
062         *  <LI><code>createMessage()</code> <BR>
063         *      This is the method clients would normally use to create a request message.
064         *  <LI><code>createMessage(MimeHeaders, java.io.InputStream)</code> -- message has
065         *       content from the <code>InputStream</code> object and headers from the
066         *       <code>MimeHeaders</code> object <BR>
067         *        This method can be used internally by a service implementation to
068         *        create a message that is a response to a request.
069         * </UL>
070         */
071        public abstract class MessageFactory {
072
073            static private final String DEFAULT_MESSAGE_FACTORY = "com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl";
074
075            static private final String MESSAGE_FACTORY_PROPERTY = "javax.xml.soap.MessageFactory";
076
077            /**
078             * Creates a new <code>MessageFactory</code> object that is an instance
079             * of the default implementation (SOAP 1.1),
080             *
081             * This method uses the following ordered lookup procedure to determine the MessageFactory implementation class to load:
082             * <UL>
083             *  <LI> Use the javax.xml.soap.MessageFactory system property.
084             *  <LI> Use the properties file "lib/jaxm.properties" in the JRE directory. This configuration file is in standard
085             * java.util.Properties format and contains the fully qualified name of the implementation class with the key being the
086             * system property defined above.
087             *  <LI> Use the Services API (as detailed in the JAR specification), if available, to determine the classname. The Services API
088             * will look for a classname in the file META-INF/services/javax.xml.soap.MessageFactory in jars available to the runtime.
089             *  <LI> Use the SAAJMetaFactory instance to locate the MessageFactory implementation class.
090             * </UL>
091
092             *
093             * @return a new instance of a <code>MessageFactory</code>
094             *
095             * @exception SOAPException if there was an error in creating the
096             *            default implementation of the
097             *            <code>MessageFactory</code>.
098             * @see SAAJMetaFactory
099             */
100
101            public static MessageFactory newInstance() throws SOAPException {
102                try {
103                    MessageFactory factory = (MessageFactory) FactoryFinder
104                            .find(MESSAGE_FACTORY_PROPERTY);
105
106                    if (factory != null)
107                        return factory;
108
109                    return newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
110                } catch (Exception ex) {
111                    throw new SOAPException(
112                            "Unable to create message factory for SOAP: "
113                                    + ex.getMessage());
114                }
115
116            }
117
118            /**
119             * Creates a new <code>MessageFactory</code> object that is an instance
120             * of the specified implementation.  May be a dynamic message factory,
121             * a SOAP 1.1 message factory, or a SOAP 1.2 message factory. A dynamic
122             * message factory creates messages based on the MIME headers specified
123             * as arguments to the <code>createMessage</code> method.
124             *
125             * This method uses the SAAJMetaFactory to locate the implementation class 
126             * and create the MessageFactory instance.
127             * 
128             * @return a new instance of a <code>MessageFactory</code>
129             *
130             * @param protocol  a string constant representing the class of the
131             *                   specified message factory implementation. May be
132             *                   either <code>DYNAMIC_SOAP_PROTOCOL</code>,
133             *                   <code>DEFAULT_SOAP_PROTOCOL</code> (which is the same
134             *                   as) <code>SOAP_1_1_PROTOCOL</code>, or
135             *                   <code>SOAP_1_2_PROTOCOL</code>.
136             *
137             * @exception SOAPException if there was an error in creating the
138             *            specified implementation of  <code>MessageFactory</code>.
139             * @see SAAJMetaFactory
140             * @since SAAJ 1.3
141             */
142            public static MessageFactory newInstance(String protocol)
143                    throws SOAPException {
144                return SAAJMetaFactory.getInstance()
145                        .newMessageFactory(protocol);
146            }
147
148            /**
149             * Creates a new <code>SOAPMessage</code> object with the default
150             * <code>SOAPPart</code>, <code>SOAPEnvelope</code>, <code>SOAPBody</code>,
151             * and <code>SOAPHeader</code> objects. Profile-specific message factories
152             * can choose to prepopulate the <code>SOAPMessage</code> object with
153             * profile-specific headers.
154             * <P>
155             * Content can be added to this message's <code>SOAPPart</code> object, and
156             * the message can be sent "as is" when a message containing only a SOAP part
157             * is sufficient. Otherwise, the <code>SOAPMessage</code> object needs
158             * to create one or more <code>AttachmentPart</code> objects and
159             * add them to itself. Any content that is not in XML format must be
160             * in an <code>AttachmentPart</code> object.
161             *
162             * @return a new <code>SOAPMessage</code> object
163             * @exception SOAPException if a SOAP error occurs
164             * @exception UnsupportedOperationException if the protocol of this
165             *      <code>MessageFactory</code> instance is <code>DYNAMIC_SOAP_PROTOCOL</code> 
166             */
167            public abstract SOAPMessage createMessage() throws SOAPException;
168
169            /**
170             * Internalizes the contents of the given <code>InputStream</code> object into a
171             * new <code>SOAPMessage</code> object and returns the <code>SOAPMessage</code>
172             * object.
173             *
174             * @param in the <code>InputStream</code> object that contains the data
175             *           for a message
176             * @param headers the transport-specific headers passed to the
177             *        message in a transport-independent fashion for creation of the
178             *        message
179             * @return a new <code>SOAPMessage</code> object containing the data from
180             *         the given <code>InputStream</code> object
181             *
182             * @exception IOException if there is a problem in reading data from
183             *            the input stream
184             *
185             * @exception SOAPException may be thrown if the message is invalid
186             * 
187             * @exception IllegalArgumentException if the <code>MessageFactory</code>
188             *      requires one or more MIME headers to be present in the 
189             *      <code>headers</code> parameter and they are missing. 
190             *      <code>MessageFactory</code> implementations for
191             *      <code>SOAP_1_1_PROTOCOL</code> or 
192             *      <code>SOAP_1_2_PROTOCOL</code> must not throw 
193             *      <code>IllegalArgumentException</code> for this reason.   
194             */
195            public abstract SOAPMessage createMessage(MimeHeaders headers,
196                    InputStream in) throws IOException, SOAPException;
197        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.