001: package org.objectweb.celtix.tools.common.model;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.HashMap;
006: import java.util.List;
007: import java.util.Map;
008: import java.util.logging.Logger;
009:
010: import javax.jws.soap.SOAPBinding;
011: import javax.wsdl.OperationType;
012:
013: import org.objectweb.celtix.common.i18n.Message;
014: import org.objectweb.celtix.common.logging.LogUtils;
015: import org.objectweb.celtix.tools.common.ToolException;
016: import org.objectweb.celtix.tools.extensions.jaxws.JAXWSBinding;
017: import org.objectweb.celtix.tools.processors.wsdl2.WSDLToProcessor;
018:
019: public class JavaMethod {
020: private static final Logger LOG = LogUtils
021: .getL7dLogger(WSDLToProcessor.class);
022: private String name;
023: private String operationName;
024: private JavaReturn javaReturn;
025: private OperationType style;
026: private String soapAction;
027: private SOAPBinding.Style soapStyle;
028: private SOAPBinding.Use soapUse;
029: private WSDLParameter requestParameter;
030: private WSDLParameter responseParameter;
031: private boolean wrapperStyle;
032: private final JavaInterface javaInterface;
033: private final List<JavaParameter> parameters = new ArrayList<JavaParameter>();
034: private final List<JavaException> exceptions = new ArrayList<JavaException>();
035: private final Map<String, JavaAnnotation> annotations = new HashMap<String, JavaAnnotation>();
036: private final List<WSDLException> wsdlExceptions = new ArrayList<WSDLException>();
037: private JAXWSBinding jaxwsBinding = new JAXWSBinding();
038: private JAXWSBinding bindingExt = new JAXWSBinding();
039:
040: public JavaMethod() {
041: this .javaInterface = null;
042: }
043:
044: public JavaMethod(JavaInterface i) {
045: this .javaInterface = i;
046: }
047:
048: public void clear() {
049: parameters.clear();
050: javaReturn = null;
051: }
052:
053: public String getSignature() {
054: StringBuffer sb = new StringBuffer();
055: sb.append(javaReturn.getName());
056: sb.append("#");
057: sb.append(javaInterface.getPackageName());
058: sb.append(".");
059: sb.append(javaInterface.getName());
060: sb.append("#");
061: sb.append(name);
062: sb.append("[");
063: for (JavaParameter param : parameters) {
064: sb.append(param.getName());
065: sb.append(",");
066: }
067: sb.append("]");
068: return sb.toString();
069: }
070:
071: public JavaInterface getInterface() {
072: return this .javaInterface;
073: }
074:
075: public String getName() {
076: return name;
077: }
078:
079: public void setName(String n) {
080: this .name = n;
081: }
082:
083: public String getOperationName() {
084: return this .operationName;
085: }
086:
087: public void setOperationName(String arg) {
088: this .operationName = arg;
089: }
090:
091: public JavaReturn getReturn() {
092: return javaReturn;
093: }
094:
095: public void setReturn(JavaReturn rt) {
096: this .javaReturn = rt;
097: }
098:
099: public boolean hasParameter(String paramName) {
100: for (int i = 0; i < parameters.size(); i++) {
101: if (paramName.equals((parameters.get(i)).getName())) {
102: return true;
103: }
104: }
105: return false;
106: }
107:
108: private void removeParameter(JavaParameter param) {
109: parameters.remove(param);
110: }
111:
112: public void addParameter(JavaParameter param) {
113: if (hasParameter(param.getName())) {
114: JavaParameter paramInList = getParameter(param.getName());
115: if (paramInList.isIN() || paramInList.isINOUT()) {
116: removeParameter(paramInList);
117: } else {
118: Message message = new Message(
119: "PARAMETER_ALREADY_EXIST", LOG, param.getName());
120: throw new ToolException(message);
121: }
122: }
123: parameters.add(param);
124: }
125:
126: public JavaParameter getParameter(String paramName) {
127: for (int i = 0; i < parameters.size(); i++) {
128: JavaParameter jParam = parameters.get(i);
129: if (paramName.equals(jParam.getName())) {
130: return jParam;
131: }
132: }
133: return null;
134: }
135:
136: public List<JavaParameter> getParameters() {
137: return parameters;
138: }
139:
140: public int getParameterCount() {
141: return parameters.size();
142: }
143:
144: public boolean hasException(JavaException exception) {
145: return exceptions.contains(exception);
146: }
147:
148: public void addException(JavaException exception) {
149: if (hasException(exception)) {
150: Message message = new Message("EXCEPTION_ALREADY_EXIST",
151: LOG, exception.getName());
152: throw new ToolException(message);
153: }
154: exceptions.add(exception);
155: }
156:
157: public List<JavaException> getExceptions() {
158: return exceptions;
159: }
160:
161: public OperationType getStyle() {
162: return this .style;
163: }
164:
165: public void setStyle(OperationType ot) {
166: this .style = ot;
167: }
168:
169: public boolean isOneWay() {
170: return OperationType.ONE_WAY.equals(getStyle());
171: }
172:
173: public boolean isWrapperStyle() {
174: return this .wrapperStyle;
175: }
176:
177: public void setWrapperStyle(boolean w) {
178: this .wrapperStyle = w;
179: }
180:
181: public void setSoapStyle(SOAPBinding.Style sty) {
182: this .soapStyle = sty;
183: }
184:
185: public SOAPBinding.Style getSoapStyle() {
186: return this .soapStyle;
187: }
188:
189: public void setSoapAction(String action) {
190: this .soapAction = action;
191: }
192:
193: public String getSoapAction() {
194: return this .soapAction;
195: }
196:
197: public void setSoapUse(SOAPBinding.Use u) {
198: this .soapUse = u;
199: }
200:
201: public SOAPBinding.Use getSoapUse() {
202: return this .soapUse;
203: }
204:
205: public void addAnnotation(String tag, JavaAnnotation annotation) {
206: if (annotation == null) {
207: return;
208: }
209: this .annotations.put(tag, annotation);
210: }
211:
212: public Collection<JavaAnnotation> getAnnotations() {
213: return this .annotations.values();
214: }
215:
216: public Map<String, JavaAnnotation> getAnnotationMap() {
217: return this .annotations;
218: }
219:
220: public void addWSDLException(WSDLException exception) {
221: if (wsdlExceptions.contains(exception)) {
222: Message message = new Message("EXCEPTION_ALREADY_EXIST",
223: LOG, exception.getDetailType().getName());
224: throw new ToolException(message);
225: }
226: wsdlExceptions.add(exception);
227: }
228:
229: public List<WSDLException> getWSDLExceptions() {
230: return wsdlExceptions;
231: }
232:
233: public void addRequest(WSDLParameter param) {
234: this .requestParameter = param;
235: }
236:
237: public WSDLParameter getRequest() {
238: return this .requestParameter;
239: }
240:
241: public void addResponse(WSDLParameter param) {
242: this .responseParameter = param;
243: }
244:
245: public WSDLParameter getResponse() {
246: return this .responseParameter;
247: }
248:
249: public List<String> getParameterList() {
250: return getParameterList(true);
251: }
252:
253: public List<String> getParameterListWithoutAnnotation() {
254: return getParameterList(false);
255: }
256:
257: public List<String> getParameterList(boolean includeAnnotation) {
258: List<String> list = new ArrayList<String>();
259: StringBuffer sb = new StringBuffer();
260: for (int i = 0; i < parameters.size(); i++) {
261: JavaParameter parameter = parameters.get(i);
262: if (includeAnnotation) {
263: list.add(parameter.getAnnotation().toString());
264: }
265: sb.setLength(0);
266: if (parameter.isHolder()) {
267: sb.append(parameter.getHolderName());
268: sb.append("<");
269: sb.append(parameter.getHolderClass());
270: sb.append(">");
271: } else {
272: sb.append(parameter.getClassName());
273: }
274: sb.append(" ");
275: sb.append(parameter.getName());
276: if (i != (parameters.size() - 1)) {
277: sb.append(',');
278: }
279: list.add(sb.toString());
280: }
281: return list;
282: }
283:
284: public JAXWSBinding getJAXWSBinding() {
285: return this .jaxwsBinding;
286: }
287:
288: public void setJAXWSBinding(JAXWSBinding binding) {
289: if (binding != null) {
290: this .jaxwsBinding = binding;
291: }
292: }
293:
294: public String toString() {
295: StringBuffer sb = new StringBuffer();
296: sb.append("\n========================\n");
297: sb.append("\nMethod:");
298: sb.append(getName());
299: sb.append("\n-----------\n");
300: sb.append("\nReturn:");
301: sb.append(getReturn());
302: sb.append("\n------------\n");
303: sb.append("\nParameter:");
304: sb.append(getParameterList());
305: sb.append("\n------------\n");
306: sb.append("\nAnnotations:");
307: sb.append(getAnnotations());
308: sb.append("\n========================\n");
309: return sb.toString();
310: }
311:
312: public JAXWSBinding getBindingExt() {
313: return bindingExt;
314: }
315:
316: public void setBindingExt(JAXWSBinding pBindingExt) {
317: this.bindingExt = pBindingExt;
318: }
319: }
|