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: package org.apache.axis2.jaxws.runtime.description.marshal.impl;
020:
021: import org.apache.axis2.jaxws.ExceptionFactory;
022: import org.apache.axis2.jaxws.description.FaultDescription;
023: import org.apache.axis2.jaxws.description.OperationDescription;
024: import org.apache.axis2.jaxws.description.ServiceDescription;
025: import org.apache.axis2.jaxws.message.factory.MessageFactory;
026: import org.apache.axis2.jaxws.registry.FactoryRegistry;
027: import org.apache.axis2.jaxws.runtime.description.marshal.AnnotationDesc;
028: import org.apache.axis2.jaxws.runtime.description.marshal.FaultBeanDesc;
029: import org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription;
030: import org.apache.axis2.jaxws.utility.PropertyDescriptorPlus;
031: import org.apache.axis2.jaxws.utility.XMLRootElementUtil;
032:
033: import java.util.Map;
034: import java.util.Map.Entry;
035: import java.util.TreeSet;
036:
037: public class MarshalServiceRuntimeDescriptionImpl implements
038: MarshalServiceRuntimeDescription {
039:
040: private ServiceDescription serviceDesc;
041: private String key;
042: private TreeSet<String> packages;
043: private String packagesKey;
044: private Map<String, AnnotationDesc> annotationMap = null;
045: private Map<Class, Map<String, PropertyDescriptorPlus>> pdMapCache = null;
046: private Map<OperationDescription, String> requestWrapperMap = null;
047: private Map<OperationDescription, String> responseWrapperMap = null;
048: private Map<FaultDescription, FaultBeanDesc> faultBeanDescMap = null;
049: private MessageFactory messageFactory = (MessageFactory) FactoryRegistry
050: .getFactory(MessageFactory.class);
051:
052: protected MarshalServiceRuntimeDescriptionImpl(String key,
053: ServiceDescription serviceDesc) {
054: this .serviceDesc = serviceDesc;
055: this .key = key;
056: }
057:
058: public ServiceDescription getServiceDescription() {
059: return serviceDesc;
060: }
061:
062: public String getKey() {
063: return key;
064: }
065:
066: public TreeSet<String> getPackages() {
067: return packages;
068: }
069:
070: public String getPackagesKey() {
071: return packagesKey;
072: }
073:
074: void setPackages(TreeSet<String> packages) {
075: this .packages = packages;
076: this .packagesKey = packages.toString(); // Unique key for searches
077: }
078:
079: public AnnotationDesc getAnnotationDesc(Class cls) {
080: String className = cls.getCanonicalName();
081: AnnotationDesc aDesc = annotationMap.get(className);
082: if (aDesc != null) {
083: // Cache hit
084: return aDesc;
085: }
086: // Cache miss...we cannot update the map because we don't want to introduce a sync call.
087: aDesc = AnnotationDescImpl.create(cls);
088:
089: return aDesc;
090: }
091:
092: void setAnnotationMap(Map<String, AnnotationDesc> map) {
093: this .annotationMap = map;
094: }
095:
096: public Map<String, PropertyDescriptorPlus> getPropertyDescriptorMap(
097: Class cls) {
098: // We are caching by class.
099: Map<String, PropertyDescriptorPlus> pdMap = pdMapCache.get(cls);
100: if (pdMap != null) {
101: // Cache hit
102: return pdMap;
103: }
104:
105: // Cache miss...this can occur if the classloader changed.
106: // We cannot add this new pdMap at this point due to sync issues.
107: try {
108: pdMap = XMLRootElementUtil.createPropertyDescriptorMap(cls);
109: } catch (Throwable t) {
110: ExceptionFactory.makeWebServiceException(t);
111: }
112: return pdMap;
113: }
114:
115: void setPropertyDescriptorMapCache(
116: Map<Class, Map<String, PropertyDescriptorPlus>> cache) {
117: this .pdMapCache = cache;
118: }
119:
120: public String getRequestWrapperClassName(
121: OperationDescription operationDesc) {
122: return requestWrapperMap.get(operationDesc);
123: }
124:
125: void setRequestWrapperMap(Map<OperationDescription, String> map) {
126: requestWrapperMap = map;
127: }
128:
129: public String getResponseWrapperClassName(
130: OperationDescription operationDesc) {
131: return responseWrapperMap.get(operationDesc);
132: }
133:
134: void setResponseWrapperMap(Map<OperationDescription, String> map) {
135: responseWrapperMap = map;
136: }
137:
138: public FaultBeanDesc getFaultBeanDesc(FaultDescription faultDesc) {
139: return faultBeanDescMap.get(faultDesc);
140: }
141:
142: void setFaultBeanDescMap(Map<FaultDescription, FaultBeanDesc> map) {
143: faultBeanDescMap = map;
144: }
145:
146: public String toString() {
147: final String newline = "\n";
148: final String sameline = " ";
149: StringBuffer string = new StringBuffer();
150:
151: string.append(newline);
152: string.append(" MarshalServiceRuntime:" + getKey());
153: string.append(newline);
154: string.append(" Packages = " + getPackages().toString());
155:
156: for (Entry<String, AnnotationDesc> entry : this .annotationMap
157: .entrySet()) {
158: string.append(newline);
159: string.append(" AnnotationDesc cached for:"
160: + entry.getKey());
161: string.append(entry.getValue().toString());
162: }
163:
164: for (Entry<Class, Map<String, PropertyDescriptorPlus>> entry : this .pdMapCache
165: .entrySet()) {
166: string.append(newline);
167: string.append(" PropertyDescriptorPlus Map cached for:"
168: + entry.getKey().getCanonicalName());
169: for (PropertyDescriptorPlus pdp : entry.getValue().values()) {
170: string.append(newline);
171: string.append(" propertyName ="
172: + pdp.getPropertyName());
173: string.append(newline);
174: string.append(" xmlName ="
175: + pdp.getXmlName());
176: string.append(newline);
177: string.append(" propertyType ="
178: + pdp.getPropertyType().getCanonicalName());
179: string.append(newline);
180: }
181: }
182:
183: string.append(" RequestWrappers");
184: for (Entry<OperationDescription, String> entry : this .requestWrapperMap
185: .entrySet()) {
186: string.append(newline);
187: string.append(" Operation:"
188: + entry.getKey().getJavaMethodName()
189: + " RequestWrapper:" + entry.getValue());
190: }
191:
192: string.append(" ResponseWrappers");
193: for (Entry<OperationDescription, String> entry : this .responseWrapperMap
194: .entrySet()) {
195: string.append(newline);
196: string.append(" Operation:"
197: + entry.getKey().getJavaMethodName()
198: + " ResponseWrapper:" + entry.getValue());
199: }
200:
201: string.append(" FaultBeanDesc");
202: for (Entry<FaultDescription, FaultBeanDesc> entry : this .faultBeanDescMap
203: .entrySet()) {
204: string.append(newline);
205: string.append(" FaultException:"
206: + entry.getKey().getExceptionClassName());
207: string.append(newline);
208: string.append(entry.getValue().toString());
209: }
210:
211: return string.toString();
212: }
213:
214: public MessageFactory getMessageFactory() {
215: return messageFactory;
216: }
217:
218: }
|