1 22 package org.jboss.resource.deployers; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import javax.management.ObjectName ; 28 29 import org.jboss.deployers.plugins.deployers.helpers.AbstractSimpleRealDeployer; 30 import org.jboss.deployers.spi.DeploymentException; 31 import org.jboss.deployers.spi.deployer.DeploymentUnit; 32 import org.jboss.deployers.spi.structure.DeploymentContext; 33 import org.jboss.resource.metadata.ConnectorMetaData; 34 import org.jboss.system.metadata.ServiceAttributeMetaData; 35 import org.jboss.system.metadata.ServiceConstructorMetaData; 36 import org.jboss.system.metadata.ServiceInjectionValueMetaData; 37 import org.jboss.system.metadata.ServiceMetaData; 38 39 45 public class RARDeployer extends AbstractSimpleRealDeployer<ConnectorMetaData> 46 { 47 48 private String workManagerName; 49 50 51 private String xaTerminatorName; 52 53 57 public RARDeployer() 58 { 59 super(ConnectorMetaData.class); 60 setRelativeOrder(COMPONENT_DEPLOYER+1); 61 } 62 63 68 public String getWorkManagerName() 69 { 70 return workManagerName; 71 } 72 73 78 public void setWorkManagerName(String workManagerName) 79 { 80 this.workManagerName = workManagerName; 81 } 82 83 88 public String getXATerminatorName() 89 { 90 return xaTerminatorName; 91 } 92 93 98 public void setXATerminatorName(String xaTerminatorName) 99 { 100 this.xaTerminatorName = xaTerminatorName; 101 } 102 103 protected String getObjectName(DeploymentUnit unit, ConnectorMetaData cmd) 104 { 105 DeploymentContext ctx = unit.getDeploymentContext(); 107 String name = ctx.getRoot().getName(); 108 ctx = ctx.getParent(); 109 while (ctx != null) 110 { 111 name = ctx.getRoot().getName() + "#" + name; 112 ctx = ctx.getParent(); 113 } 114 return "jboss.jca:service=RARDeployment,name='" + name + "'"; 115 } 116 117 public void deploy(DeploymentUnit unit, ConnectorMetaData cmd) throws DeploymentException 118 { 119 try 120 { 121 ServiceMetaData rarDeployment = new ServiceMetaData(); 122 String name = getObjectName(unit, cmd); 123 ObjectName objectName = new ObjectName (name); 124 rarDeployment.setObjectName(objectName); 125 rarDeployment.setCode(RARDeployment.class.getName()); 126 ServiceConstructorMetaData constructor = new ServiceConstructorMetaData(); 127 constructor.setSignature(new String [] { ConnectorMetaData.class.getName() }); 128 constructor.setParameters(new Object [] { cmd }); 129 rarDeployment.setConstructor(constructor); 130 131 List <ServiceAttributeMetaData> attributes = new ArrayList <ServiceAttributeMetaData>(); 132 ServiceAttributeMetaData attribute = null; 133 if (workManagerName != null) 134 { 135 attribute = new ServiceAttributeMetaData(); 136 attribute.setName("WorkManager"); 137 attribute.setValue(new ServiceInjectionValueMetaData(workManagerName)); 138 attributes.add(attribute); 139 } 140 if (xaTerminatorName != null) 141 { 142 attribute = new ServiceAttributeMetaData(); 143 attribute.setName("XATerminator"); 144 attribute.setValue(new ServiceInjectionValueMetaData(xaTerminatorName, "XATerminator")); 145 attributes.add(attribute); 146 } 147 if (attributes.isEmpty() == false) 148 rarDeployment.setAttributes(attributes); 149 150 unit.addAttachment(ServiceMetaData.class, rarDeployment); 152 } 153 catch (Exception e) 154 { 155 throw DeploymentException.rethrowAsDeploymentException("Error creating rar deployment " + unit.getName(), e); 156 } 157 } 158 159 public void undeploy(DeploymentUnit unit, ConnectorMetaData cmd) 160 { 161 } 162 } 163 | Popular Tags |