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