001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2007 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: ServiceInfo.java 10081 2007-11-14 16:43:38Z mpreston $
023: */
024:
025: package com.bostechcorp.cbesb.common.wsdl;
026:
027: import java.util.ArrayList;
028: import java.util.Iterator;
029: import java.util.LinkedHashMap;
030: import java.util.List;
031: import java.util.Map;
032: import java.util.Set;
033:
034: import javax.wsdl.Definition;
035: import javax.wsdl.Port;
036: import javax.wsdl.Service;
037: import javax.wsdl.WSDLException;
038: import javax.xml.namespace.QName;
039:
040: /**
041: * Represents a single service in a WSDL
042: *
043: */
044:
045: public class ServiceInfo extends ComponentInfo {
046:
047: /** The list of ports defined for this service */
048: private LinkedHashMap<String, PortInfo> ports;
049:
050: /**
051: * Constructor
052: */
053: public ServiceInfo() {
054: super ();
055: ports = new LinkedHashMap<String, PortInfo>();
056: }
057:
058: protected static ServiceInfo load(WsdlInfo wsdlInfo,
059: Service wsdlService) throws WSDLException {
060: ServiceInfo svcInfo = new ServiceInfo();
061:
062: // Get the qualified service name information
063: QName qName = wsdlService.getQName();
064: String namespace = qName.getNamespaceURI();
065: String name = qName.getLocalPart();
066: svcInfo.setName(name);
067: svcInfo.setNamespaceURI(namespace);
068:
069: // Get the defined ports for this service
070: Map ports = wsdlService.getPorts();
071: Iterator iter = ports.values().iterator();
072: while (iter.hasNext()) {
073: // Get the next defined port
074: Port port = (Port) iter.next();
075: PortInfo portInfo = PortInfo.load(wsdlInfo, port);
076:
077: if (portInfo != null)
078: svcInfo.addPort(portInfo);
079: }
080:
081: return svcInfo;
082: }
083:
084: /**
085: * Add a new PortInfo object to the Service
086: * @param port
087: */
088: public void addPort(PortInfo port) {
089: ports.put(port.getName(), port);
090: }
091:
092: /**
093: * Returns an array containing the names of all
094: * of the Ports defined in this service
095: * @return
096: */
097: public String[] getPortNames() {
098: String[] retArray = null;
099: Set Names = ports.keySet();
100: retArray = new String[Names.size()];
101: int i = 0;
102: for (Iterator iter = Names.iterator(); iter.hasNext();) {
103: retArray[i] = (String) iter.next();
104: i++;
105: }
106: return retArray;
107: }
108:
109: /**
110: * Returns a List containing all of the PortInfo
111: * objects defined in this service
112: * @return
113: */
114: public List getPorts() {
115: return new ArrayList<PortInfo>(ports.values());
116: }
117:
118: /**
119: * Return the named PortInfo object
120: * @param name
121: * @return
122: */
123: public PortInfo getPort(String name) {
124: return ports.get(name);
125: }
126:
127: /**
128: * For debugging
129: */
130: public String toString() {
131: StringBuffer buffer = new StringBuffer();
132: buffer.append("Service: " + name + "\n");
133:
134: for (Iterator iter = getPorts().iterator(); iter.hasNext();) {
135: PortInfo port = (PortInfo) iter.next();
136: buffer.append(port.toString() + "\n");
137: }
138: return buffer.toString();
139: }
140: }
|