1 17 package org.apache.servicemix.wsn.component; 18 19 import java.net.URL ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import javax.jbi.servicedesc.ServiceEndpoint; 24 import javax.jms.ConnectionFactory ; 25 import javax.wsdl.Definition; 26 import javax.wsdl.factory.WSDLFactory; 27 import javax.wsdl.xml.WSDLReader; 28 import javax.xml.namespace.QName ; 29 30 import org.apache.servicemix.common.BaseComponent; 31 import org.apache.servicemix.common.BaseLifeCycle; 32 import org.apache.servicemix.common.BaseServiceUnitManager; 33 import org.apache.servicemix.common.Deployer; 34 import org.apache.servicemix.common.Endpoint; 35 import org.apache.servicemix.common.EndpointSupport; 36 import org.apache.servicemix.common.tools.wsdl.WSDLFlattener; 37 import org.w3c.dom.Document ; 38 39 import com.ibm.wsdl.Constants; 40 41 public class WSNComponent extends BaseComponent { 42 43 private WSDLFlattener flattener; 44 private Map descriptions; 45 46 @Override 47 protected BaseLifeCycle createLifeCycle() { 48 return new WSNLifeCycle(this); 49 } 50 51 @Override 52 public BaseServiceUnitManager createServiceUnitManager() { 53 Deployer[] deployers = new Deployer[] { new WSNDeployer(this) }; 54 return new BaseServiceUnitManager(this, deployers); 55 } 56 57 public ConnectionFactory getConnectionFactory() { 58 return ((WSNLifeCycle) lifeCycle).getConnectionFactory(); 59 } 60 61 public void setConnectionFactory(ConnectionFactory connectionFactory) { 62 ((WSNLifeCycle) lifeCycle).setConnectionFactory(connectionFactory); 63 } 64 65 68 @Override 69 public Document getServiceDescription(ServiceEndpoint endpoint) { 70 if (logger.isDebugEnabled()) { 71 logger.debug("Querying service description for " + endpoint); 72 } 73 String key = EndpointSupport.getKey(endpoint); 74 Endpoint ep = this.registry.getEndpoint(key); 75 if (ep != null) { 76 QName interfaceName = ep.getInterfaceName(); 77 if (interfaceName == null) { 78 if (logger.isDebugEnabled()) { 79 logger.debug("Could not retrieve description for endpoint " + key + " (no interface defined)"); 80 } 81 return null; 82 } 83 Document doc = getDescription(interfaceName); 84 return doc; 85 } else { 86 if (logger.isDebugEnabled()) { 87 logger.debug("No endpoint found for " + key); 88 } 89 return null; 90 } 91 } 92 93 private synchronized Document getDescription(QName interfaceName) { 94 try { 95 if (descriptions == null) { 96 descriptions = new HashMap (); 97 } 98 Document doc = (Document ) descriptions.get(interfaceName); 99 if (doc == null) { 100 if (flattener == null) { 101 URL resource = getClass().getClassLoader().getResource("org/apache/servicemix/wsn/wsn.wsdl"); 102 WSDLReader reader = WSDLFactory.newInstance().newWSDLReader(); 103 reader.setFeature(Constants.FEATURE_VERBOSE, false); 104 Definition definition = reader.readWSDL(null, resource.toString()); 105 flattener = new WSDLFlattener(definition); 106 } 107 Definition flatDef = flattener.getDefinition(interfaceName); 108 doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(flatDef); 109 descriptions.put(interfaceName, doc); 110 } 111 return doc; 112 } catch (Exception e) { 113 if (logger.isDebugEnabled()) { 114 logger.debug("Error retrieving endpoint description", e); 115 } 116 return null; 117 } 118 } 119 120 } 121 | Popular Tags |