1 22 package org.jboss.system.deployers; 23 24 import java.util.List ; 25 26 import javax.management.ObjectName ; 27 28 import org.jboss.deployers.plugins.deployers.helpers.AbstractComponentDeployer; 29 import org.jboss.deployers.plugins.deployers.helpers.SimpleDeploymentVisitor; 30 import org.jboss.deployers.spi.DeploymentException; 31 import org.jboss.deployers.spi.deployer.DeploymentUnit; 32 import org.jboss.system.metadata.ServiceDeployment; 33 import org.jboss.system.metadata.ServiceMetaData; 34 import org.jboss.system.metadata.ServiceMetaDataParser; 35 import org.w3c.dom.Element ; 36 37 46 public class ServiceDeploymentDeployer extends AbstractComponentDeployer<ServiceDeployment, ServiceMetaData> 47 { 48 51 public ServiceDeploymentDeployer() 52 { 53 setDeploymentVisitor(new ServiceDeploymentVisitor()); 54 setComponentVisitor(new ServiceMetaDataVisitor()); 55 } 56 57 protected static void addServiceComponent(DeploymentUnit unit, ServiceMetaData service) 58 { 59 ObjectName objectName = service.getObjectName(); 60 String name = objectName.getCanonicalName(); 61 DeploymentUnit component = unit.addComponent(name); 62 component.addAttachment(ServiceMetaData.class.getName(), service); 63 } 64 65 protected static void removeServiceComponent(DeploymentUnit unit, ServiceMetaData service) 66 { 67 ObjectName objectName = service.getObjectName(); 68 String name = objectName.getCanonicalName(); 69 unit.removeComponent(name); 70 } 71 72 75 public class ServiceDeploymentVisitor implements SimpleDeploymentVisitor<ServiceDeployment> 76 { 77 public Class <ServiceDeployment> getVisitorType() 78 { 79 return ServiceDeployment.class; 80 } 81 82 public void deploy(DeploymentUnit unit, ServiceDeployment deployment) throws DeploymentException 83 { 84 try 85 { 86 List <ServiceMetaData> services = deployment.getServices(); 87 if (services == null) 88 { 89 Element config = deployment.getConfig(); 90 if (config == null) 91 { 92 log.debug("Service deployment has no services: " + deployment.getName()); 93 return; 94 } 95 96 ServiceMetaDataParser parser = new ServiceMetaDataParser(config); 97 services = parser.parse(); 98 deployment.setServices(services); 99 } 100 101 if (services == null || services.isEmpty()) 102 return; 103 104 for (ServiceMetaData service : services) 105 addServiceComponent(unit, service); 106 } 107 catch (Throwable t) 108 { 109 throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + deployment.getName(), t); 110 } 111 } 112 113 public void undeploy(DeploymentUnit unit, ServiceDeployment deployment) 114 { 115 List <ServiceMetaData> services = deployment.getServices(); 116 if (services == null) 117 return; 118 119 for (ServiceMetaData service : services) 120 { 121 ObjectName objectName = service.getObjectName(); 122 String name = objectName.getCanonicalName(); 123 unit.removeComponent(name); 124 } 125 } 126 } 127 128 131 public static class ServiceMetaDataVisitor implements SimpleDeploymentVisitor<ServiceMetaData> 132 { 133 public Class <ServiceMetaData> getVisitorType() 134 { 135 return ServiceMetaData.class; 136 } 137 138 public void deploy(DeploymentUnit unit, ServiceMetaData deployment) throws DeploymentException 139 { 140 addServiceComponent(unit, deployment); 141 } 142 143 public void undeploy(DeploymentUnit unit, ServiceMetaData deployment) 144 { 145 removeServiceComponent(unit, deployment); 146 } 147 } 148 } 149 | Popular Tags |