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    package org.apache.geronimo.webservices.builder;
018    
019    import java.net.URI;
020    import java.net.URISyntaxException;
021    import java.util.Collections;
022    import java.util.HashMap;
023    import java.util.Map;
024    import java.util.jar.JarFile;
025    
026    import org.apache.geronimo.common.DeploymentException;
027    import org.apache.geronimo.xbeans.j2ee.JavaWsdlMappingType;
028    import org.apache.geronimo.xbeans.j2ee.ServiceEndpointInterfaceMappingType;
029    
030    /**
031     * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
032     */
033    public class SharedPortInfo {
034        
035        private String jaxrpcMappingFile;
036        private String wsdlLocation;
037        private JavaWsdlMappingType javaWsdlMapping;
038        private SchemaInfoBuilder schemaInfoBuilder;
039        private DescriptorVersion ddVersion;
040    
041        public SharedPortInfo(String wsdlLocation, String jaxrpcMappingFile) {
042            this(wsdlLocation, jaxrpcMappingFile, DescriptorVersion.UNKNOWN);
043        }
044        
045        public SharedPortInfo(String wsdlLocation, String jaxrpcMappingFile, DescriptorVersion ddVersion) {
046            this.wsdlLocation = wsdlLocation;
047            this.jaxrpcMappingFile = jaxrpcMappingFile;
048            this.ddVersion = ddVersion;
049        }
050    
051        public DescriptorVersion getDescriptorVersion() {
052            return this.ddVersion;
053        }
054        
055        public String getWsdlLocation() {
056            return this.wsdlLocation;
057        }
058        
059        public String getJaxrpcMappingFile() {
060            return this.jaxrpcMappingFile;
061        }
062        
063        public void initialize(JarFile moduleFile) throws DeploymentException {
064            if (this.jaxrpcMappingFile == null) {
065                throw new DeploymentException("JAX-RPC mapping file is required.");
066            }
067            if (this.wsdlLocation == null) {
068                throw new DeploymentException("WSDL file is required.");
069            }
070            
071            if (this.javaWsdlMapping == null) {
072                URI jaxrpcMappingURI;
073                try {
074                    jaxrpcMappingURI = new URI(this.jaxrpcMappingFile);
075                } catch (URISyntaxException e) {
076                    throw new DeploymentException("Could not construct jaxrpc mapping uri from "
077                                                  + this.jaxrpcMappingFile, e);
078                }
079    
080                this.javaWsdlMapping = WSDescriptorParser.readJaxrpcMapping(moduleFile, jaxrpcMappingURI);
081            }
082            
083            if (this.schemaInfoBuilder == null) {
084                URI wsdlURI;
085                try {
086                    wsdlURI = new URI(this.wsdlLocation);
087                } catch (URISyntaxException e) {
088                    throw new DeploymentException("could not construct wsdl uri from "
089                                                  + this.wsdlLocation, e);
090                }
091    
092                this.schemaInfoBuilder = new SchemaInfoBuilder(moduleFile, wsdlURI);
093            }
094        }
095        
096        public JavaWsdlMappingType getJavaWsdlMapping() {
097            return this.javaWsdlMapping;
098        }
099        
100        public SchemaInfoBuilder getSchemaInfoBuilder() {
101            return schemaInfoBuilder;
102        }
103        
104        public Map<String, ServiceEndpointInterfaceMappingType> getSEIMappings() {
105            if (this.javaWsdlMapping == null) {
106                return Collections.emptyMap();
107            }
108            HashMap<String, ServiceEndpointInterfaceMappingType> seiMappings = new HashMap<String, ServiceEndpointInterfaceMappingType>();
109            ServiceEndpointInterfaceMappingType[] mappings = this.javaWsdlMapping.getServiceEndpointInterfaceMappingArray();
110            for (ServiceEndpointInterfaceMappingType seiMapping : mappings) {
111                seiMappings.put(seiMapping.getServiceEndpointInterface().getStringValue().trim(), seiMapping);
112            }
113            return seiMappings;
114        }
115        
116    }