KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > soap > SoapMethod


1 /*
2  * $Id: SoapMethod.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.soap;
12
13 import org.apache.commons.lang.StringUtils;
14 import org.mule.config.converters.QNameConverter;
15 import org.mule.util.ClassUtils;
16
17 import javax.xml.namespace.QName JavaDoc;
18 import javax.xml.rpc.ParameterMode JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.StringTokenizer JavaDoc;
23
24 /**
25  * A soap method representation where the parameters are named
26  *
27  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
28  * @version $Revision: 3798 $
29  */

30 public class SoapMethod
31 {
32
33     private QName JavaDoc name;
34     private List JavaDoc namedParameters = new ArrayList JavaDoc();
35     private QName JavaDoc returnType;
36     private Class JavaDoc returnClass = Object JavaDoc.class;
37     private static QNameConverter converter = new QNameConverter();
38
39     public SoapMethod(String JavaDoc methodName, String JavaDoc paramsString) throws ClassNotFoundException JavaDoc
40     {
41         this((QName JavaDoc)converter.convert(QName JavaDoc.class, methodName), paramsString);
42     }
43
44     /**
45      * Creates a Soap Method using the param string set in the MUle configuration
46      * file
47      *
48      * @param methodName the name of the method
49      * @param params the param string to parse
50      */

51     public SoapMethod(String JavaDoc methodName, List JavaDoc params) throws ClassNotFoundException JavaDoc
52     {
53         this((QName JavaDoc)converter.convert(QName JavaDoc.class, methodName), params);
54     }
55
56     public SoapMethod(QName JavaDoc methodName, String JavaDoc paramsString) throws ClassNotFoundException JavaDoc
57     {
58         name = methodName;
59         List JavaDoc params = new ArrayList JavaDoc();
60         for (StringTokenizer JavaDoc stringTokenizer = new StringTokenizer JavaDoc(paramsString, ","); stringTokenizer.hasMoreTokens();)
61         {
62             params.add(stringTokenizer.nextToken().trim());
63         }
64         initParams(params);
65     }
66
67     public SoapMethod(QName JavaDoc methodName, List JavaDoc params) throws ClassNotFoundException JavaDoc
68     {
69         name = methodName;
70         initParams(params);
71     }
72
73     private void initParams(List JavaDoc params) throws ClassNotFoundException JavaDoc
74     {
75
76         NamedParameter param;
77         for (Iterator JavaDoc iterator = params.iterator(); iterator.hasNext();)
78         {
79             String JavaDoc s = (String JavaDoc)iterator.next();
80
81             for (StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(s, ";"); tokenizer.hasMoreTokens();)
82             {
83                 String JavaDoc name = tokenizer.nextToken();
84                 String JavaDoc type = tokenizer.nextToken();
85                 if (name.equalsIgnoreCase("return"))
86                 {
87                     if (type.startsWith("qname{"))
88                     {
89                         returnType = (QName JavaDoc)converter.convert(QName JavaDoc.class, type);
90                     }
91                     else
92                     {
93                         returnType = NamedParameter.createQName(type);
94                     }
95                 }
96                 else if (name.equalsIgnoreCase("returnClass"))
97                 {
98                     returnClass = ClassUtils.loadClass(type, getClass());
99                 }
100                 else
101                 {
102                     String JavaDoc mode = tokenizer.nextToken();
103                     QName JavaDoc paramName = null;
104                     if (name.startsWith("qname{"))
105                     {
106                         paramName = (QName JavaDoc)converter.convert(QName JavaDoc.class, name);
107                     }
108                     else
109                     {
110                         paramName = new QName JavaDoc(getName().getNamespaceURI(), name, getName().getPrefix());
111                     }
112                     QName JavaDoc qtype = null;
113                     if (type.startsWith("qname{"))
114                     {
115                         qtype = (QName JavaDoc)converter.convert(QName JavaDoc.class, type);
116                     }
117                     else
118                     {
119                         qtype = NamedParameter.createQName(type);
120                     }
121                     param = new NamedParameter(paramName, qtype, mode);
122                     addNamedParameter(param);
123                 }
124             }
125         }
126     }
127
128     public SoapMethod(QName JavaDoc name)
129     {
130         this.name = name;
131         this.returnType = null;
132     }
133
134     public SoapMethod(QName JavaDoc name, QName JavaDoc returnType)
135     {
136         this.name = name;
137         this.returnType = returnType;
138     }
139
140     public SoapMethod(QName JavaDoc name, QName JavaDoc returnType, Class JavaDoc returnClass)
141     {
142         this.name = name;
143         this.returnType = returnType;
144         this.returnClass = returnClass;
145     }
146
147     public SoapMethod(QName JavaDoc name, Class JavaDoc returnClass)
148     {
149         this.name = name;
150         this.returnClass = returnClass;
151     }
152
153     public SoapMethod(QName JavaDoc name, List JavaDoc namedParameters, QName JavaDoc returnType)
154     {
155         this.name = name;
156         this.namedParameters = namedParameters;
157         this.returnType = returnType;
158     }
159
160     public void addNamedParameter(NamedParameter param)
161     {
162         namedParameters.add(param);
163     }
164
165     public NamedParameter addNamedParameter(QName JavaDoc name, QName JavaDoc type, String JavaDoc mode)
166     {
167         if (StringUtils.isBlank(name.getNamespaceURI()))
168         {
169             name = new QName JavaDoc(getName().getNamespaceURI(), name.getLocalPart(), name.getPrefix());
170         }
171         NamedParameter param = new NamedParameter(name, type, mode);
172         namedParameters.add(param);
173         return param;
174     }
175
176     public NamedParameter addNamedParameter(QName JavaDoc name, QName JavaDoc type, ParameterMode JavaDoc mode)
177     {
178         if (StringUtils.isBlank(name.getNamespaceURI()))
179         {
180             name = new QName JavaDoc(getName().getNamespaceURI(), name.getLocalPart(), name.getPrefix());
181         }
182         NamedParameter param = new NamedParameter(name, type, mode);
183         namedParameters.add(param);
184         return param;
185     }
186
187     public void removeNamedParameter(NamedParameter param)
188     {
189         namedParameters.remove(param);
190     }
191
192     public QName JavaDoc getName()
193     {
194         return name;
195     }
196
197     public List JavaDoc getNamedParameters()
198     {
199         return namedParameters;
200     }
201
202     public QName JavaDoc getReturnType()
203     {
204         return returnType;
205     }
206
207     public void setReturnType(QName JavaDoc returnType)
208     {
209         this.returnType = returnType;
210     }
211
212     public Class JavaDoc getReturnClass()
213     {
214         return returnClass;
215     }
216
217     public void setReturnClass(Class JavaDoc returnClass)
218     {
219         this.returnClass = returnClass;
220     }
221 }
222
Popular Tags