001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.model;
038:
039: import com.sun.xml.bind.api.Bridge;
040: import com.sun.xml.bind.api.TypeReference;
041: import com.sun.xml.ws.api.model.JavaMethod;
042: import com.sun.xml.ws.api.model.Parameter;
043: import com.sun.xml.ws.api.model.ParameterBinding;
044:
045: import javax.jws.WebParam.Mode;
046: import javax.xml.namespace.QName;
047: import javax.xml.ws.Holder;
048: import java.util.List;
049:
050: /**
051: * runtime Parameter that abstracts the annotated java parameter
052: *
053: * <p>
054: * A parameter may be bound to a header, a body, or an attachment.
055: * Note that when it's bound to a body, it's bound to a body,
056: * it binds to the whole payload.
057: *
058: * <p>
059: * Sometimes multiple Java parameters are packed into the payload,
060: * in which case the subclass {@link WrapperParameter} is used.
061: *
062: * @author Vivek Pandey
063: */
064: public class ParameterImpl implements Parameter {
065:
066: private ParameterBinding binding;
067: private ParameterBinding outBinding;
068: private String partName;
069: private final int index;
070: private final Mode mode;
071: private TypeReference typeReference;
072: private QName name;
073: private final JavaMethodImpl parent;
074:
075: public ParameterImpl(JavaMethodImpl parent, TypeReference type,
076: Mode mode, int index) {
077: assert type != null;
078:
079: this .typeReference = type;
080: this .name = type.tagName;
081: this .mode = mode;
082: this .index = index;
083: this .parent = parent;
084: }
085:
086: //public ParameterImpl(TypeReference type, Mode mode, int index) {
087: // this(null, type, mode, index);
088: //}
089:
090: public AbstractSEIModelImpl getOwner() {
091: return parent.owner;
092: }
093:
094: public JavaMethod getParent() {
095: return parent;
096: }
097:
098: /**
099: * @return Returns the name.
100: */
101: public QName getName() {
102: return name;
103: }
104:
105: public Bridge getBridge() {
106: return getOwner().getBridge(typeReference);
107: }
108:
109: protected Bridge getBridge(TypeReference typeRef) {
110: return getOwner().getBridge(typeRef);
111: }
112:
113: /**
114: * TODO: once the model gets JAXBContext, shouldn't {@link Bridge}s
115: * be made available from model objects?
116: *
117: * @return Returns the TypeReference associated with this Parameter
118: */
119: public TypeReference getTypeReference() {
120: return typeReference;
121: }
122:
123: /**
124: * Sometimes we need to overwrite the typeReferenc, such as during patching for rpclit
125: * @see AbstractSEIModelImpl#applyParameterBinding(com.sun.xml.ws.model.wsdl.WSDLBoundPortTypeImpl)
126: */
127: void setTypeReference(TypeReference type) {
128: typeReference = type;
129: name = type.tagName;
130: }
131:
132: public Mode getMode() {
133: return mode;
134: }
135:
136: public int getIndex() {
137: return index;
138: }
139:
140: /**
141: * @return true if <tt>this instanceof {@link WrapperParameter}</tt>.
142: */
143: public boolean isWrapperStyle() {
144: return false;
145: }
146:
147: public boolean isReturnValue() {
148: return index == -1;
149: }
150:
151: /**
152: * @return the Binding for this Parameter
153: */
154: public ParameterBinding getBinding() {
155: if (binding == null)
156: return ParameterBinding.BODY;
157: return binding;
158: }
159:
160: /**
161: * @param binding
162: */
163: public void setBinding(ParameterBinding binding) {
164: this .binding = binding;
165: }
166:
167: public void setInBinding(ParameterBinding binding) {
168: this .binding = binding;
169: }
170:
171: public void setOutBinding(ParameterBinding binding) {
172: this .outBinding = binding;
173: }
174:
175: public ParameterBinding getInBinding() {
176: return binding;
177: }
178:
179: public ParameterBinding getOutBinding() {
180: if (outBinding == null)
181: return binding;
182: return outBinding;
183: }
184:
185: public boolean isIN() {
186: return mode == Mode.IN;
187: }
188:
189: public boolean isOUT() {
190: return mode == Mode.OUT;
191: }
192:
193: public boolean isINOUT() {
194: return mode == Mode.INOUT;
195: }
196:
197: /**
198: * If true, this parameter maps to the return value of a method invocation.
199: *
200: * <p>
201: * {@link JavaMethodImpl#getResponseParameters()} is guaranteed to have
202: * at most one such {@link ParameterImpl}. Note that there coule be none,
203: * in which case the method returns <tt>void</tt>.
204: */
205: public boolean isResponse() {
206: return index == -1;
207: }
208:
209: /**
210: * Creates a holder if applicable else gives the object as it is. To be
211: * called on the inbound message.
212: *
213: * @param value
214: * @return the non-holder value if its Response or IN otherwise creates a
215: * holder with the passed value and returns it back.
216: *
217: */
218: public Object createHolderValue(Object value) {
219: if (isResponse() || isIN()) {
220: return value;
221: }
222: return new Holder(value);
223: }
224:
225: /**
226: * Gets the holder value if applicable. To be called for inbound client side
227: * message.
228: *
229: * @param obj
230: * @return the holder value if applicable.
231: */
232: public Object getHolderValue(Object obj) {
233: if (obj != null && obj instanceof Holder)
234: return ((Holder) obj).value;
235: return obj;
236: }
237:
238: public static void setHolderValue(Object obj, Object value) {
239: if (obj instanceof Holder)
240: ((Holder) obj).value = value;
241: else
242: // TODO: this can't be correct
243: obj = value;
244: }
245:
246: public String getPartName() {
247: if (partName == null)
248: return name.getLocalPart();
249: return partName;
250: }
251:
252: public void setPartName(String partName) {
253: this .partName = partName;
254: }
255:
256: void fillTypes(List<TypeReference> types) {
257: types.add(getTypeReference());
258: }
259: }
|