1 22 package org.jboss.management.j2ee.factory; 23 24 import org.jboss.deployment.DeploymentInfo; 25 import org.jboss.logging.Logger; 26 import org.jboss.management.j2ee.JCAResource; 27 28 import javax.management.MBeanServer ; 29 import javax.management.ObjectName ; 30 import java.util.Iterator ; 31 32 38 public class JCAResourceFactory 39 implements ManagedObjectFactory 40 { 41 private static Logger log = Logger.getLogger(JCAResourceFactory.class); 42 43 50 public ObjectName create(MBeanServer mbeanServer, Object data) 51 { 52 if ((data instanceof DeploymentInfo) == false) 53 return null; 54 55 DeploymentInfo di = (DeploymentInfo) data; 56 ObjectName jsr77Name = null; 57 58 62 ObjectName rarDeployService = null; 63 ObjectName cmService = null; 64 ObjectName poolService = null; 65 Iterator iter = di.mbeans.iterator(); 66 while (iter.hasNext()) 67 { 68 ObjectName oname = (ObjectName ) iter.next(); 69 String name = oname.getKeyProperty("service"); 70 if (name.equals("ManagedConnectionFactory") || name.endsWith("DS")) 71 rarDeployService = oname; 72 else if (name.endsWith("CM")) 73 cmService = oname; 74 else if (name.endsWith("Pool")) 75 poolService = oname; 76 } 77 if (rarDeployService == null || cmService == null) 78 { 79 log.debug("Failed to find a service=xxxDS match"); 80 return null; 81 } 82 83 try 84 { 85 88 ObjectName rarService = (ObjectName ) mbeanServer.getAttribute(rarDeployService, 89 "OldRarDeployment"); 90 ObjectName jsr77RAName = RARModuleFactory.getResourceAdapterName(rarService); 92 String resName = rarDeployService.getKeyProperty("name"); 94 jsr77Name = JCAResource.create(mbeanServer, resName, jsr77RAName, 95 cmService, rarDeployService, poolService); 96 } 97 catch (Exception e) 98 { 99 log.debug("Failed to create JCAResource", e); 100 } 101 102 return jsr77Name; 103 } 104 105 111 public void destroy(MBeanServer mbeanServer, Object data) 112 { 113 if ((data instanceof DeploymentInfo) == false) 114 return; 115 116 DeploymentInfo di = (DeploymentInfo) data; 117 String resName = getDeploymentResName(mbeanServer, di); 118 JCAResource.destroy(mbeanServer, resName); 119 } 120 121 private String getDeploymentResName(MBeanServer mbeanServer, DeploymentInfo di) 122 { 123 String resName = null; 124 128 ObjectName rarDeployService = null; 129 Iterator iter = di.mbeans.iterator(); 130 while (iter.hasNext()) 131 { 132 ObjectName oname = (ObjectName ) iter.next(); 133 String name = oname.getKeyProperty("service"); 134 if (name.equals("ManagedConnectionFactory") || name.endsWith("DS")) 135 { 136 rarDeployService = oname; 137 resName = rarDeployService.getKeyProperty("name"); 138 break; 139 } 140 } 141 return resName; 142 } 143 } 144 | Popular Tags |