src/share/jaxws_classes/com/sun/xml/internal/ws/model/ParameterImpl.java

Fri, 22 Nov 2013 21:11:19 +0100

author
mkos
date
Fri, 22 Nov 2013 21:11:19 +0100
changeset 450
b0c2840e2513
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010935: Better XML handling
8027378: Two closed/javax/xml/8005432 fails with jdk7u51b04
8028382: Two javax/xml/8005433 tests still fail after the fix JDK-8028147
Summary: base fix + fixes for test regressions; fix also reviewed by Maxim Soloviev, Alexander Fomin
Reviewed-by: mchung, mgrebac, mullan

ohair@286 1 /*
alanb@368 2 * Copyright (c) 1997, 2012, 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.xml.internal.ws.model;
ohair@286 27
ohair@286 28 import com.sun.xml.internal.bind.api.Bridge;
ohair@286 29 import com.sun.xml.internal.bind.api.TypeReference;
ohair@286 30 import com.sun.xml.internal.ws.api.model.JavaMethod;
ohair@286 31 import com.sun.xml.internal.ws.api.model.Parameter;
ohair@286 32 import com.sun.xml.internal.ws.api.model.ParameterBinding;
alanb@368 33 import com.sun.xml.internal.ws.spi.db.RepeatedElementBridge;
alanb@368 34 import com.sun.xml.internal.ws.spi.db.WrapperComposite;
ohair@286 35 import com.sun.xml.internal.ws.spi.db.XMLBridge;
ohair@286 36 import com.sun.xml.internal.ws.spi.db.TypeInfo;
ohair@286 37
ohair@286 38 import javax.jws.WebParam.Mode;
ohair@286 39 import javax.xml.namespace.QName;
ohair@286 40 import javax.xml.ws.Holder;
ohair@286 41 import java.util.List;
ohair@286 42
ohair@286 43 /**
ohair@286 44 * runtime Parameter that abstracts the annotated java parameter
ohair@286 45 *
ohair@286 46 * <p>
ohair@286 47 * A parameter may be bound to a header, a body, or an attachment.
ohair@286 48 * Note that when it's bound to a body, it's bound to a body,
ohair@286 49 * it binds to the whole payload.
ohair@286 50 *
ohair@286 51 * <p>
ohair@286 52 * Sometimes multiple Java parameters are packed into the payload,
ohair@286 53 * in which case the subclass {@link WrapperParameter} is used.
ohair@286 54 *
ohair@286 55 * @author Vivek Pandey
ohair@286 56 */
ohair@286 57 public class ParameterImpl implements Parameter {
ohair@286 58
ohair@286 59 private ParameterBinding binding;
ohair@286 60 private ParameterBinding outBinding;
ohair@286 61 private String partName;
ohair@286 62 private final int index;
ohair@286 63 private final Mode mode;
ohair@286 64 /** @deprecated */
ohair@286 65 private TypeReference typeReference;
ohair@286 66 private TypeInfo typeInfo;
ohair@286 67 private QName name;
ohair@286 68 private final JavaMethodImpl parent;
ohair@286 69
alanb@368 70 WrapperParameter wrapper;
alanb@368 71 TypeInfo itemTypeInfo;
alanb@368 72
ohair@286 73 public ParameterImpl(JavaMethodImpl parent, TypeInfo type, Mode mode, int index) {
ohair@286 74 assert type != null;
ohair@286 75
ohair@286 76 this.typeInfo = type;
ohair@286 77 this.name = type.tagName;
ohair@286 78 this.mode = mode;
ohair@286 79 this.index = index;
ohair@286 80 this.parent = parent;
ohair@286 81 }
ohair@286 82
ohair@286 83 public AbstractSEIModelImpl getOwner() {
ohair@286 84 return parent.owner;
ohair@286 85 }
ohair@286 86
ohair@286 87 public JavaMethod getParent() {
ohair@286 88 return parent;
ohair@286 89 }
ohair@286 90
ohair@286 91 /**
ohair@286 92 * @return Returns the name.
ohair@286 93 */
ohair@286 94 public QName getName() {
ohair@286 95 return name;
ohair@286 96 }
ohair@286 97
ohair@286 98 public XMLBridge getXMLBridge() {
ohair@286 99 return getOwner().getXMLBridge(typeInfo);
ohair@286 100 }
ohair@286 101
alanb@368 102 public XMLBridge getInlinedRepeatedElementBridge() {
alanb@368 103 TypeInfo itemType = getItemType();
alanb@368 104 if (itemType != null) {
alanb@368 105 XMLBridge xb = getOwner().getXMLBridge(itemType);
alanb@368 106 if (xb != null) return new RepeatedElementBridge(typeInfo, xb);
alanb@368 107 }
alanb@368 108 return null;
alanb@368 109 }
alanb@368 110
alanb@368 111 public TypeInfo getItemType() {
alanb@368 112 if (itemTypeInfo != null) return itemTypeInfo;
alanb@368 113 //RpcLit cannot inline repeated element in wrapper
alanb@368 114 if (parent.getBinding().isRpcLit() || wrapper == null) return null;
alanb@368 115 //InlinedRepeatedElementBridge is only used for dynamic wrapper (no wrapper class)
alanb@368 116 if (!WrapperComposite.class.equals(wrapper.getTypeInfo().type)) return null;
alanb@368 117 if (!getBinding().isBody()) return null;
alanb@368 118 itemTypeInfo = typeInfo.getItemType();
alanb@368 119 return itemTypeInfo;
alanb@368 120 }
alanb@368 121
ohair@286 122 /** @deprecated */
ohair@286 123 public Bridge getBridge() {
ohair@286 124 return getOwner().getBridge(typeReference);
ohair@286 125 }
ohair@286 126 /** @deprecated */
ohair@286 127 protected Bridge getBridge(TypeReference typeRef) {
ohair@286 128 return getOwner().getBridge(typeRef);
ohair@286 129 }
ohair@286 130
ohair@286 131 /**
ohair@286 132 * TODO: once the model gets JAXBContext, shouldn't {@link Bridge}s
ohair@286 133 * be made available from model objects?
ohair@286 134 * @deprecated use getTypeInfo
ohair@286 135 * @return Returns the TypeReference associated with this Parameter
ohair@286 136 */
ohair@286 137 public TypeReference getTypeReference() {
ohair@286 138 return typeReference;
ohair@286 139 }
ohair@286 140 public TypeInfo getTypeInfo() {
ohair@286 141 return typeInfo;
ohair@286 142 }
ohair@286 143
ohair@286 144 /**
ohair@286 145 * Sometimes we need to overwrite the typeReferenc, such as during patching for rpclit
alanb@368 146 * @see AbstractSEIModelImpl#applyRpcLitParamBinding(JavaMethodImpl, WrapperParameter, WSDLBoundPortType, WebParam.Mode)
ohair@286 147 * @deprecated
ohair@286 148 */
ohair@286 149 void setTypeReference(TypeReference type){
ohair@286 150 typeReference = type;
ohair@286 151 name = type.tagName;
ohair@286 152 }
ohair@286 153
ohair@286 154
ohair@286 155 public Mode getMode() {
ohair@286 156 return mode;
ohair@286 157 }
ohair@286 158
ohair@286 159 public int getIndex() {
ohair@286 160 return index;
ohair@286 161 }
ohair@286 162
ohair@286 163 /**
ohair@286 164 * @return true if <tt>this instanceof {@link WrapperParameter}</tt>.
ohair@286 165 */
ohair@286 166 public boolean isWrapperStyle() {
ohair@286 167 return false;
ohair@286 168 }
ohair@286 169
ohair@286 170 public boolean isReturnValue() {
ohair@286 171 return index==-1;
ohair@286 172 }
ohair@286 173
ohair@286 174 /**
ohair@286 175 * @return the Binding for this Parameter
ohair@286 176 */
ohair@286 177 public ParameterBinding getBinding() {
ohair@286 178 if(binding == null)
ohair@286 179 return ParameterBinding.BODY;
ohair@286 180 return binding;
ohair@286 181 }
ohair@286 182
ohair@286 183 /**
ohair@286 184 * @param binding
ohair@286 185 */
ohair@286 186 public void setBinding(ParameterBinding binding) {
ohair@286 187 this.binding = binding;
ohair@286 188 }
ohair@286 189
ohair@286 190 public void setInBinding(ParameterBinding binding){
ohair@286 191 this.binding = binding;
ohair@286 192 }
ohair@286 193
ohair@286 194 public void setOutBinding(ParameterBinding binding){
ohair@286 195 this.outBinding = binding;
ohair@286 196 }
ohair@286 197
ohair@286 198 public ParameterBinding getInBinding(){
ohair@286 199 return binding;
ohair@286 200 }
ohair@286 201
ohair@286 202 public ParameterBinding getOutBinding(){
ohair@286 203 if(outBinding == null)
ohair@286 204 return binding;
ohair@286 205 return outBinding;
ohair@286 206 }
ohair@286 207
ohair@286 208 public boolean isIN() {
ohair@286 209 return mode==Mode.IN;
ohair@286 210 }
ohair@286 211
ohair@286 212 public boolean isOUT() {
ohair@286 213 return mode==Mode.OUT;
ohair@286 214 }
ohair@286 215
ohair@286 216 public boolean isINOUT() {
ohair@286 217 return mode==Mode.INOUT;
ohair@286 218 }
ohair@286 219
ohair@286 220 /**
ohair@286 221 * If true, this parameter maps to the return value of a method invocation.
ohair@286 222 *
ohair@286 223 * <p>
ohair@286 224 * {@link JavaMethodImpl#getResponseParameters()} is guaranteed to have
ohair@286 225 * at most one such {@link ParameterImpl}. Note that there coule be none,
ohair@286 226 * in which case the method returns <tt>void</tt>.
ohair@286 227 */
ohair@286 228 public boolean isResponse() {
ohair@286 229 return index == -1;
ohair@286 230 }
ohair@286 231
ohair@286 232
ohair@286 233 /**
ohair@286 234 * Gets the holder value if applicable. To be called for inbound client side
ohair@286 235 * message.
ohair@286 236 *
ohair@286 237 * @param obj
ohair@286 238 * @return the holder value if applicable.
ohair@286 239 */
ohair@286 240 public Object getHolderValue(Object obj) {
ohair@286 241 if (obj != null && obj instanceof Holder)
ohair@286 242 return ((Holder) obj).value;
ohair@286 243 return obj;
ohair@286 244 }
ohair@286 245
ohair@286 246 public String getPartName() {
ohair@286 247 if(partName == null)
ohair@286 248 return name.getLocalPart();
ohair@286 249 return partName;
ohair@286 250 }
ohair@286 251
ohair@286 252 public void setPartName(String partName) {
ohair@286 253 this.partName = partName;
ohair@286 254 }
ohair@286 255
ohair@286 256 void fillTypes(List<TypeInfo> types) {
alanb@368 257 TypeInfo itemType = getItemType();
alanb@368 258 types.add((itemType != null) ? itemType : getTypeInfo());
ohair@286 259 }
ohair@286 260 }

mercurial