1 22 package org.objectweb.petals.jbi.management.deployment.deploy; 23 24 import java.util.HashMap ; 25 import java.util.List ; 26 27 import javax.jbi.JBIException; 28 import javax.xml.namespace.QName ; 29 30 import org.objectweb.petals.jbi.management.deployment.DeploymentContextConstants; 31 import org.objectweb.petals.jbi.management.deployment.DeploymentUtils; 32 import org.objectweb.petals.jbi.management.service.EndpointService; 33 import org.objectweb.petals.jbi.management.service.ManagementException; 34 import org.objectweb.petals.processor.Task; 35 import org.objectweb.petals.tools.jbicommon.descriptor.Connection; 36 import org.objectweb.petals.tools.jbicommon.descriptor.JBIDescriptor; 37 import org.objectweb.petals.tools.jbicommon.descriptor.ServiceAssembly; 38 import org.objectweb.petals.util.LoggingUtil; 39 40 46 public class AllConnectionRegistrationTask implements Task { 47 48 protected EndpointService endpointService; 49 50 53 protected LoggingUtil log; 54 55 public AllConnectionRegistrationTask(EndpointService endpointService, 56 LoggingUtil log) { 57 super(); 58 this.endpointService = endpointService; 59 this.log = log; 60 } 61 62 public void execute(HashMap context) throws Exception { 63 JBIDescriptor descriptor = (JBIDescriptor) context 64 .get(DeploymentContextConstants.SA_DESCRIPTOR); 65 66 List <Connection> connections = descriptor.getServiceAssembly() 67 .getConnections(); 68 if (connections != null) { 69 for (Connection connection : connections) { 70 registerConnection(connection, descriptor); 71 } 72 } 73 74 } 75 76 87 protected void registerConnection(Connection connection, 88 JBIDescriptor descriptor) throws ManagementException { 89 String saName = DeploymentUtils.getServiceAssemblyName(descriptor); 90 91 QName consInterface = connection.getConsumerInterfaceName(); 92 QName consService = connection.getConsumerServiceName(); 93 String consEndpoint = connection.getConsumerEndpointName(); 94 QName provService = connection.getProviderServiceName(); 95 String provEndpoint = connection.getProviderEndpointName(); 96 97 try { 98 if (consInterface != null) { 99 100 endpointService.createConnection(consInterface, provService, 101 provEndpoint); 102 103 } else { 104 endpointService.createConnection(consService, consEndpoint, 105 provService, provEndpoint); 106 } 107 } catch (JBIException e) { 108 String msg = "Error while registering a service unit connection for the service assembly: " 109 + saName + "."; 110 log.error(msg, e); 111 throw new ManagementException(msg, e); 112 } 113 114 } 115 116 public void undo(HashMap context) { 117 JBIDescriptor descriptor = (JBIDescriptor) context 118 .get(DeploymentContextConstants.SA_DESCRIPTOR); 119 120 ServiceAssembly serviceAssembly = descriptor.getServiceAssembly(); 121 122 try { 123 removeConnections(serviceAssembly); 124 } catch (Exception e) { 125 String msg = "Failed to revert a AllConnectionRegistrationTask"; 126 log.error(msg, e); 127 } 128 } 129 130 139 protected void removeConnections(ServiceAssembly saDescriptor) 140 throws Exception { 141 List <Connection> connections = saDescriptor.getConnections(); 142 if (connections != null) { 143 for (Connection connection : connections) { 144 QName consInterface = connection.getConsumerInterfaceName(); 145 QName consService = connection.getConsumerServiceName(); 146 String consEndpoint = connection.getConsumerEndpointName(); 147 QName provService = connection.getProviderServiceName(); 148 String provEndpoint = connection.getProviderEndpointName(); 149 150 if (provEndpoint != null && provService != null) { 151 if (consInterface != null) { 152 endpointService.deleteConnection(consInterface, 153 provService, provEndpoint); 154 } else if (consService != null && consEndpoint != null) { 155 endpointService.deleteConnection(consService, 156 consEndpoint, provService, provEndpoint); 157 } 158 } 159 } 160 } 161 } 162 163 } 164 | Popular Tags |