Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.internal.ws.processor.modeler.wsdl;
28 import com.sun.tools.internal.ws.processor.model.AbstractType;
29 import com.sun.tools.internal.ws.processor.model.Block;
30 import com.sun.tools.internal.ws.processor.model.ModelProperties;
31 import com.sun.tools.internal.ws.processor.model.Parameter;
32 import com.sun.tools.internal.ws.processor.model.java.JavaSimpleType;
33 import com.sun.tools.internal.ws.processor.model.java.JavaStructureMember;
34 import com.sun.tools.internal.ws.processor.model.java.JavaStructureType;
35 import com.sun.tools.internal.ws.processor.model.java.JavaType;
36 import com.sun.tools.internal.ws.processor.model.jaxb.*;
37 import com.sun.tools.internal.ws.resources.ModelerMessages;
38 import com.sun.tools.internal.ws.util.ClassNameInfo;
39 import com.sun.tools.internal.ws.wscompile.AbortException;
40 import com.sun.tools.internal.ws.wscompile.ErrorReceiverFilter;
41 import com.sun.tools.internal.ws.wsdl.document.Message;
42 import com.sun.tools.internal.ws.wsdl.document.MessagePart;
43 import com.sun.tools.internal.xjc.api.S2JJAXBModel;
44 import com.sun.tools.internal.xjc.api.TypeAndAnnotation;
46 import javax.xml.namespace.QName;
47 import java.util.ArrayList;
48 import java.util.Iterator;
49 import java.util.List;
51 /**
52 * Utilities to be used by WSDLModeler
53 *
54 * @author Vivek Pandey
55 *
56 */
57 class ModelerUtils {
59 /**
60 * This method should be called incase of wrapper style operations. This is
61 * equivalent to wrapper style schema component or JAXB Mapping object.
62 *
63 * @param jaxbType JAXBType from which a JAXBStructured type will be created.
64 * @return returns JAXBStructured type
65 */
66 public static JAXBStructuredType createJAXBStructureType(JAXBType jaxbType) {
67 JAXBStructuredType type = new JAXBStructuredType(jaxbType);
68 type.setName(jaxbType.getName());
69 type.setJavaType(jaxbType.getJavaType());
70 return type;
71 }
73 /**
74 * This method uses JAXBStructured type (wrapper style operations) and
75 * unwraps it to create list of parameters.
76 *
77 *
78 * @param jaxbType instance of JAXBType, could be JAXBStructured type.
79 * @param block The Block (body/Header/Attachment) to which the created Parameter belong.
80 * @return list of Parameters
81 */
82 public static List<Parameter> createUnwrappedParameters(JAXBType jaxbType,
83 Block block) {
84 List<Parameter> paramList = new ArrayList<Parameter>();
85 JAXBStructuredType type = null;
86 if (!(jaxbType instanceof JAXBStructuredType))
87 type = createJAXBStructureType(jaxbType);
88 else
89 type = (JAXBStructuredType) jaxbType;
91 JavaStructureType jst = new JavaStructureType(jaxbType.getJavaType()
92 .getRealName(), true, type);
93 type.setJavaType(jst);
94 block.setType(type);
95 List memberList = jaxbType.getWrapperChildren();
96 Iterator props = memberList.iterator();
97 while (props.hasNext()) {
98 JAXBProperty prop = (JAXBProperty) props.next();
99 paramList.add(createUnwrappedParameter(prop, jaxbType, block, type,
100 jst));
101 }
103 return paramList;
104 }
106 /**
107 * @param prop
108 * @param jaxbType
109 * @param block
110 * @return unwrapped parameter
111 */
112 private static Parameter createUnwrappedParameter(JAXBProperty prop,
113 JAXBType jaxbType, Block block, JAXBStructuredType type,
114 JavaStructureType jst) {
115 QName elementName = prop.getElementName();
116 JavaType javaType = new JavaSimpleType(prop.getType());
117 JAXBElementMember eType = new JAXBElementMember(elementName, jaxbType);
118 JavaStructureMember jsm = new JavaStructureMember(elementName
119 .getLocalPart(), javaType, eType);
120 eType.setJavaStructureMember(jsm);
121 jst.add(jsm);
122 eType.setProperty(prop);
123 type.add(eType);
124 JAXBType t = new JAXBType(elementName, javaType, jaxbType
125 .getJaxbMapping(), jaxbType.getJaxbModel());
126 t.setUnwrapped(true);
127 Parameter parameter = createParameter(elementName.getLocalPart(), t, block);
128 parameter.setEmbedded(true);
129 return parameter;
130 }
132 public static List<Parameter> createRpcLitParameters(Message message, Block block, S2JJAXBModel jaxbModel, ErrorReceiverFilter errReceiver){
133 RpcLitStructure rpcStruct = (RpcLitStructure)block.getType();
135 List<Parameter> parameters = new ArrayList<Parameter>();
136 for(MessagePart part : message.getParts()){
137 if(!ModelerUtils.isBoundToSOAPBody(part))
138 continue;
139 QName name = part.getDescriptor();
140 TypeAndAnnotation typeAndAnn = jaxbModel.getJavaType(name);
141 if(typeAndAnn == null){
142 String msgQName = "{"+message.getDefining().getTargetNamespaceURI()+"}"+message.getName();
143 errReceiver.error(part.getLocator(), ModelerMessages.WSDLMODELER_RPCLIT_UNKOWNSCHEMATYPE(name.toString(),
144 part.getName(), msgQName));
145 throw new AbortException();
146 }
147 String type = typeAndAnn.getTypeClass().fullName();
148 type = ClassNameInfo.getGenericClass(type);
149 RpcLitMember param = new RpcLitMember(new QName("", part.getName()), type);
150 JavaType javaType = new JavaSimpleType(new JAXBTypeAndAnnotation(typeAndAnn));
151 param.setJavaType(javaType);
152 rpcStruct.addRpcLitMember(param);
153 Parameter parameter = ModelerUtils.createParameter(part.getName(), param, block);
154 parameter.setEmbedded(true);
155 parameters.add(parameter);
156 }
157 return parameters;
158 }
160 /**
161 * Called for non-wrapper style operations. It returns a Parameter constructed
162 * using the JAXBType and the Block.
163 *
164 * @param partName typically wsdl:part or any name to be given to the parameter
165 * @param jaxbType type of Parameter
166 * @param block Block to which the parameter belongs to
167 * @return Parameter created.
168 */
169 public static Parameter createParameter(String partName, AbstractType jaxbType,
170 Block block) {
171 Parameter parameter = new Parameter(partName, block.getEntity());
172 parameter.setProperty(ModelProperties.PROPERTY_PARAM_MESSAGE_PART_NAME,
173 partName);
174 parameter.setEmbedded(false);
175 parameter.setType(jaxbType);
176 parameter.setTypeName(jaxbType.getJavaType().getType().getName());
177 parameter.setBlock(block);
178 return parameter;
179 }
181 /**
182 * Get Parameter from the list of parameters.
183 *
184 * @param paramName
185 * @param parameters
186 * @return the Parameter with name paramName from parameters
187 */
188 public static Parameter getParameter(String paramName, List<Parameter> parameters){
189 if(parameters == null)
190 return null;
191 for(Parameter param: parameters){
192 //if(param.getName().equals("_return") && paramName.equals("return") || param.getName().equals(paramName)) {
193 if(param.getName().equals(paramName)){
194 return param;
195 }
196 }
197 return null;
198 }
200 /**
201 * Compares two JAXBStructures.
202 *
203 * @param struct1
204 * @param struct2
205 * @return true if struct1 and struct2 are equivalent.
206 */
207 public static boolean isEquivalentLiteralStructures(
208 JAXBStructuredType struct1,
209 JAXBStructuredType struct2) {
210 if (struct1.getElementMembersCount() != struct2.getElementMembersCount())
211 return false;
212 Iterator members = struct1.getElementMembers();
213 JAXBElementMember member1;
214 JavaStructureMember javaMember1, javaMember2;
215 for (int i = 0; members.hasNext(); i++) {
216 member1 = (JAXBElementMember)members.next();
217 javaMember1 = member1.getJavaStructureMember();
218 javaMember2 =
219 ((JavaStructureType)struct2.getJavaType()).getMemberByName(
220 member1.getJavaStructureMember().getName());
221 if (javaMember2.getConstructorPos() != i
222 || !javaMember1.getType().equals(javaMember2.getType())) {
223 return false;
224 }
225 }
226 return false;
227 }
229 public static QName getRawTypeName(Parameter parameter) {
230 String name = parameter.getName();
232 if (parameter.getType() instanceof JAXBType) {
233 JAXBType jt = (JAXBType)parameter.getType();
234 if (jt.isUnwrappable()) {
235 List<JAXBProperty> props = jt.getWrapperChildren();
236 for(JAXBProperty prop: props) {
237 if (prop.getName().equals(name)) {
238 return prop.getRawTypeName();
239 }
240 }
241 }
242 }
243 return null;
244 }
246 /**
247 * @param part
248 * @return true if part is bound to Mime content
249 */
250 public static boolean isBoundToMimeContent(MessagePart part) {
251 if((part != null) && part.getBindingExtensibilityElementKind() == MessagePart.WSDL_MIME_BINDING)
252 return true;
253 return false;
254 }
256 /**
257 * @param part
258 * @return true if part is bound to SOAPBody
259 */
260 public static boolean isBoundToSOAPBody(MessagePart part) {
261 if((part != null) && part.getBindingExtensibilityElementKind() == MessagePart.SOAP_BODY_BINDING)
262 return true;
263 return false;
264 }
266 /**
267 * @param part
268 * @return true if part is bound to SOAPHeader
269 */
270 public static boolean isBoundToSOAPHeader(MessagePart part) {
271 if((part != null) && part.getBindingExtensibilityElementKind() == MessagePart.SOAP_HEADER_BINDING)
272 return true;
273 return false;
274 }
276 public static boolean isUnbound(MessagePart part) {
277 if((part != null) && part.getBindingExtensibilityElementKind() == MessagePart.PART_NOT_BOUNDED)
278 return true;
279 return false;
280 }
281 }