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:
020: package org.apache.axis2.tool.codegen.eclipse.util;
021:
022: import org.apache.axis2.util.URLProcessor;
023:
024: import javax.wsdl.Definition;
025: import javax.wsdl.Port;
026: import javax.wsdl.Service;
027: import javax.wsdl.WSDLException;
028: import javax.wsdl.factory.WSDLFactory;
029: import javax.wsdl.xml.WSDLReader;
030: import javax.xml.namespace.QName;
031: import java.util.ArrayList;
032: import java.util.Iterator;
033: import java.util.List;
034: import java.util.Map;
035:
036: /**
037: * This class presents a convenient way of reading the
038: * WSDL file(url) and producing a useful set of information
039: * It does NOT use any of the standard WSDL classes from
040: * Axis2, rather it uses wsdl4j to read the wsdl and extract
041: * the properties (This is meant as a convenience for the UI
042: * only. We may not need the whole conversion the WSDLpump
043: * goes through)
044: * One would need to change this to suit a proper WSDL
045: */
046: public class WSDLPropertyReader {
047: private Definition wsdlDefinition = null;
048:
049: public void readWSDL(String filepath) throws WSDLException {
050: WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
051: wsdlDefinition = reader.readWSDL(filepath);
052: }
053:
054: /**
055: * Returns the namespace map from definition
056: * @return
057: */
058: public Map getDefinitionNamespaceMap() {
059: return wsdlDefinition.getNamespaces();
060: }
061:
062: /**
063: * get the default package derived by the targetNamespace
064: */
065: public String packageFromTargetNamespace() {
066: return URLProcessor.makePackageName(wsdlDefinition
067: .getTargetNamespace());
068:
069: }
070:
071: /**
072: * Returns a list of service names
073: * the names are QNames
074: * @return
075: */
076: public List getServiceList() {
077: List returnList = new ArrayList();
078: Service service = null;
079: Map serviceMap = wsdlDefinition.getServices();
080: if (serviceMap != null && !serviceMap.isEmpty()) {
081: Iterator serviceIterator = serviceMap.values().iterator();
082: while (serviceIterator.hasNext()) {
083: service = (Service) serviceIterator.next();
084: returnList.add(service.getQName());
085: }
086: }
087:
088: return returnList;
089: }
090:
091: /**
092: * Returns a list of ports for a particular service
093: * the names are QNames
094: * @return
095: */
096: public List getPortNameList(QName serviceName) {
097: List returnList = new ArrayList();
098: Service service = wsdlDefinition.getService(serviceName);
099: Port port = null;
100: if (service != null) {
101: Map portMap = service.getPorts();
102: if (portMap != null && !portMap.isEmpty()) {
103: Iterator portIterator = portMap.values().iterator();
104: while (portIterator.hasNext()) {
105: port = (Port) portIterator.next();
106: returnList.add(port.getName());
107: }
108: }
109:
110: }
111:
112: return returnList;
113: }
114:
115: /**
116: * public method to get loaded wsdl Definition
117: * @return
118: */
119: public Definition getWsdlDefinition() {
120: return wsdlDefinition;
121: }
122: }
|