001: package org.objectweb.celtix.tools.common.model;
002:
003: import java.util.ArrayList;
004: import java.util.HashMap;
005: import java.util.Iterator;
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.jws.soap.SOAPBinding.ParameterStyle;
012: import javax.jws.soap.SOAPBinding.Style;
013: import javax.jws.soap.SOAPBinding.Use;
014: import javax.wsdl.Definition;
015: import javax.wsdl.WSDLException;
016: import javax.wsdl.factory.WSDLFactory;
017:
018: import com.sun.xml.bind.api.JAXBRIContext;
019: import com.sun.xml.bind.api.TypeReference;
020:
021: import org.objectweb.celtix.common.i18n.Message;
022: import org.objectweb.celtix.common.logging.LogUtils;
023: import org.objectweb.celtix.tools.common.ToolException;
024: import org.objectweb.celtix.tools.processors.java2.JavaToWSDLProcessor;
025:
026: public class WSDLModel {
027: private static final Logger LOG = LogUtils
028: .getL7dLogger(JavaToWSDLProcessor.class);
029: protected JAXBRIContext jaxbContext;
030:
031: private Definition definition;
032:
033: private String wsdlLocation;
034:
035: private String serviceName;
036:
037: private String targetNameSpace;
038:
039: private String portTypeName;
040:
041: private String portName;
042:
043: private String packageName;
044:
045: private final List<JavaMethod> methods = new ArrayList<JavaMethod>();
046:
047: private final Map<String, String> schemaNSFileMap = new HashMap<String, String>();
048:
049: // default Doc-Lit-Wrapped
050: private Style style = SOAPBinding.Style.DOCUMENT;
051:
052: private Use use = SOAPBinding.Use.LITERAL;
053:
054: private ParameterStyle paraStyle = SOAPBinding.ParameterStyle.WRAPPED;
055:
056: public WSDLModel() throws ToolException {
057: try {
058: WSDLFactory wsdlFactory = WSDLFactory.newInstance();
059: definition = wsdlFactory.newDefinition();
060: } catch (WSDLException e) {
061: Message message = new Message(
062: "FAIL_TO_CREATE_WSDL_DEFINITION", LOG);
063: throw new ToolException(message, e);
064: }
065: }
066:
067: public void setWsdllocation(String loc) {
068: this .wsdlLocation = loc;
069: }
070:
071: public String getWsdllocation() {
072: return this .wsdlLocation;
073:
074: }
075:
076: public void setServiceName(String name) {
077: this .serviceName = name;
078: }
079:
080: public String getServiceName() {
081: return this .serviceName;
082: }
083:
084: public String getPortTypeName() {
085: return this .portTypeName;
086: }
087:
088: public void setPortTypeName(String pname) {
089: this .portTypeName = pname;
090: }
091:
092: public void setPortName(String name) {
093: this .portName = name;
094: }
095:
096: public String getPortName() {
097: return this .portName;
098: }
099:
100: public void setTargetNameSpace(String space) {
101: this .targetNameSpace = space;
102: }
103:
104: public String getTargetNameSpace() {
105: return this .targetNameSpace;
106: }
107:
108: public Definition getDefinition() {
109: return this .definition;
110: }
111:
112: public String getPackageName() {
113: return this .packageName;
114: }
115:
116: public void setPackageName(String name) {
117: this .packageName = name;
118: }
119:
120: public void addJavaMethod(JavaMethod jmothd) {
121: this .methods.add(jmothd);
122: }
123:
124: public List<JavaMethod> getJavaMethods() {
125: return this .methods;
126: }
127:
128: public void createJAXBContext() throws ToolException {
129: List<TypeReference> types = this .getAllTypeReference();
130: Class[] clzzs = new Class[types.size()];
131: int i = 0;
132: for (TypeReference typeref : types) {
133: clzzs[i++] = (Class) typeref.type;
134: }
135: try {
136: jaxbContext = JAXBRIContext.newInstance(clzzs, types, this
137: .getTargetNameSpace(), false);
138:
139: } catch (Exception e) {
140: Message message = new Message(
141: "CREATE_JAXBRICONTEXT_EXCEPTION", LOG);
142: throw new ToolException(message, e);
143: }
144:
145: }
146:
147: /**
148: * @return returns non-null list of TypeReference
149: */
150: public List<TypeReference> getAllTypeReference() {
151: List<TypeReference> types = new ArrayList<TypeReference>();
152: for (JavaMethod m : methods) {
153: WSDLParameter request = m.getRequest();
154: if (request.getTypeReference() != null
155: && m.isWrapperStyle()) {
156: types.add(request.getTypeReference());
157:
158: } else {
159: Iterator ite2 = request.getChildren().iterator();
160: while (ite2.hasNext()) {
161: JavaParameter jp = (JavaParameter) ite2.next();
162: if (jp.getTypeReference() != null) {
163: types.add(jp.getTypeReference());
164:
165: }
166: }
167: }
168: if (!m.isOneWay()) {
169: WSDLParameter response = m.getResponse();
170: if (response.getTypeReference() != null
171: && m.isWrapperStyle()) {
172: types.add(response.getTypeReference());
173:
174: } else {
175: Iterator ite2 = response.getChildren().iterator();
176: while (ite2.hasNext()) {
177: JavaParameter jp = (JavaParameter) ite2.next();
178: if (jp.getTypeReference() != null) {
179: types.add(jp.getTypeReference());
180:
181: }
182: }
183: }
184: }
185: Iterator ite3 = m.getWSDLExceptions().iterator();
186: while (ite3.hasNext()) {
187: org.objectweb.celtix.tools.common.model.WSDLException wsdlEx = (org.objectweb.celtix.tools.common.model.WSDLException) ite3
188: .next();
189: types.add(wsdlEx.getDetailTypeReference());
190: }
191: }
192:
193: return types;
194: }
195:
196: public JAXBRIContext getJaxbContext() {
197: return this .jaxbContext;
198: }
199:
200: public void setStyle(Style s) {
201: this .style = s;
202: }
203:
204: public Style getStyle() {
205: return this .style;
206: }
207:
208: public void setUse(Use u) {
209: this .use = u;
210: }
211:
212: public ParameterStyle getParameterStyle() {
213: return paraStyle;
214: }
215:
216: public void setPrameterStyle(ParameterStyle pstyle) {
217: paraStyle = pstyle;
218: }
219:
220: public Use getUse() {
221: return this .use;
222: }
223:
224: public boolean isDocLit() {
225: if (this .style == Style.DOCUMENT && this .use == Use.LITERAL) {
226: return true;
227: }
228: return false;
229: }
230:
231: public boolean isWrapped() {
232: return this .paraStyle == SOAPBinding.ParameterStyle.WRAPPED;
233: }
234:
235: public boolean isRPC() {
236: return (this .style == SOAPBinding.Style.RPC)
237: && (this .use == SOAPBinding.Use.LITERAL)
238: && (this .paraStyle == SOAPBinding.ParameterStyle.WRAPPED);
239: }
240:
241: public Map<String, String> getSchemaNSFileMap() {
242: return this .schemaNSFileMap;
243: }
244:
245: public void addSchemaNSFileToMap(String schemaNS, String filename) {
246: this.schemaNSFileMap.put(schemaNS, filename);
247: }
248:
249: }
|