001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    package org.apache.geronimo.axis2.client;
019    
020    import java.net.URI;
021    import java.util.Map;
022    
023    import javax.xml.namespace.QName;
024    import javax.xml.ws.handler.HandlerResolver;
025    
026    import org.apache.axis2.jaxws.context.WebServiceContextImpl;
027    import org.apache.commons.logging.Log;
028    import org.apache.commons.logging.LogFactory;
029    import org.apache.geronimo.axis2.Axis2HandlerResolver;
030    import org.apache.geronimo.gbean.AbstractName;
031    import org.apache.geronimo.jaxws.JAXWSAnnotationProcessor;
032    import org.apache.geronimo.jaxws.JNDIResolver;
033    import org.apache.geronimo.jaxws.client.EndpointInfo;
034    import org.apache.geronimo.jaxws.client.JAXWSServiceReference;
035    import org.apache.geronimo.jaxws.client.PortMethodInterceptor;
036    import org.apache.geronimo.xbeans.javaee.HandlerChainsDocument;
037    import org.apache.geronimo.xbeans.javaee.HandlerChainsType;
038    import org.apache.xmlbeans.XmlException;
039    
040    /**
041     * @version $Rev$ $Date$
042     */
043    public class Axis2ServiceReference extends JAXWSServiceReference {
044    
045        private static final Log LOG = LogFactory.getLog(Axis2ServiceReference.class);
046    
047        public Axis2ServiceReference(String serviceClassName,
048                                     String referenceClassName,
049                                     URI wsdlURI,
050                                     QName serviceQName,
051                                     AbstractName name,
052                                     String handlerChainsXML,
053                                     Map<Object, EndpointInfo> seiInfoMap) {
054            super(handlerChainsXML, seiInfoMap, name, serviceQName, wsdlURI, referenceClassName, serviceClassName);
055        }
056    
057        protected HandlerResolver getHandlerResolver(Class serviceClass) {
058            HandlerChainsType types = null;
059            try {
060                if (this.handlerChainsXML != null){
061                    try {
062                        types = HandlerChainsDocument.Factory.parse(this.handlerChainsXML).getHandlerChains();
063                    } catch (XmlException e){
064                        types = HandlerChainsType.Factory.parse(this.handlerChainsXML);
065                    }
066                }
067            } catch (Exception e) {
068                LOG.warn("Failed to deserialize handler chains", e);
069            }
070            JAXWSAnnotationProcessor annotationProcessor =
071                    new JAXWSAnnotationProcessor(new JNDIResolver(), new WebServiceContextImpl());
072            Axis2HandlerResolver handlerResolver =
073                    new Axis2HandlerResolver(classLoader, serviceClass, types, annotationProcessor);
074            return handlerResolver;
075        }
076        
077        protected PortMethodInterceptor getPortMethodInterceptor() {
078            return new Axis2PortMethodInterceptor(this.seiInfoMap);
079        }
080        
081    }