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: PortInfo.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.Set;
032:
033: import javax.wsdl.Binding;
034: import javax.wsdl.BindingOperation;
035: import javax.wsdl.Definition;
036: import javax.wsdl.Port;
037: import javax.wsdl.WSDLException;
038: import javax.wsdl.extensions.ExtensibilityElement;
039: import javax.wsdl.extensions.soap.SOAPBinding;
040: import javax.wsdl.extensions.soap.SOAPAddress;
041: import javax.wsdl.extensions.soap12.SOAP12Binding;
042: import javax.wsdl.extensions.soap12.SOAP12Address;
043:
044: public class PortInfo extends ComponentInfo {
045:
046: protected static final String SOAP_NS_URL = "http://schemas.xmlsoap.org/wsdl/soap/";
047:
048: protected static final String SOAP_NS_URL12 = "http://schemas.xmlsoap.org/wsdl/soap12/";
049:
050: protected static final String SOAP_HTTP_TRANSPORT = "http://schemas.xmlsoap.org/soap/http";
051:
052: /** The list of operations that this service defines. */
053: private LinkedHashMap<String, OperationInfo> operations;
054:
055: private String locationURI;
056:
057: public PortInfo() {
058: super ();
059: operations = new LinkedHashMap<String, OperationInfo>();
060: }
061:
062: protected static PortInfo load(WsdlInfo wsdlInfo, Port wsdlPort)
063: throws WSDLException {
064: PortInfo portInfo = new PortInfo();
065: portInfo.setName(wsdlPort.getName());
066:
067: portInfo.locationURI = getSoapAddressLocationURI(wsdlPort);
068:
069: // Get the Port's Binding
070: Binding binding = wsdlPort.getBinding();
071:
072: String style = "document"; //Set a default style
073: // Check if a Soap Binding style attribute exists
074: ExtensibilityElement soapBindingElem = findExtensibilityElement(
075: binding.getExtensibilityElements(), "binding");
076: if (soapBindingElem != null
077: && soapBindingElem instanceof SOAPBinding) {
078: SOAPBinding soapBinding = (SOAPBinding) soapBindingElem;
079: if ("rpc".equals(soapBinding.getStyle())) {
080: style = "rpc";
081: }
082:
083: if (!soapBinding.getTransportURI().equals(
084: SOAP_HTTP_TRANSPORT)) {
085: // let us do not add the load port if it is not HTTP based.
086: return null;
087: }
088:
089: } else if (soapBindingElem != null
090: && soapBindingElem instanceof SOAP12Binding) {
091: SOAP12Binding soapBinding = (SOAP12Binding) soapBindingElem;
092: if ("rpc".equals(soapBinding.getStyle())) {
093: style = "rpc";
094: }
095:
096: if (!soapBinding.getTransportURI().equals(
097: SOAP_HTTP_TRANSPORT)) {
098: // let us do not add the load port if it is not HTTP based.
099: return null;
100: }
101: }
102:
103: // Get the Binding's Operations
104: List operations = binding.getBindingOperations();
105: for (Iterator iter = operations.iterator(); iter.hasNext();) {
106: BindingOperation operation = (BindingOperation) iter.next();
107: OperationInfo opInfo = OperationInfo.load(wsdlInfo,
108: operation, style);
109: if (opInfo != null) {
110: portInfo.addOperation(opInfo);
111: }
112: }
113:
114: return portInfo;
115: }
116:
117: private static String getSoapAddressLocationURI(Port wsdlPort) {
118: String location = null;
119: ExtensibilityElement soapAddressElem = findExtensibilityElement(
120: wsdlPort.getExtensibilityElements(), "address");
121: if (soapAddressElem != null
122: && soapAddressElem instanceof SOAPAddress) {
123: SOAPAddress soapAddress = (SOAPAddress) soapAddressElem;
124: location = soapAddress.getLocationURI();
125: } else if (soapAddressElem != null
126: && soapAddressElem instanceof SOAP12Address) {
127: SOAP12Address soapAddress = (SOAP12Address) soapAddressElem;
128: location = soapAddress.getLocationURI();
129: }
130: return location;
131: }
132:
133: /**
134: * @return the locationURI
135: */
136: public String getLocationURI() {
137: return locationURI;
138: }
139:
140: /**
141: * Adds a new OperationInfo to this Port
142: * @param operation
143: */
144: public void addOperation(OperationInfo operation) {
145: operations.put(operation.getName(), operation);
146: }
147:
148: /**
149: * Returns an array containing all of the operation
150: * names contained by this Port
151: * @return
152: */
153: public String[] getOperationNames() {
154: String[] retArray = null;
155: Set opNames = operations.keySet();
156: retArray = new String[opNames.size()];
157: int i = 0;
158: for (Iterator iter = opNames.iterator(); iter.hasNext();) {
159: retArray[i] = (String) iter.next();
160: i++;
161: }
162: return retArray;
163: }
164:
165: /**
166: * Returns a List containing all of the OperationInfo
167: * objects defined for this Port
168: * @return
169: */
170: public List getOperations() {
171: return new ArrayList<OperationInfo>(operations.values());
172: }
173:
174: /**
175: * Returns the specified OperationInfo
176: * @param operationName The name of the operation to retreive
177: * @return
178: */
179: public OperationInfo getOperationInfo(String operationName) {
180: OperationInfo operation = null;
181: if (operations != null) {
182: operation = operations.get(operationName);
183: }
184: return operation;
185: }
186:
187: /**
188: * For debugging
189: */
190: public String toString() {
191: StringBuffer buffer = new StringBuffer();
192: buffer.append("Port: " + name + "\n");
193: for (Iterator iter = getOperations().iterator(); iter.hasNext();) {
194: OperationInfo operation = (OperationInfo) iter.next();
195: buffer.append(operation.toString() + "\n");
196: }
197:
198: return buffer.toString();
199: }
200:
201: }
|