ohair@286: /* alanb@368: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. ohair@286: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@286: * ohair@286: * This code is free software; you can redistribute it and/or modify it ohair@286: * under the terms of the GNU General Public License version 2 only, as ohair@286: * published by the Free Software Foundation. Oracle designates this ohair@286: * particular file as subject to the "Classpath" exception as provided ohair@286: * by Oracle in the LICENSE file that accompanied this code. ohair@286: * ohair@286: * This code is distributed in the hope that it will be useful, but WITHOUT ohair@286: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@286: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@286: * version 2 for more details (a copy is included in the LICENSE file that ohair@286: * accompanied this code). ohair@286: * ohair@286: * You should have received a copy of the GNU General Public License version ohair@286: * 2 along with this work; if not, write to the Free Software Foundation, ohair@286: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@286: * ohair@286: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@286: * or visit www.oracle.com if you need additional information or have any ohair@286: * questions. ohair@286: */ ohair@286: ohair@286: package com.sun.xml.internal.ws.model; ohair@286: ohair@286: import com.sun.xml.internal.bind.api.Bridge; ohair@286: import com.sun.xml.internal.bind.api.TypeReference; ohair@286: import com.sun.xml.internal.ws.api.model.JavaMethod; ohair@286: import com.sun.xml.internal.ws.api.model.Parameter; ohair@286: import com.sun.xml.internal.ws.api.model.ParameterBinding; alanb@368: import com.sun.xml.internal.ws.spi.db.RepeatedElementBridge; alanb@368: import com.sun.xml.internal.ws.spi.db.WrapperComposite; ohair@286: import com.sun.xml.internal.ws.spi.db.XMLBridge; ohair@286: import com.sun.xml.internal.ws.spi.db.TypeInfo; ohair@286: ohair@286: import javax.jws.WebParam.Mode; ohair@286: import javax.xml.namespace.QName; ohair@286: import javax.xml.ws.Holder; ohair@286: import java.util.List; ohair@286: ohair@286: /** ohair@286: * runtime Parameter that abstracts the annotated java parameter ohair@286: * ohair@286: *

ohair@286: * A parameter may be bound to a header, a body, or an attachment. ohair@286: * Note that when it's bound to a body, it's bound to a body, ohair@286: * it binds to the whole payload. ohair@286: * ohair@286: *

ohair@286: * Sometimes multiple Java parameters are packed into the payload, ohair@286: * in which case the subclass {@link WrapperParameter} is used. ohair@286: * ohair@286: * @author Vivek Pandey ohair@286: */ ohair@286: public class ParameterImpl implements Parameter { ohair@286: ohair@286: private ParameterBinding binding; ohair@286: private ParameterBinding outBinding; ohair@286: private String partName; ohair@286: private final int index; ohair@286: private final Mode mode; ohair@286: /** @deprecated */ ohair@286: private TypeReference typeReference; ohair@286: private TypeInfo typeInfo; ohair@286: private QName name; ohair@286: private final JavaMethodImpl parent; ohair@286: alanb@368: WrapperParameter wrapper; alanb@368: TypeInfo itemTypeInfo; alanb@368: ohair@286: public ParameterImpl(JavaMethodImpl parent, TypeInfo type, Mode mode, int index) { ohair@286: assert type != null; ohair@286: ohair@286: this.typeInfo = type; ohair@286: this.name = type.tagName; ohair@286: this.mode = mode; ohair@286: this.index = index; ohair@286: this.parent = parent; ohair@286: } ohair@286: ohair@286: public AbstractSEIModelImpl getOwner() { ohair@286: return parent.owner; ohair@286: } ohair@286: ohair@286: public JavaMethod getParent() { ohair@286: return parent; ohair@286: } ohair@286: ohair@286: /** ohair@286: * @return Returns the name. ohair@286: */ ohair@286: public QName getName() { ohair@286: return name; ohair@286: } ohair@286: ohair@286: public XMLBridge getXMLBridge() { ohair@286: return getOwner().getXMLBridge(typeInfo); ohair@286: } ohair@286: alanb@368: public XMLBridge getInlinedRepeatedElementBridge() { alanb@368: TypeInfo itemType = getItemType(); alanb@368: if (itemType != null) { alanb@368: XMLBridge xb = getOwner().getXMLBridge(itemType); alanb@368: if (xb != null) return new RepeatedElementBridge(typeInfo, xb); alanb@368: } alanb@368: return null; alanb@368: } alanb@368: alanb@368: public TypeInfo getItemType() { alanb@368: if (itemTypeInfo != null) return itemTypeInfo; alanb@368: //RpcLit cannot inline repeated element in wrapper alanb@368: if (parent.getBinding().isRpcLit() || wrapper == null) return null; alanb@368: //InlinedRepeatedElementBridge is only used for dynamic wrapper (no wrapper class) alanb@368: if (!WrapperComposite.class.equals(wrapper.getTypeInfo().type)) return null; alanb@368: if (!getBinding().isBody()) return null; alanb@368: itemTypeInfo = typeInfo.getItemType(); alanb@368: return itemTypeInfo; alanb@368: } alanb@368: ohair@286: /** @deprecated */ ohair@286: public Bridge getBridge() { ohair@286: return getOwner().getBridge(typeReference); ohair@286: } ohair@286: /** @deprecated */ ohair@286: protected Bridge getBridge(TypeReference typeRef) { ohair@286: return getOwner().getBridge(typeRef); ohair@286: } ohair@286: ohair@286: /** ohair@286: * TODO: once the model gets JAXBContext, shouldn't {@link Bridge}s ohair@286: * be made available from model objects? ohair@286: * @deprecated use getTypeInfo ohair@286: * @return Returns the TypeReference associated with this Parameter ohair@286: */ ohair@286: public TypeReference getTypeReference() { ohair@286: return typeReference; ohair@286: } ohair@286: public TypeInfo getTypeInfo() { ohair@286: return typeInfo; ohair@286: } ohair@286: ohair@286: /** ohair@286: * Sometimes we need to overwrite the typeReferenc, such as during patching for rpclit alanb@368: * @see AbstractSEIModelImpl#applyRpcLitParamBinding(JavaMethodImpl, WrapperParameter, WSDLBoundPortType, WebParam.Mode) ohair@286: * @deprecated ohair@286: */ ohair@286: void setTypeReference(TypeReference type){ ohair@286: typeReference = type; ohair@286: name = type.tagName; ohair@286: } ohair@286: ohair@286: ohair@286: public Mode getMode() { ohair@286: return mode; ohair@286: } ohair@286: ohair@286: public int getIndex() { ohair@286: return index; ohair@286: } ohair@286: ohair@286: /** ohair@286: * @return true if this instanceof {@link WrapperParameter}. ohair@286: */ ohair@286: public boolean isWrapperStyle() { ohair@286: return false; ohair@286: } ohair@286: ohair@286: public boolean isReturnValue() { ohair@286: return index==-1; ohair@286: } ohair@286: ohair@286: /** ohair@286: * @return the Binding for this Parameter ohair@286: */ ohair@286: public ParameterBinding getBinding() { ohair@286: if(binding == null) ohair@286: return ParameterBinding.BODY; ohair@286: return binding; ohair@286: } ohair@286: ohair@286: /** ohair@286: * @param binding ohair@286: */ ohair@286: public void setBinding(ParameterBinding binding) { ohair@286: this.binding = binding; ohair@286: } ohair@286: ohair@286: public void setInBinding(ParameterBinding binding){ ohair@286: this.binding = binding; ohair@286: } ohair@286: ohair@286: public void setOutBinding(ParameterBinding binding){ ohair@286: this.outBinding = binding; ohair@286: } ohair@286: ohair@286: public ParameterBinding getInBinding(){ ohair@286: return binding; ohair@286: } ohair@286: ohair@286: public ParameterBinding getOutBinding(){ ohair@286: if(outBinding == null) ohair@286: return binding; ohair@286: return outBinding; ohair@286: } ohair@286: ohair@286: public boolean isIN() { ohair@286: return mode==Mode.IN; ohair@286: } ohair@286: ohair@286: public boolean isOUT() { ohair@286: return mode==Mode.OUT; ohair@286: } ohair@286: ohair@286: public boolean isINOUT() { ohair@286: return mode==Mode.INOUT; ohair@286: } ohair@286: ohair@286: /** ohair@286: * If true, this parameter maps to the return value of a method invocation. ohair@286: * ohair@286: *

ohair@286: * {@link JavaMethodImpl#getResponseParameters()} is guaranteed to have ohair@286: * at most one such {@link ParameterImpl}. Note that there coule be none, ohair@286: * in which case the method returns void. ohair@286: */ ohair@286: public boolean isResponse() { ohair@286: return index == -1; ohair@286: } ohair@286: ohair@286: ohair@286: /** ohair@286: * Gets the holder value if applicable. To be called for inbound client side ohair@286: * message. ohair@286: * ohair@286: * @param obj ohair@286: * @return the holder value if applicable. ohair@286: */ ohair@286: public Object getHolderValue(Object obj) { ohair@286: if (obj != null && obj instanceof Holder) ohair@286: return ((Holder) obj).value; ohair@286: return obj; ohair@286: } ohair@286: ohair@286: public String getPartName() { ohair@286: if(partName == null) ohair@286: return name.getLocalPart(); ohair@286: return partName; ohair@286: } ohair@286: ohair@286: public void setPartName(String partName) { ohair@286: this.partName = partName; ohair@286: } ohair@286: ohair@286: void fillTypes(List types) { alanb@368: TypeInfo itemType = getItemType(); alanb@368: types.add((itemType != null) ? itemType : getTypeInfo()); ohair@286: } ohair@286: }