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