1 22 package org.jboss.management.j2ee; 23 24 import org.jboss.logging.Logger; 25 26 import javax.management.MBeanServer ; 27 import javax.management.MalformedObjectNameException ; 28 import javax.management.ObjectName ; 29 import java.util.Hashtable ; 30 31 37 public class ResourceAdapter extends J2EEManagedObject 38 implements ResourceAdapterMBean 39 { 40 42 private static Logger log = Logger.getLogger(ResourceAdapter.class); 44 45 48 private ObjectName rarServiceName; 49 50 53 private ObjectName jcaResourceName; 54 55 57 public static ObjectName create(MBeanServer mbeanServer, String displayName, 58 ObjectName jsr77ParentName, ObjectName rarServiceName) 59 { 60 ObjectName jsr77Name = null; 61 try 62 { 63 ResourceAdapter adapter = new ResourceAdapter(displayName, jsr77ParentName, 64 rarServiceName); 65 jsr77Name = adapter.getObjectName(); 66 mbeanServer.registerMBean(adapter, jsr77Name); 67 log.debug("Created JSR-77 ResourceAdapter: " + displayName); 68 } 69 catch (Exception e) 70 { 71 log.debug("Could not create JSR-77 ResourceAdapter: " + displayName, e); 72 } 73 return jsr77Name; 74 } 75 76 public static void destroy(MBeanServer mbeanServer, String displayName) 77 { 78 try 79 { 80 J2EEManagedObject.removeObject(mbeanServer, 81 J2EEDomain.getDomainName() + ":" + 82 J2EEManagedObject.TYPE + "=" + J2EETypeConstants.ResourceAdapter + "," + 83 "name=" + displayName + "," + 84 "*"); 85 } 86 catch (Exception e) 87 { 88 log.error("Could not destroy JSR-77 ResourceAdapter: " + displayName, e); 89 } 90 } 91 92 94 98 public ResourceAdapter(String displayName, ObjectName jsr77ParentName, 99 ObjectName rarServiceName) 100 throws MalformedObjectNameException , 101 InvalidParentException 102 { 103 super(J2EETypeConstants.ResourceAdapter, displayName, jsr77ParentName); 104 this.rarServiceName = rarServiceName; 105 } 106 107 110 public ObjectName getJBossServiceName() 111 { 112 return rarServiceName; 113 } 114 115 118 public ObjectName getJcaResource() 119 { 120 return jcaResourceName; 121 } 122 125 public ObjectName getjcaResource() 126 { 127 return jcaResourceName; 128 } 129 130 132 public String toString() 133 { 134 return "ResourceAdapter { " + super.toString() + " } []"; 135 } 136 137 public void addChild(ObjectName j2eeName) 138 { 139 String j2eeType = J2EEManagedObject.getType(j2eeName); 140 if (J2EETypeConstants.JCAResource.equals(j2eeType)) 141 { 142 jcaResourceName = j2eeName; 143 } 144 } 145 146 public void removeChild(ObjectName j2eeName) 147 { 148 String j2eeType = J2EEManagedObject.getType(j2eeName); 149 if (J2EETypeConstants.JCAResource.equals(j2eeType)) 150 { 151 jcaResourceName = null; 152 } 153 } 154 155 157 159 162 protected Hashtable getParentKeys(ObjectName pParent) 163 { 164 Hashtable lReturn = new Hashtable (); 165 Hashtable lProperties = pParent.getKeyPropertyList(); 166 lReturn.put(J2EETypeConstants.ResourceAdapterModule, lProperties.get("name")); 167 lReturn.put(J2EETypeConstants.J2EEApplication, lProperties.get(J2EETypeConstants.J2EEApplication)); 170 lReturn.put(J2EETypeConstants.J2EEServer, lProperties.get(J2EETypeConstants.J2EEServer)); 171 172 return lReturn; 173 } 174 175 177 179 } 180 | Popular Tags |