KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > soap > SOAPFactoryImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55 package org.jboss.axis.soap;
56
57 import org.jboss.axis.message.DetailImpl;
58 import org.jboss.axis.message.NameImpl;
59 import org.jboss.axis.message.SOAPElementAxisImpl;
60 import org.jboss.axis.utils.ClassUtils;
61
62 import javax.xml.soap.Detail JavaDoc;
63 import javax.xml.soap.Name JavaDoc;
64 import javax.xml.soap.SOAPElement JavaDoc;
65 import javax.xml.soap.SOAPException JavaDoc;
66 import java.lang.reflect.Constructor JavaDoc;
67 import java.lang.reflect.InvocationTargetException JavaDoc;
68
69 /**
70  * SOAP Element Factory implementation
71  * <p/>
72  * This factory reads the following system properties for the SOAP implementation class names
73  * <p/>
74  * javax.xml.soap.SOAPElement
75  * javax.xml.soap.Detail
76  * javax.xml.soap.Name
77  *
78  * @author Thomas Diesler (thomas.diesler@jboss.org)
79  */

80 public class SOAPFactoryImpl extends javax.xml.soap.SOAPFactory JavaDoc
81 {
82
83    private static Class JavaDoc elementClass;
84    private static Class JavaDoc detailClass;
85    private static Class JavaDoc nameClass;
86
87    static
88    {
89       try
90       {
91          String JavaDoc elementClass = System.getProperty(SOAPElement JavaDoc.class.getName(), SOAPElementAxisImpl.class.getName());
92          SOAPFactoryImpl.elementClass = ClassUtils.forName(elementClass);
93          String JavaDoc detailClass = System.getProperty(Detail JavaDoc.class.getName(), DetailImpl.class.getName());
94          SOAPFactoryImpl.detailClass = ClassUtils.forName(detailClass);
95          String JavaDoc nameClass = System.getProperty(Name JavaDoc.class.getName(), NameImpl.class.getName());
96          SOAPFactoryImpl.nameClass = ClassUtils.forName(nameClass);
97       }
98       catch (ClassNotFoundException JavaDoc e)
99       {
100          throw new IllegalArgumentException JavaDoc("SOAP implementation not found: " + e.getMessage());
101       }
102    }
103
104    /**
105     * Create a <CODE>SOAPElement</CODE> object initialized with
106     * the given <CODE>Name</CODE> object.
107     *
108     * @param name a <CODE>Name</CODE> object with
109     * the XML name for the new element
110     * @return the new <CODE>SOAPElement</CODE> object that was
111     * created
112     * @throws SOAPException if there is an error in
113     * creating the <CODE>SOAPElement</CODE> object
114     */

115    public SOAPElement JavaDoc createElement(Name JavaDoc name) throws SOAPException JavaDoc
116    {
117       try
118       {
119          Constructor JavaDoc ctor = elementClass.getConstructor(new Class JavaDoc[]{Name JavaDoc.class});
120          return (SOAPElement JavaDoc)ctor.newInstance(new Object JavaDoc[]{name});
121       }
122       catch (InvocationTargetException JavaDoc e)
123       {
124          Throwable JavaDoc te = e.getTargetException();
125          if (te instanceof SOAPException JavaDoc)
126             throw (SOAPException JavaDoc)te;
127          throw new SOAPException JavaDoc(e);
128       }
129       catch (Exception JavaDoc e)
130       {
131          throw new SOAPException JavaDoc(e);
132       }
133    }
134
135    /**
136     * Create a <CODE>SOAPElement</CODE> object initialized with
137     * the given local name.
138     *
139     * @param localName a <CODE>String</CODE> giving
140     * the local name for the new element
141     * @return the new <CODE>SOAPElement</CODE> object that was
142     * created
143     * @throws SOAPException if there is an error in
144     * creating the <CODE>SOAPElement</CODE> object
145     */

146    public SOAPElement JavaDoc createElement(String JavaDoc localName) throws SOAPException JavaDoc
147    {
148       try
149       {
150          Constructor JavaDoc ctor = elementClass.getConstructor(new Class JavaDoc[]{String JavaDoc.class});
151          return (SOAPElement JavaDoc)ctor.newInstance(new Object JavaDoc[]{localName});
152       }
153       catch (InvocationTargetException JavaDoc e)
154       {
155
156          Throwable JavaDoc te = e.getTargetException();
157          if (te instanceof SOAPException JavaDoc)
158             throw (SOAPException JavaDoc)te;
159
160          throw new SOAPException JavaDoc(te);
161       }
162       catch (Exception JavaDoc e)
163       {
164          throw new SOAPException JavaDoc(e);
165       }
166    }
167
168    /**
169     * Create a new <CODE>SOAPElement</CODE> object with the
170     * given local name, prefix and uri.
171     *
172     * @param localName a <CODE>String</CODE> giving
173     * the local name for the new element
174     * @param prefix the prefix for this <CODE>
175     * SOAPElement</CODE>
176     * @param uri a <CODE>String</CODE> giving the
177     * URI of the namespace to which the new element
178     * belongs
179     * @return the new <CODE>SOAPElement</CODE> object that was
180     * created
181     * @throws SOAPException if there is an error in
182     * creating the <CODE>SOAPElement</CODE> object
183     */

184    public SOAPElement JavaDoc createElement(String JavaDoc localName, String JavaDoc prefix, String JavaDoc uri) throws SOAPException JavaDoc
185    {
186       try
187       {
188          Constructor JavaDoc ctor = elementClass.getConstructor(new Class JavaDoc[]{String JavaDoc.class, String JavaDoc.class, String JavaDoc.class});
189          return (SOAPElement JavaDoc)ctor.newInstance(new Object JavaDoc[]{localName, prefix, uri});
190       }
191       catch (InvocationTargetException JavaDoc e)
192       {
193
194          Throwable JavaDoc te = e.getTargetException();
195          if (te instanceof SOAPException JavaDoc)
196             throw (SOAPException JavaDoc)te;
197
198          throw new SOAPException JavaDoc(e);
199       }
200       catch (Exception JavaDoc e)
201       {
202          throw new SOAPException JavaDoc(e);
203       }
204    }
205
206    public Detail JavaDoc createDetail() throws SOAPException JavaDoc
207    {
208       try
209       {
210          return (Detail JavaDoc)detailClass.newInstance();
211       }
212       catch (Exception JavaDoc e)
213       {
214          throw new SOAPException JavaDoc(e);
215       }
216    }
217
218    public Name JavaDoc createName(String JavaDoc localName, String JavaDoc prefix, String JavaDoc uri) throws SOAPException JavaDoc
219    {
220       try
221       {
222          Constructor JavaDoc ctor = nameClass.getConstructor(new Class JavaDoc[]{String JavaDoc.class, String JavaDoc.class, String JavaDoc.class});
223          return (Name JavaDoc)ctor.newInstance(new Object JavaDoc[]{localName, prefix, uri});
224       }
225       catch (InvocationTargetException JavaDoc e)
226       {
227
228          Throwable JavaDoc te = e.getTargetException();
229          if (te instanceof SOAPException JavaDoc)
230             throw (SOAPException JavaDoc)te;
231
232          throw new SOAPException JavaDoc(e);
233       }
234       catch (Exception JavaDoc e)
235       {
236          throw new SOAPException JavaDoc(e);
237       }
238    }
239
240    public Name JavaDoc createName(String JavaDoc localName) throws SOAPException JavaDoc
241    {
242       try
243       {
244          Constructor JavaDoc ctor = nameClass.getConstructor(new Class JavaDoc[]{String JavaDoc.class});
245          return (Name JavaDoc)ctor.newInstance(new Object JavaDoc[]{localName});
246       }
247       catch (InvocationTargetException JavaDoc e)
248       {
249
250          Throwable JavaDoc te = e.getTargetException();
251          if (te instanceof SOAPException JavaDoc)
252             throw (SOAPException JavaDoc)te;
253
254          throw new SOAPException JavaDoc(e);
255       }
256       catch (Exception JavaDoc e)
257       {
258          throw new SOAPException JavaDoc(e);
259       }
260    }
261 }
262
Popular Tags