1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/model/ParameterImpl.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,260 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.model; 1.30 + 1.31 +import com.sun.xml.internal.bind.api.Bridge; 1.32 +import com.sun.xml.internal.bind.api.TypeReference; 1.33 +import com.sun.xml.internal.ws.api.model.JavaMethod; 1.34 +import com.sun.xml.internal.ws.api.model.Parameter; 1.35 +import com.sun.xml.internal.ws.api.model.ParameterBinding; 1.36 +import com.sun.xml.internal.ws.spi.db.RepeatedElementBridge; 1.37 +import com.sun.xml.internal.ws.spi.db.WrapperComposite; 1.38 +import com.sun.xml.internal.ws.spi.db.XMLBridge; 1.39 +import com.sun.xml.internal.ws.spi.db.TypeInfo; 1.40 + 1.41 +import javax.jws.WebParam.Mode; 1.42 +import javax.xml.namespace.QName; 1.43 +import javax.xml.ws.Holder; 1.44 +import java.util.List; 1.45 + 1.46 +/** 1.47 + * runtime Parameter that abstracts the annotated java parameter 1.48 + * 1.49 + * <p> 1.50 + * A parameter may be bound to a header, a body, or an attachment. 1.51 + * Note that when it's bound to a body, it's bound to a body, 1.52 + * it binds to the whole payload. 1.53 + * 1.54 + * <p> 1.55 + * Sometimes multiple Java parameters are packed into the payload, 1.56 + * in which case the subclass {@link WrapperParameter} is used. 1.57 + * 1.58 + * @author Vivek Pandey 1.59 + */ 1.60 +public class ParameterImpl implements Parameter { 1.61 + 1.62 + private ParameterBinding binding; 1.63 + private ParameterBinding outBinding; 1.64 + private String partName; 1.65 + private final int index; 1.66 + private final Mode mode; 1.67 + /** @deprecated */ 1.68 + private TypeReference typeReference; 1.69 + private TypeInfo typeInfo; 1.70 + private QName name; 1.71 + private final JavaMethodImpl parent; 1.72 + 1.73 + WrapperParameter wrapper; 1.74 + TypeInfo itemTypeInfo; 1.75 + 1.76 + public ParameterImpl(JavaMethodImpl parent, TypeInfo type, Mode mode, int index) { 1.77 + assert type != null; 1.78 + 1.79 + this.typeInfo = type; 1.80 + this.name = type.tagName; 1.81 + this.mode = mode; 1.82 + this.index = index; 1.83 + this.parent = parent; 1.84 + } 1.85 + 1.86 + public AbstractSEIModelImpl getOwner() { 1.87 + return parent.owner; 1.88 + } 1.89 + 1.90 + public JavaMethod getParent() { 1.91 + return parent; 1.92 + } 1.93 + 1.94 + /** 1.95 + * @return Returns the name. 1.96 + */ 1.97 + public QName getName() { 1.98 + return name; 1.99 + } 1.100 + 1.101 + public XMLBridge getXMLBridge() { 1.102 + return getOwner().getXMLBridge(typeInfo); 1.103 + } 1.104 + 1.105 + public XMLBridge getInlinedRepeatedElementBridge() { 1.106 + TypeInfo itemType = getItemType(); 1.107 + if (itemType != null) { 1.108 + XMLBridge xb = getOwner().getXMLBridge(itemType); 1.109 + if (xb != null) return new RepeatedElementBridge(typeInfo, xb); 1.110 + } 1.111 + return null; 1.112 + } 1.113 + 1.114 + public TypeInfo getItemType() { 1.115 + if (itemTypeInfo != null) return itemTypeInfo; 1.116 + //RpcLit cannot inline repeated element in wrapper 1.117 + if (parent.getBinding().isRpcLit() || wrapper == null) return null; 1.118 + //InlinedRepeatedElementBridge is only used for dynamic wrapper (no wrapper class) 1.119 + if (!WrapperComposite.class.equals(wrapper.getTypeInfo().type)) return null; 1.120 + if (!getBinding().isBody()) return null; 1.121 + itemTypeInfo = typeInfo.getItemType(); 1.122 + return itemTypeInfo; 1.123 + } 1.124 + 1.125 + /** @deprecated */ 1.126 + public Bridge getBridge() { 1.127 + return getOwner().getBridge(typeReference); 1.128 + } 1.129 + /** @deprecated */ 1.130 + protected Bridge getBridge(TypeReference typeRef) { 1.131 + return getOwner().getBridge(typeRef); 1.132 + } 1.133 + 1.134 + /** 1.135 + * TODO: once the model gets JAXBContext, shouldn't {@link Bridge}s 1.136 + * be made available from model objects? 1.137 + * @deprecated use getTypeInfo 1.138 + * @return Returns the TypeReference associated with this Parameter 1.139 + */ 1.140 + public TypeReference getTypeReference() { 1.141 + return typeReference; 1.142 + } 1.143 + public TypeInfo getTypeInfo() { 1.144 + return typeInfo; 1.145 + } 1.146 + 1.147 + /** 1.148 + * Sometimes we need to overwrite the typeReferenc, such as during patching for rpclit 1.149 + * @see AbstractSEIModelImpl#applyRpcLitParamBinding(JavaMethodImpl, WrapperParameter, WSDLBoundPortType, WebParam.Mode) 1.150 + * @deprecated 1.151 + */ 1.152 + void setTypeReference(TypeReference type){ 1.153 + typeReference = type; 1.154 + name = type.tagName; 1.155 + } 1.156 + 1.157 + 1.158 + public Mode getMode() { 1.159 + return mode; 1.160 + } 1.161 + 1.162 + public int getIndex() { 1.163 + return index; 1.164 + } 1.165 + 1.166 + /** 1.167 + * @return true if <tt>this instanceof {@link WrapperParameter}</tt>. 1.168 + */ 1.169 + public boolean isWrapperStyle() { 1.170 + return false; 1.171 + } 1.172 + 1.173 + public boolean isReturnValue() { 1.174 + return index==-1; 1.175 + } 1.176 + 1.177 + /** 1.178 + * @return the Binding for this Parameter 1.179 + */ 1.180 + public ParameterBinding getBinding() { 1.181 + if(binding == null) 1.182 + return ParameterBinding.BODY; 1.183 + return binding; 1.184 + } 1.185 + 1.186 + /** 1.187 + * @param binding 1.188 + */ 1.189 + public void setBinding(ParameterBinding binding) { 1.190 + this.binding = binding; 1.191 + } 1.192 + 1.193 + public void setInBinding(ParameterBinding binding){ 1.194 + this.binding = binding; 1.195 + } 1.196 + 1.197 + public void setOutBinding(ParameterBinding binding){ 1.198 + this.outBinding = binding; 1.199 + } 1.200 + 1.201 + public ParameterBinding getInBinding(){ 1.202 + return binding; 1.203 + } 1.204 + 1.205 + public ParameterBinding getOutBinding(){ 1.206 + if(outBinding == null) 1.207 + return binding; 1.208 + return outBinding; 1.209 + } 1.210 + 1.211 + public boolean isIN() { 1.212 + return mode==Mode.IN; 1.213 + } 1.214 + 1.215 + public boolean isOUT() { 1.216 + return mode==Mode.OUT; 1.217 + } 1.218 + 1.219 + public boolean isINOUT() { 1.220 + return mode==Mode.INOUT; 1.221 + } 1.222 + 1.223 + /** 1.224 + * If true, this parameter maps to the return value of a method invocation. 1.225 + * 1.226 + * <p> 1.227 + * {@link JavaMethodImpl#getResponseParameters()} is guaranteed to have 1.228 + * at most one such {@link ParameterImpl}. Note that there coule be none, 1.229 + * in which case the method returns <tt>void</tt>. 1.230 + */ 1.231 + public boolean isResponse() { 1.232 + return index == -1; 1.233 + } 1.234 + 1.235 + 1.236 + /** 1.237 + * Gets the holder value if applicable. To be called for inbound client side 1.238 + * message. 1.239 + * 1.240 + * @param obj 1.241 + * @return the holder value if applicable. 1.242 + */ 1.243 + public Object getHolderValue(Object obj) { 1.244 + if (obj != null && obj instanceof Holder) 1.245 + return ((Holder) obj).value; 1.246 + return obj; 1.247 + } 1.248 + 1.249 + public String getPartName() { 1.250 + if(partName == null) 1.251 + return name.getLocalPart(); 1.252 + return partName; 1.253 + } 1.254 + 1.255 + public void setPartName(String partName) { 1.256 + this.partName = partName; 1.257 + } 1.258 + 1.259 + void fillTypes(List<TypeInfo> types) { 1.260 + TypeInfo itemType = getItemType(); 1.261 + types.add((itemType != null) ? itemType : getTypeInfo()); 1.262 + } 1.263 +}