KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.objectweb.celtix.tools.common.model;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.HashMap JavaDoc;
5 import java.util.Iterator 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.jws.soap.SOAPBinding.ParameterStyle;
12 import javax.jws.soap.SOAPBinding.Style;
13 import javax.jws.soap.SOAPBinding.Use;
14 import javax.wsdl.Definition;
15 import javax.wsdl.WSDLException;
16 import javax.wsdl.factory.WSDLFactory;
17
18 import com.sun.xml.bind.api.JAXBRIContext;
19 import com.sun.xml.bind.api.TypeReference;
20
21 import org.objectweb.celtix.common.i18n.Message;
22 import org.objectweb.celtix.common.logging.LogUtils;
23 import org.objectweb.celtix.tools.common.ToolException;
24 import org.objectweb.celtix.tools.processors.java2.JavaToWSDLProcessor;
25
26 public class WSDLModel {
27     private static final Logger JavaDoc LOG = LogUtils.getL7dLogger(JavaToWSDLProcessor.class);
28     protected JAXBRIContext jaxbContext;
29
30     private Definition definition;
31
32     private String JavaDoc wsdlLocation;
33
34     private String JavaDoc serviceName;
35
36     private String JavaDoc targetNameSpace;
37
38     private String JavaDoc portTypeName;
39
40     private String JavaDoc portName;
41
42     private String JavaDoc packageName;
43
44     private final List JavaDoc<JavaMethod> methods = new ArrayList JavaDoc<JavaMethod>();
45
46     private final Map JavaDoc<String JavaDoc, String JavaDoc> schemaNSFileMap = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
47   
48     // default Doc-Lit-Wrapped
49
private Style style = SOAPBinding.Style.DOCUMENT;
50
51     private Use use = SOAPBinding.Use.LITERAL;
52
53     private ParameterStyle paraStyle = SOAPBinding.ParameterStyle.WRAPPED;
54
55     public WSDLModel() throws ToolException {
56         try {
57             WSDLFactory wsdlFactory = WSDLFactory.newInstance();
58             definition = wsdlFactory.newDefinition();
59         } catch (WSDLException e) {
60             Message message = new Message("FAIL_TO_CREATE_WSDL_DEFINITION", LOG);
61             throw new ToolException(message, e);
62         }
63     }
64
65     public void setWsdllocation(String JavaDoc loc) {
66         this.wsdlLocation = loc;
67     }
68
69     public String JavaDoc getWsdllocation() {
70         return this.wsdlLocation;
71
72     }
73
74     public void setServiceName(String JavaDoc name) {
75         this.serviceName = name;
76     }
77
78     public String JavaDoc getServiceName() {
79         return this.serviceName;
80     }
81
82     public String JavaDoc getPortTypeName() {
83         return this.portTypeName;
84     }
85
86     public void setPortTypeName(String JavaDoc pname) {
87         this.portTypeName = pname;
88     }
89
90     public void setPortName(String JavaDoc name) {
91         this.portName = name;
92     }
93
94     public String JavaDoc getPortName() {
95         return this.portName;
96     }
97
98     public void setTargetNameSpace(String JavaDoc space) {
99         this.targetNameSpace = space;
100     }
101
102     public String JavaDoc getTargetNameSpace() {
103         return this.targetNameSpace;
104     }
105
106     public Definition getDefinition() {
107         return this.definition;
108     }
109
110     public String JavaDoc getPackageName() {
111         return this.packageName;
112     }
113
114     public void setPackageName(String JavaDoc name) {
115         this.packageName = name;
116     }
117
118     public void addJavaMethod(JavaMethod jmothd) {
119         this.methods.add(jmothd);
120     }
121
122     public List JavaDoc<JavaMethod> getJavaMethods() {
123         return this.methods;
124     }
125
126     public void createJAXBContext() throws ToolException {
127         List JavaDoc<TypeReference> types = this.getAllTypeReference();
128         Class JavaDoc[] clzzs = new Class JavaDoc[types.size()];
129         int i = 0;
130         for (TypeReference typeref : types) {
131             clzzs[i++] = (Class JavaDoc)typeref.type;
132         }
133         try {
134             jaxbContext = JAXBRIContext.newInstance(clzzs, types, this.getTargetNameSpace(), false);
135
136         } catch (Exception JavaDoc e) {
137             Message message = new Message("CREATE_JAXBRICONTEXT_EXCEPTION", LOG);
138             throw new ToolException(message, e);
139         }
140
141     }
142
143     /**
144      * @return returns non-null list of TypeReference
145      */

146     public List JavaDoc<TypeReference> getAllTypeReference() {
147         List JavaDoc<TypeReference> types = new ArrayList JavaDoc<TypeReference>();
148         for (JavaMethod m : methods) {
149             WSDLParameter request = m.getRequest();
150             if (request.getTypeReference() != null && m.isWrapperStyle()) {
151                 types.add(request.getTypeReference());
152
153             } else {
154                 Iterator JavaDoc ite2 = request.getChildren().iterator();
155                 while (ite2.hasNext()) {
156                     JavaParameter jp = (JavaParameter)ite2.next();
157                     if (jp.getTypeReference() != null) {
158                         types.add(jp.getTypeReference());
159
160                     }
161                 }
162             }
163             if (!m.isOneWay()) {
164                 WSDLParameter response = m.getResponse();
165                 if (response.getTypeReference() != null && m.isWrapperStyle()) {
166                     types.add(response.getTypeReference());
167
168                 } else {
169                     Iterator JavaDoc ite2 = response.getChildren().iterator();
170                     while (ite2.hasNext()) {
171                         JavaParameter jp = (JavaParameter)ite2.next();
172                         if (jp.getTypeReference() != null) {
173                             types.add(jp.getTypeReference());
174
175                         }
176                     }
177                 }
178             }
179             Iterator JavaDoc ite3 = m.getWSDLExceptions().iterator();
180             while (ite3.hasNext()) {
181                 org.objectweb.celtix.tools.common.model.WSDLException wsdlEx =
182                     (org.objectweb.celtix.tools.common.model.WSDLException)ite3.next();
183                 types.add(wsdlEx.getDetailTypeReference());
184             }
185         }
186
187         return types;
188     }
189
190     public JAXBRIContext getJaxbContext() {
191         return this.jaxbContext;
192     }
193
194     public void setStyle(Style s) {
195         this.style = s;
196     }
197
198     public Style getStyle() {
199         return this.style;
200     }
201
202     public void setUse(Use u) {
203         this.use = u;
204     }
205
206     public ParameterStyle getParameterStyle() {
207         return paraStyle;
208     }
209
210     public void setPrameterStyle(ParameterStyle pstyle) {
211         paraStyle = pstyle;
212     }
213
214     public Use getUse() {
215         return this.use;
216     }
217
218     public boolean isDocLit() {
219         if (this.style == Style.DOCUMENT && this.use == Use.LITERAL) {
220             return true;
221         }
222         return false;
223     }
224
225     public boolean isWrapped() {
226         return this.paraStyle == SOAPBinding.ParameterStyle.WRAPPED;
227     }
228
229     public boolean isRPC() {
230         return (this.style == SOAPBinding.Style.RPC) && (this.use == SOAPBinding.Use.LITERAL)
231                && (this.paraStyle == SOAPBinding.ParameterStyle.WRAPPED);
232     }
233
234     public Map JavaDoc<String JavaDoc, String JavaDoc> getSchemaNSFileMap() {
235         return this.schemaNSFileMap;
236     }
237
238     public void addSchemaNSFileToMap(String JavaDoc schemaNS, String JavaDoc filename) {
239         this.schemaNSFileMap.put(schemaNS, filename);
240     }
241
242 }
243
Popular Tags