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.description;
020:
021: import org.apache.axis2.AxisFault;
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: import javax.wsdl.Port;
026: import javax.wsdl.Service;
027: import javax.wsdl.Definition;
028: import javax.xml.namespace.QName;
029: import java.io.InputStream;
030: import java.util.ArrayList;
031: import java.util.Iterator;
032: import java.util.List;
033: import java.util.Map.Entry;
034:
035: /**
036: * Extends the WSDL11ToAxisServiceBuilder class to provide functionality to return
037: * multiple AxisService objects; one for each port on each service in the WSDL 1.1 file.
038: */
039: public class WSDL11ToAllAxisServicesBuilder extends
040: WSDL11ToAxisServiceBuilder {
041: protected static final Log log = LogFactory
042: .getLog(WSDL11ToAllAxisServicesBuilder.class);
043:
044: public static final String WSDL_SERVICE_QNAME = "WSDL_SERVICE_QNAME";
045:
046: public static final String WSDL_PORT = "WSDL_PORT";
047:
048: private ArrayList axisServices = null;
049:
050: /**
051: * Class constructor.
052: *
053: * @param in - Contains the wsdl 1.1 file
054: */
055: public WSDL11ToAllAxisServicesBuilder(InputStream in) {
056: super (in);
057: axisServices = new ArrayList(); // create an empty ArrayList
058: }
059:
060: public WSDL11ToAllAxisServicesBuilder(Definition def) {
061: super (def, null, null);
062: axisServices = new ArrayList(); // create an empty ArrayList
063: }
064:
065: public WSDL11ToAllAxisServicesBuilder(Definition def,
066: String portName) {
067: super (def, null, portName);
068: axisServices = new ArrayList(); // create an empty ArrayList
069: }
070:
071: /**
072: * Public method to access the wsdl 1.1 file and create a List of AxisService objects.
073: * For each port on each service in the wsdl, an AxisService object is created and
074: * added to the List. The name of the AxisService is changed from the service name
075: * to the port name, since port names are unique to the wsdl.
076: *
077: * @return A List containing one AxisService object for each port in the wsdl file.
078: * The name of the AxisService is modified from the service name to the port name.
079: * @throws AxisFault
080: */
081: public List populateAllServices() throws AxisFault {
082: try {
083: if (log.isDebugEnabled()) {
084: log.debug("Entry: populateAllServices");
085: }
086:
087: setup(); // setup contains code with gathers non-service specific info
088: // from the WSDL. This only needs to be done once per WSDL.
089: if (wsdl4jDefinition == null) {
090: if (log.isDebugEnabled()) {
091: log
092: .debug("Exit: populateAllServices. wsdl definition is null!");
093: }
094: return null; // can't go any further without the wsdl
095: }
096:
097: if (wsdl4jDefinition.getServices().size() > 0) {
098: Iterator wsdlServIter = wsdl4jDefinition.getServices()
099: .values().iterator();
100: if (wsdl4jDefinition.getServices().size() > 1) {
101: // let the wsdlToservice builder to decide the port to generate binding
102: portName = null;
103: }
104:
105: while (wsdlServIter.hasNext()) {
106: Service service = (Service) wsdlServIter.next();
107: // set the serviceName on the parent to setup call to populateService
108: serviceName = service.getQName();
109: this .axisService = new AxisService();
110: // now that serviceName and portName are set, call up to the
111: // parent class to populate this service.
112: AxisService retAxisService = populateService();
113: if (retAxisService != null) {
114: axisServices.add(retAxisService);
115: }
116: // reset the port name if it had set when moving to next service
117: portName = null;
118: }
119: } else {
120: throw new AxisFault(
121: "No service was not found in the WSDL at "
122: + wsdl4jDefinition.getDocumentBaseURI()
123: + " with targetnamespace "
124: + wsdl4jDefinition.getTargetNamespace());
125: }
126:
127: if (log.isDebugEnabled()) {
128: log.debug("Exit: populateAllServices.");
129: }
130: return axisServices;
131: } catch (AxisFault e) {
132: throw e; // just rethrow any AxisFaults
133: } catch (Exception e) {
134: if (log.isDebugEnabled()) {
135: log
136: .debug("populateAllServices caught Exception. Converting to AxisFault. "
137: + e.toString());
138: }
139: throw AxisFault.makeFault(e);
140: }
141: }
142:
143: }
|