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: package com.sun.xml.internal.ws.model;
026:
027: import java.lang.reflect.Method;
028: import java.util.ArrayList;
029: import java.util.Collections;
030: import java.util.List;
031:
032: import com.sun.xml.internal.bind.api.TypeReference;
033: import com.sun.xml.internal.ws.model.soap.SOAPBinding;
034: import com.sun.xml.internal.ws.pept.presentation.MessageStruct;
035:
036: /**
037: * Build this runtime model using java SEI and annotations
038: *
039: * @author Vivek Pandey
040: */
041: public class JavaMethod {
042: /**
043: *
044: */
045: public JavaMethod(Method method) {
046: this .method = method;
047: }
048:
049: /**
050: * @return Returns the method.
051: */
052: public Method getMethod() {
053: return method;
054: }
055:
056: /**
057: * @return Returns the mep.
058: */
059: public int getMEP() {
060: return mep;
061: }
062:
063: /**
064: * @param mep
065: * The mep to set.
066: */
067: public void setMEP(int mep) {
068: this .mep = mep;
069: }
070:
071: /**
072: * @return the Binding object
073: */
074: public Object getBinding() {
075: if (binding == null)
076: return new SOAPBinding();
077: return binding;
078: }
079:
080: /**
081: * @param binding
082: */
083: public void setBinding(Object binding) {
084: this .binding = binding;
085: }
086:
087: public void setOperationName(String operationName) {
088: this .operationName = operationName;
089: }
090:
091: public String getOperationName() {
092: return operationName;
093: }
094:
095: /**
096: * @return returns unmodifiable list of request parameters
097: */
098: public List<Parameter> getRequestParameters() {
099: return unmReqParams;
100: }
101:
102: /**
103: * @return returns unmodifiable list of response parameters
104: */
105: public List<Parameter> getResponseParameters() {
106: return unmResParams;
107: }
108:
109: /**
110: * @param p
111: */
112: public void addParameter(Parameter p) {
113: if (p.isIN() || p.isINOUT()) {
114: if (requestParams.contains(p)) {
115: // TODO throw exception
116: }
117: requestParams.add(p);
118: }
119:
120: if (p.isOUT() || p.isINOUT()) {
121: // this check is only for out parameters
122: if (requestParams.contains(p)) {
123: // TODO throw exception
124: }
125: responseParams.add(p);
126: }
127: }
128:
129: public void addRequestParameter(Parameter p) {
130: if (p.isIN() || p.isINOUT()) {
131: requestParams.add(p);
132: }
133: }
134:
135: public void addResponseParameter(Parameter p) {
136: if (p.isOUT() || p.isINOUT()) {
137: responseParams.add(p);
138: }
139: }
140:
141: /**
142: * @return Returns number of java method parameters - that will be all the
143: * IN, INOUT and OUT holders
144: */
145: public int getInputParametersCount() {
146: int count = 0;
147: for (Parameter param : requestParams) {
148: if (param.isWrapperStyle()) {
149: count += ((WrapperParameter) param)
150: .getWrapperChildren().size();
151: } else {
152: count++;
153: }
154: }
155:
156: for (Parameter param : responseParams) {
157: if (param.isWrapperStyle()) {
158: for (Parameter wc : ((WrapperParameter) param)
159: .getWrapperChildren()) {
160: if (!wc.isResponse() && wc.isOUT()) {
161: count++;
162: }
163: }
164: } else if (!param.isResponse() && param.isOUT()) {
165: count++;
166: }
167: }
168:
169: return count;
170: }
171:
172: /**
173: * @param ce
174: */
175: public void addException(CheckedException ce) {
176: if (!exceptions.contains(ce))
177: exceptions.add(ce);
178: }
179:
180: /**
181: * @param exceptionClass
182: * @return CheckedException corresponding to the exceptionClass. Returns
183: * null if not found.
184: */
185: public CheckedException getCheckedException(Class exceptionClass) {
186: for (CheckedException ce : exceptions) {
187: if (ce.getExcpetionClass().equals(exceptionClass))
188: return ce;
189: }
190: return null;
191: }
192:
193: /**
194: * @return a list of checked Exceptions thrown by this method
195: */
196: public List<CheckedException> getCheckedExceptions() {
197: return Collections.unmodifiableList(exceptions);
198: }
199:
200: /**
201: * @param detailType
202: * @return Gets the CheckedException corresponding to detailType. Returns
203: * null if no CheckedExcpetion with the detailType found.
204: */
205: public CheckedException getCheckedException(TypeReference detailType) {
206: for (CheckedException ce : exceptions) {
207: TypeReference actual = ce.getDetailType();
208: if (actual.tagName.equals(detailType.tagName)
209: && actual.type.getClass().getName().equals(
210: detailType.type.getClass().getName())) {
211: return ce;
212: }
213: }
214: return null;
215: }
216:
217: /**
218: * Returns if the java method MEP is async
219: * @return if this is an Asynch MEP
220: */
221: public boolean isAsync() {
222: return mep == MessageStruct.ASYNC_CALLBACK_MEP
223: || mep == MessageStruct.ASYNC_POLL_MEP;
224: }
225:
226: private List<CheckedException> exceptions = new ArrayList<CheckedException>();
227: private Method method;
228: private final List<Parameter> requestParams = new ArrayList<Parameter>();
229: private final List<Parameter> responseParams = new ArrayList<Parameter>();
230: private final List<Parameter> unmReqParams = Collections
231: .unmodifiableList(requestParams);
232: private final List<Parameter> unmResParams = Collections
233: .unmodifiableList(responseParams);
234: private Object binding;
235: private int mep;
236: private String operationName;
237: }
|