001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: /**
021: *
022: */package org.apache.axis2.jaxws.description.builder;
023:
024: public class ParameterDescriptionComposite {
025: private String parameterType;
026: private Class parameterTypeClass;
027: private WebParamAnnot webParamAnnot;
028: private WebServiceRefAnnot webServiceRefAnnot;
029: private WebServiceContextAnnot webServiceContextAnnot;
030: private int listOrder;
031: // Will indicate whether or not we found an @XMLList annotation on the parameter
032: private boolean isListType;
033:
034: private MethodDescriptionComposite parentMDC;
035:
036: public ParameterDescriptionComposite() {
037:
038: }
039:
040: public ParameterDescriptionComposite(String parameterType,
041: Class parameterTypeClass, WebParamAnnot webParamAnnot,
042: WebServiceRefAnnot webServiceRefAnnot,
043: WebServiceContextAnnot webServiceContextAnnot) {
044:
045: this .parameterType = parameterType;
046: this .parameterTypeClass = parameterTypeClass;
047: this .webParamAnnot = webParamAnnot;
048: this .webServiceRefAnnot = webServiceRefAnnot;
049: this .webServiceContextAnnot = webServiceContextAnnot;
050: }
051:
052: /**
053: * Returns the String descrbing this Parameter type. Note that this string is unparsed. For
054: * example, if it represents a java.util.List<my.package.Foo>, then that excact string will be
055: * returned, i.e. "java.util.List<my.package.Foo>". You can use other methods to retrieve parsed
056: * values for Generics and Holders. For example, getParameterTypeClass(), getRawType(),
057: * getHolderActualType(), and getHolderActualTypeClass().
058: *
059: * @return Returns the parameterType.
060: */
061: public String getParameterType() {
062: return parameterType;
063: }
064:
065: /**
066: * Returns the class associated with the Parameter. Note that if this is a generic (including a
067: * JAXWS Holder<T>) then the class associated with the raw type is returned (i.e. Holder.class).
068: * <p/>
069: * For a JAX-WS Holder<T>, use getHolderActualType(...) to get the class associated with T.
070: *
071: * @return Returns the parameterTypeClass.
072: */
073: public Class getParameterTypeClass() {
074:
075: if (parameterTypeClass == null) {
076: if (getParameterType() != null) {
077: parameterTypeClass = DescriptionBuilderUtils
078: .getPrimitiveClass(getParameterType());
079: if (parameterTypeClass == null) {
080: // If this is a Generic, we need to load the class associated with the Raw Type,
081: // i.e. for JAX-WS Holder<Foo>, we want to load Holder. Othwerise, load the type directly.
082: String classToLoad = null;
083: if (DescriptionBuilderUtils
084: .getRawType(parameterType) != null) {
085: classToLoad = DescriptionBuilderUtils
086: .getRawType(parameterType);
087: } else {
088: classToLoad = parameterType;
089: }
090: parameterTypeClass = loadClassFromPDC(classToLoad);
091: }
092: }
093: }
094: return parameterTypeClass;
095: }
096:
097: /**
098: * For JAX-WS Holder<T>, returns the class associated with T. For non-JAX-WS Holders returns
099: * null.
100: */
101: public Class getHolderActualTypeClass() {
102: Class returnClass = null;
103:
104: if (DescriptionBuilderUtils.isHolderType(parameterType)) {
105: String classToLoad = DescriptionBuilderUtils
106: .getHolderActualType(parameterType);
107: returnClass = loadClassFromPDC(classToLoad);
108: }
109: return returnClass;
110: }
111:
112: private Class loadClassFromPDC(String classToLoad) {
113: Class returnClass = null;
114: ClassLoader classLoader = null;
115:
116: if (getMethodDescriptionCompositeRef() != null) {
117: if (getMethodDescriptionCompositeRef()
118: .getDescriptionBuilderCompositeRef() != null) {
119: classLoader = getMethodDescriptionCompositeRef()
120: .getDescriptionBuilderCompositeRef()
121: .getClassLoader();
122: }
123: }
124: returnClass = DescriptionBuilderUtils.loadClassFromComposite(
125: classToLoad, classLoader);
126: return returnClass;
127: }
128:
129: /** @return Returns the webParamAnnot. */
130: public WebParamAnnot getWebParamAnnot() {
131: return webParamAnnot;
132: }
133:
134: /** @return Returns the webServiceRefAnnot. */
135: public WebServiceRefAnnot getWebServiceRefAnnot() {
136: return webServiceRefAnnot;
137: }
138:
139: /** @return Returns the webServiceContextAnnot. */
140: public WebServiceContextAnnot getWebServiceContextAnnot() {
141: return webServiceContextAnnot;
142: }
143:
144: /** @return Returns the webServiceContextAnnot. */
145: public int getListOrder() {
146: return listOrder;
147: }
148:
149: /** @return Returns the parentMDC. */
150: public MethodDescriptionComposite getMethodDescriptionCompositeRef() {
151: return this .parentMDC;
152: }
153:
154: /** @param parameterType The parameterType to set. */
155: public void setParameterType(String parameterType) {
156: this .parameterType = parameterType;
157: }
158:
159: /** @param parameterTypeClass The parameterTypeClass to set. */
160: private void setParameterTypeClass(Class parameterTypeClass) {
161: this .parameterTypeClass = parameterTypeClass;
162: }
163:
164: /** @param webParamAnnot The webParamAnnot to set. */
165: public void setWebParamAnnot(WebParamAnnot webParamAnnot) {
166: this .webParamAnnot = webParamAnnot;
167: }
168:
169: /** @param webServiceRefAnnot The webServiceRefAnnot to set. */
170: public void setWebServiceRefAnnot(
171: WebServiceRefAnnot webServiceRefAnnot) {
172: this .webServiceRefAnnot = webServiceRefAnnot;
173: }
174:
175: /** @param webServiceContextAnnot The webServiceContextAnnot to set. */
176: public void setWebServiceContextAnnot(
177: WebServiceContextAnnot webServiceContextAnnot) {
178: this .webServiceContextAnnot = webServiceContextAnnot;
179: }
180:
181: /** @param webServiceContextAnnot The webServiceContextAnnot to set. */
182: public void setListOrder(int listOrder) {
183: this .listOrder = listOrder;
184: }
185:
186: /** @param mdc The parent MethodDescriptionComposite to set. */
187: public void setMethodDescriptionCompositeRef(
188: MethodDescriptionComposite mdc) {
189: this .parentMDC = mdc;
190: }
191:
192: public boolean compare(Object obj) {
193: if (obj instanceof ParameterDescriptionComposite) {
194: ParameterDescriptionComposite pdc = (ParameterDescriptionComposite) obj;
195: if (!(this .parameterType.equals(pdc.getParameterType()))) {
196: return false;
197: }
198: return true;
199: } else {
200: return super .equals(obj);
201: }
202: }
203:
204: public void setIsListType(boolean isListType) {
205: this .isListType = isListType;
206: }
207:
208: public boolean isListType() {
209: return isListType;
210: }
211:
212: /** Convenience method for unit testing. We will print all of the data members here. */
213: public String toString() {
214: StringBuffer sb = new StringBuffer();
215: final String newLine = "\n";
216: final String sameLine = "; ";
217: sb.append(super .toString());
218: sb.append(sameLine);
219: sb.append("ParameterType: " + parameterType);
220:
221: if (webParamAnnot != null) {
222: sb.append(newLine);
223: sb.append("WebParam: ");
224: sb.append(webParamAnnot.toString());
225: }
226:
227: if (webServiceRefAnnot != null) {
228: sb.append(newLine);
229: sb.append("WebServiceRef: ");
230: sb.append(webServiceRefAnnot.toString());
231: }
232: return sb.toString();
233: }
234:
235: public String getRawType() {
236: return DescriptionBuilderUtils.getRawType(parameterType);
237: }
238:
239: public String getHolderActualType() {
240: return DescriptionBuilderUtils
241: .getHolderActualType(parameterType);
242: }
243:
244: public boolean isHolderType() {
245: return DescriptionBuilderUtils.isHolderType(parameterType);
246: }
247:
248: }
|