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.ServiceDescription;
023: import org.apache.axis2.jaxws.runtime.description.marshal.AnnotationDesc;
024: import org.apache.axis2.jaxws.runtime.description.marshal.MarshalServiceRuntimeDescription;
025: import org.apache.axis2.jaxws.utility.PropertyDescriptorPlus;
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028:
029: import java.util.HashMap;
030: import java.util.Map;
031: import java.util.TreeSet;
032:
033: public class MarshalServiceRuntimeDescriptionBuilder {
034:
035: private static Log log = LogFactory
036: .getLog(MarshalServiceRuntimeDescriptionBuilder.class);
037:
038: /** Intentionally Private */
039: private MarshalServiceRuntimeDescriptionBuilder() {
040: }
041:
042: /**
043: * create
044: *
045: * @param opDesc
046: * @param implClassName
047: * @return
048: */
049: static public MarshalServiceRuntimeDescription create(
050: ServiceDescription serviceDesc) {
051: MarshalServiceRuntimeDescriptionImpl desc = new MarshalServiceRuntimeDescriptionImpl(
052: getKey(), serviceDesc);
053: init(desc, serviceDesc);
054: return desc;
055: }
056:
057: static public String getKey() {
058: return "JAXWS-MARSHAL";
059: }
060:
061: /**
062: * @param implClass
063: * @return true if Field or Method has a @Resource annotation
064: */
065: static private void init(
066: MarshalServiceRuntimeDescriptionImpl marshalDesc,
067: ServiceDescription serviceDesc) {
068:
069: // Artifact class discovery/builder
070: ArtifactProcessor artifactProcessor = new ArtifactProcessor(
071: serviceDesc);
072: try {
073: artifactProcessor.build();
074: } catch (Throwable t) {
075: ExceptionFactory.makeWebServiceException(t);
076: }
077: marshalDesc.setRequestWrapperMap(artifactProcessor
078: .getRequestWrapperMap());
079: marshalDesc.setResponseWrapperMap(artifactProcessor
080: .getResponseWrapperMap());
081: marshalDesc.setFaultBeanDescMap(artifactProcessor
082: .getFaultBeanDescMap());
083:
084: // Build the annotation map
085: Map<String, AnnotationDesc> map;
086: try {
087: map = AnnotationBuilder.getAnnotationDescs(serviceDesc,
088: artifactProcessor);
089: } catch (Throwable t) {
090: // Since we are building a cache, proceed without exception
091: if (log.isDebugEnabled()) {
092: log
093: .debug("Exception occurred during cache processing. This will impact performance:"
094: + t);
095: }
096: map = new HashMap<String, AnnotationDesc>();
097: }
098: marshalDesc.setAnnotationMap(map);
099:
100: // Build the property descriptor map
101: Map<Class, Map<String, PropertyDescriptorPlus>> cache;
102: try {
103: cache = PropertyDescriptorMapBuilder.getPropertyDescMaps(
104: serviceDesc, artifactProcessor);
105: } catch (Throwable t) {
106: // Since we are building a cache, proceed without exception
107: if (log.isDebugEnabled()) {
108: log
109: .debug("Exception occurred during cache processing. This will impact performance:"
110: + t);
111: }
112: cache = new HashMap<Class, Map<String, PropertyDescriptorPlus>>();
113: }
114: marshalDesc.setPropertyDescriptorMapCache(cache);
115:
116: // @TODO There are two ways to get the packages.
117: // Schema Walk (prefered) and Annotation Walk.
118: // The Schema walk requires an existing or generated schema.
119: //
120: // There are some limitations in the current schema walk
121: // And there are problems in the annotation walk.
122: // So for now we will do both.
123: TreeSet<String> packages = new TreeSet<String>();
124: boolean doSchemaWalk = true;
125: boolean doAnnotationWalk = true;
126: packages = new TreeSet<String>();
127: if (doSchemaWalk) {
128: packages.addAll(PackageSetBuilder
129: .getPackagesFromSchema(serviceDesc));
130: }
131: if (doAnnotationWalk) {
132: // Get the package names from the annotations. Use the annotation map to reduce Annotation introspection
133: packages.addAll(PackageSetBuilder
134: .getPackagesFromAnnotations(serviceDesc,
135: marshalDesc));
136: }
137: marshalDesc.setPackages(packages);
138: }
139: }
|