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

Thu, 12 Oct 2017 19:44:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 19:44:07 +0800
changeset 760
e530533619ec
parent 637
9c07ef4934dd
permissions
-rw-r--r--

merge

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

mercurial