1 17 package org.apache.servicemix.sca.assembly.impl; 18 19 import java.util.List ; 20 21 import javax.wsdl.Definition; 22 import javax.wsdl.Port; 23 import javax.wsdl.PortType; 24 import javax.wsdl.Service; 25 import javax.xml.namespace.QName ; 26 27 import org.apache.servicemix.sca.assembly.JbiBinding; 28 import org.apache.tuscany.model.assembly.AssemblyModelContext; 29 import org.apache.tuscany.model.assembly.impl.BindingImpl; 30 31 34 public class JbiBindingImpl extends BindingImpl implements JbiBinding { 35 36 private String portURI; 37 private QName serviceName; 38 private String endpointName; 39 private QName interfaceName; 40 private Definition definition; 41 private Service service; 42 private PortType portType; 43 private Port port; 44 45 46 49 protected JbiBindingImpl() { 50 } 51 52 55 public String getPortURI() { 56 return portURI; 57 } 58 59 62 public void setPortURI(String portURI) { 63 this.portURI = portURI; 64 } 65 66 69 public QName getServiceName() { 70 return serviceName; 71 } 72 73 76 public String getEndpointName() { 77 return endpointName; 78 } 79 80 83 public QName getInterfaceName() { 84 return interfaceName; 85 } 86 87 90 public Definition getDefinition() { 91 return definition; 92 } 93 94 97 public Service getService() { 98 return service; 99 } 100 101 104 public Port getPort() { 105 return port; 106 } 107 108 111 public PortType getPortType() { 112 return portType; 113 } 114 115 118 public void initialize(AssemblyModelContext modelContext) { 119 if (isInitialized()) 120 return; 121 super.initialize(modelContext); 122 123 String [] parts = split(portURI); 125 serviceName = new QName (parts[0], parts[1]); 126 endpointName = parts[2]; 127 128 List <Definition> definitions = modelContext.getAssemblyLoader().loadDefinitions(parts[0]); 130 if (definitions != null) { 131 for (Definition definition : definitions) { 132 Service service = definition.getService(serviceName); 133 if (service != null) { 134 Port port = service.getPort(endpointName); 135 if (port != null) { 136 this.service = service; 137 this.port = port; 138 this.portType = port.getBinding().getPortType(); 139 this.interfaceName = portType.getQName(); 140 this.definition = definition; 141 return; 142 } 143 } 144 } 145 } 146 } 147 148 protected String [] split(String uri) { 149 char sep; 150 uri = uri.trim(); 151 if (uri.indexOf('/') > 0) { 152 sep = '/'; 153 } else { 154 sep = ':'; 155 } 156 int idx1 = uri.lastIndexOf(sep); 157 int idx2 = uri.lastIndexOf(sep, idx1 - 1); 158 String epName = uri.substring(idx1 + 1); 159 String svcName = uri.substring(idx2 + 1, idx1); 160 String nsUri = uri.substring(0, idx2); 161 return new String [] { nsUri, svcName, epName }; 162 } 163 164 } 165 | Popular Tags |