001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.xml.internal.ws.model;
027:
028: import com.sun.xml.internal.bind.api.TypeReference;
029:
030: import javax.xml.namespace.QName;
031: import javax.xml.ws.Holder;
032:
033: /**
034: * runtime Parameter that abstracts the annotated java parameter
035: *
036: * @author Vivek Pandey
037: */
038:
039: public class Parameter {
040: /**
041: *
042: */
043: public Parameter(TypeReference type, Mode mode, int index) {
044: this .typeReference = type;
045: this .name = type.tagName;
046: this .mode = mode;
047: this .index = index;
048: }
049:
050: /**
051: * @return Returns the name.
052: */
053: public QName getName() {
054: return name;
055: }
056:
057: /**
058: * @return Returns the TypeReference associated with this Parameter
059: */
060: public TypeReference getTypeReference() {
061: return typeReference;
062: }
063:
064: /**
065: * Sometimes we need to overwrite the typeReferenc, such as during patching for rpclit
066: * @see RuntimeModel#applyParameterBinding(com.sun.xml.internal.ws.wsdl.parser.Binding)
067: */
068:
069: void setTypeReference(TypeReference type) {
070: typeReference = type;
071: name = type.tagName;
072: }
073:
074: /**
075: * @return Returns the mode.
076: */
077: public Mode getMode() {
078: return mode;
079: }
080:
081: /**
082: * @return Returns the index.
083: */
084: public int getIndex() {
085: return index;
086: }
087:
088: /**
089: * @return WrapperStyle == true
090: */
091: public boolean isWrapperStyle() {
092: return false;
093: }
094:
095: /**
096: * @return the Binding for this Parameter
097: */
098: public ParameterBinding getBinding() {
099: if (binding == null)
100: return ParameterBinding.BODY;
101: return binding;
102: }
103:
104: /**
105: * @param binding
106: */
107: public void setBinding(ParameterBinding binding) {
108: this .binding = binding;
109: }
110:
111: public void setInBinding(ParameterBinding binding) {
112: this .binding = binding;
113: }
114:
115: public void setOutBinding(ParameterBinding binding) {
116: this .outBinding = binding;
117: }
118:
119: public ParameterBinding getInBinding() {
120: return binding;
121: }
122:
123: public ParameterBinding getOutBinding() {
124: if (outBinding == null)
125: return binding;
126: return outBinding;
127: }
128:
129: public boolean isIN() {
130: return mode == Mode.IN;
131: }
132:
133: public boolean isOUT() {
134: return mode == Mode.OUT;
135: }
136:
137: public boolean isINOUT() {
138: return mode == Mode.INOUT;
139: }
140:
141: public boolean isResponse() {
142: return index == -1;
143: }
144:
145: /**
146: * Creates a holder if applicable else gives the object as it is. To be
147: * called on the inbound message.
148: *
149: * @param value
150: * @return the non-holder value if its Response or IN otherwise creates a
151: * holder with the passed value and returns it back.
152: *
153: */
154: public Object createHolderValue(Object value) {
155: if (isResponse() || isIN()) {
156: return value;
157: }
158: return new Holder(value);
159: }
160:
161: /**
162: * Gets the holder value if applicable. To be called for inbound client side
163: * message.
164: *
165: * @param obj
166: * @return the holder value if applicable.
167: */
168: public Object getHolderValue(Object obj) {
169: if (obj != null && obj instanceof Holder)
170: return ((Holder) obj).value;
171: return obj;
172: }
173:
174: public static void setHolderValue(Object obj, Object value) {
175: if (obj instanceof Holder)
176: ((Holder) obj).value = value;
177: else
178: // TODO: this can't be correct
179: obj = value;
180: }
181:
182: public String getPartName() {
183: if (partName == null)
184: return name.getLocalPart();
185: return partName;
186: }
187:
188: public void setPartName(String partName) {
189: this .partName = partName;
190: }
191:
192: protected ParameterBinding binding;
193: protected ParameterBinding outBinding;
194: protected int index;
195: protected Mode mode;
196: protected TypeReference typeReference;
197: protected QName name;
198: protected String partName;
199: }
|