KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > tools > common > model > JavaMethod


1 package org.objectweb.celtix.tools.common.model;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5 import java.util.HashMap JavaDoc;
6 import java.util.List JavaDoc;
7 import java.util.Map JavaDoc;
8 import java.util.logging.Logger JavaDoc;
9
10 import javax.jws.soap.SOAPBinding;
11 import javax.wsdl.OperationType;
12
13 import org.objectweb.celtix.common.i18n.Message;
14 import org.objectweb.celtix.common.logging.LogUtils;
15 import org.objectweb.celtix.tools.common.ToolException;
16 import org.objectweb.celtix.tools.extensions.jaxws.JAXWSBinding;
17 import org.objectweb.celtix.tools.processors.wsdl2.WSDLToProcessor;
18
19 public class JavaMethod {
20     private static final Logger JavaDoc LOG = LogUtils.getL7dLogger(WSDLToProcessor.class);
21     private String JavaDoc name;
22     private String JavaDoc operationName;
23     private JavaReturn javaReturn;
24     private OperationType style;
25     private String JavaDoc soapAction;
26     private SOAPBinding.Style soapStyle;
27     private SOAPBinding.Use soapUse;
28     private WSDLParameter requestParameter;
29     private WSDLParameter responseParameter;
30     private boolean wrapperStyle;
31     private final JavaInterface javaInterface;
32     private final List JavaDoc<JavaParameter> parameters = new ArrayList JavaDoc<JavaParameter>();
33     private final List JavaDoc<JavaException> exceptions = new ArrayList JavaDoc<JavaException>();
34     private final Map JavaDoc<String JavaDoc, JavaAnnotation> annotations = new HashMap JavaDoc<String JavaDoc, JavaAnnotation>();
35     private final List JavaDoc<WSDLException> wsdlExceptions = new ArrayList JavaDoc<WSDLException>();
36     private JAXWSBinding jaxwsBinding = new JAXWSBinding();
37     private JAXWSBinding bindingExt = new JAXWSBinding();
38
39     public JavaMethod() {
40         this.javaInterface = null;
41     }
42
43     public JavaMethod(JavaInterface i) {
44         this.javaInterface = i;
45     }
46
47     public void clear() {
48         parameters.clear();
49         javaReturn = null;
50     }
51
52     public String JavaDoc getSignature() {
53         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
54         sb.append(javaReturn.getName());
55         sb.append("#");
56         sb.append(javaInterface.getPackageName());
57         sb.append(".");
58         sb.append(javaInterface.getName());
59         sb.append("#");
60         sb.append(name);
61         sb.append("[");
62         for (JavaParameter param : parameters) {
63             sb.append(param.getName());
64             sb.append(",");
65         }
66         sb.append("]");
67         return sb.toString();
68     }
69
70     public JavaInterface getInterface() {
71         return this.javaInterface;
72     }
73
74     public String JavaDoc getName() {
75         return name;
76     }
77
78     public void setName(String JavaDoc n) {
79         this.name = n;
80     }
81
82     public String JavaDoc getOperationName() {
83         return this.operationName;
84     }
85
86     public void setOperationName(String JavaDoc arg) {
87         this.operationName = arg;
88     }
89
90     public JavaReturn getReturn() {
91         return javaReturn;
92     }
93
94     public void setReturn(JavaReturn rt) {
95         this.javaReturn = rt;
96     }
97
98     public boolean hasParameter(String JavaDoc paramName) {
99         for (int i = 0; i < parameters.size(); i++) {
100             if (paramName.equals((parameters.get(i)).getName())) {
101                 return true;
102             }
103         }
104         return false;
105     }
106
107     private void removeParameter(JavaParameter param) {
108         parameters.remove(param);
109     }
110
111     public void addParameter(JavaParameter param) {
112         if (hasParameter(param.getName())) {
113             JavaParameter paramInList = getParameter(param.getName());
114             if (paramInList.isIN() || paramInList.isINOUT()) {
115                 removeParameter(paramInList);
116             } else {
117                 Message message = new Message("PARAMETER_ALREADY_EXIST", LOG, param.getName());
118                 throw new ToolException(message);
119             }
120         }
121         parameters.add(param);
122     }
123
124     public JavaParameter getParameter(String JavaDoc paramName) {
125         for (int i = 0; i < parameters.size(); i++) {
126             JavaParameter jParam = parameters.get(i);
127             if (paramName.equals(jParam.getName())) {
128                 return jParam;
129             }
130         }
131         return null;
132     }
133
134     public List JavaDoc<JavaParameter> getParameters() {
135         return parameters;
136     }
137
138     public int getParameterCount() {
139         return parameters.size();
140     }
141
142     public boolean hasException(JavaException exception) {
143         return exceptions.contains(exception);
144     }
145
146     public void addException(JavaException exception) {
147         if (hasException(exception)) {
148             Message message = new Message("EXCEPTION_ALREADY_EXIST", LOG, exception.getName());
149             throw new ToolException(message);
150         }
151         exceptions.add(exception);
152     }
153
154     public List JavaDoc<JavaException> getExceptions() {
155         return exceptions;
156     }
157
158     public OperationType getStyle() {
159         return this.style;
160     }
161
162     public void setStyle(OperationType ot) {
163         this.style = ot;
164     }
165
166     public boolean isOneWay() {
167         return OperationType.ONE_WAY.equals(getStyle());
168     }
169
170     public boolean isWrapperStyle() {
171         return this.wrapperStyle;
172     }
173
174     public void setWrapperStyle(boolean w) {
175         this.wrapperStyle = w;
176     }
177
178     public void setSoapStyle(SOAPBinding.Style sty) {
179         this.soapStyle = sty;
180     }
181
182     public SOAPBinding.Style getSoapStyle() {
183         return this.soapStyle;
184     }
185
186     public void setSoapAction(String JavaDoc action) {
187         this.soapAction = action;
188     }
189
190     public String JavaDoc getSoapAction() {
191         return this.soapAction;
192     }
193
194     public void setSoapUse(SOAPBinding.Use u) {
195         this.soapUse = u;
196     }
197
198     public SOAPBinding.Use getSoapUse() {
199         return this.soapUse;
200     }
201
202     public void addAnnotation(String JavaDoc tag, JavaAnnotation annotation) {
203         if (annotation == null) {
204             return;
205         }
206         this.annotations.put(tag, annotation);
207     }
208
209     public Collection JavaDoc<JavaAnnotation> getAnnotations() {
210         return this.annotations.values();
211     }
212
213     public Map JavaDoc<String JavaDoc, JavaAnnotation> getAnnotationMap() {
214         return this.annotations;
215     }
216
217     public void addWSDLException(WSDLException exception) {
218         if (wsdlExceptions.contains(exception)) {
219             Message message = new Message("EXCEPTION_ALREADY_EXIST", LOG,
220                                           exception.getDetailType().getName());
221             throw new ToolException(message);
222         }
223         wsdlExceptions.add(exception);
224     }
225
226     public List JavaDoc<WSDLException> getWSDLExceptions() {
227         return wsdlExceptions;
228     }
229
230     public void addRequest(WSDLParameter param) {
231         this.requestParameter = param;
232     }
233
234     public WSDLParameter getRequest() {
235         return this.requestParameter;
236     }
237
238     public void addResponse(WSDLParameter param) {
239         this.responseParameter = param;
240     }
241
242     public WSDLParameter getResponse() {
243         return this.responseParameter;
244     }
245
246     public List JavaDoc<String JavaDoc> getParameterList() {
247         return getParameterList(true);
248     }
249
250     public List JavaDoc<String JavaDoc> getParameterListWithoutAnnotation() {
251         return getParameterList(false);
252     }
253
254     public List JavaDoc<String JavaDoc> getParameterList(boolean includeAnnotation) {
255         List JavaDoc<String JavaDoc> list = new ArrayList JavaDoc<String JavaDoc>();
256         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
257         for (int i = 0; i < parameters.size(); i++) {
258             JavaParameter parameter = parameters.get(i);
259             if (includeAnnotation) {
260                 list.add(parameter.getAnnotation().toString());
261             }
262             sb.setLength(0);
263             if (parameter.isHolder()) {
264                 sb.append(parameter.getHolderName());
265                 sb.append("<");
266                 sb.append(parameter.getHolderClass());
267                 sb.append(">");
268             } else {
269                 sb.append(parameter.getClassName());
270             }
271             sb.append(" ");
272             sb.append(parameter.getName());
273             if (i != (parameters.size() - 1)) {
274                 sb.append(',');
275             }
276             list.add(sb.toString());
277         }
278         return list;
279     }
280
281     public JAXWSBinding getJAXWSBinding() {
282         return this.jaxwsBinding;
283     }
284
285     public void setJAXWSBinding(JAXWSBinding binding) {
286         if (binding != null) {
287             this.jaxwsBinding = binding;
288         }
289     }
290
291     public String JavaDoc toString() {
292         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
293         sb.append("\n========================\n");
294         sb.append("\nMethod:");
295         sb.append(getName());
296         sb.append("\n-----------\n");
297         sb.append("\nReturn:");
298         sb.append(getReturn());
299         sb.append("\n------------\n");
300         sb.append("\nParameter:");
301         sb.append(getParameterList());
302         sb.append("\n------------\n");
303         sb.append("\nAnnotations:");
304         sb.append(getAnnotations());
305         sb.append("\n========================\n");
306         return sb.toString();
307     }
308
309     public JAXWSBinding getBindingExt() {
310         return bindingExt;
311     }
312
313     public void setBindingExt(JAXWSBinding pBindingExt) {
314         this.bindingExt = pBindingExt;
315     }
316 }
317
Popular Tags