1 22 package org.jboss.resource.deployment; 23 24 import java.util.Properties ; 25 26 import javax.management.ObjectName ; 27 import javax.naming.InitialContext ; 28 29 import org.jboss.deployment.DeploymentException; 30 import org.jboss.resource.metadata.AdminObjectMetaData; 31 import org.jboss.resource.metadata.ConnectorMetaData; 32 import org.jboss.system.ServiceMBeanSupport; 33 import org.jboss.util.naming.Util; 34 35 41 public class AdminObject extends ServiceMBeanSupport implements AdminObjectMBean 42 { 43 44 protected ObjectName rarName; 45 46 47 protected String type; 48 49 50 protected Properties properties; 51 52 53 protected String jndiName; 54 55 public String getJNDIName() 56 { 57 return jndiName; 58 } 59 60 public void setJNDIName(String jndiName) 61 { 62 this.jndiName = jndiName; 63 } 64 65 public Properties getProperties() 66 { 67 return properties; 68 } 69 70 public void setProperties(Properties properties) 71 { 72 this.properties = properties; 73 } 74 75 public ObjectName getRARName() 76 { 77 return rarName; 78 } 79 80 public void setRARName(ObjectName rarName) 81 { 82 this.rarName = rarName; 83 } 84 85 public String getType() 86 { 87 return type; 88 } 89 90 public void setType(String type) 91 { 92 this.type = type; 93 } 94 95 protected void startService() throws Exception 96 { 97 AdminObjectMetaData aomd = retrieveAdminObjectMetaData(); 98 if (aomd == null) 99 throw new DeploymentException("No admin object metadata type=" + type + " ra=" + rarName); 100 101 Object adminObject = createAdminObject(aomd); 102 103 bind(adminObject); 104 } 105 106 protected void stopService() throws Exception 107 { 108 unbind(); 109 } 110 111 117 protected AdminObjectMetaData retrieveAdminObjectMetaData() throws DeploymentException 118 { 119 try 120 { 121 ConnectorMetaData cmd = (ConnectorMetaData) server.getAttribute(rarName, "MetaData"); 122 return cmd.getAdminObject(type); 123 } 124 catch (Throwable t) 125 { 126 DeploymentException.rethrowAsDeploymentException("Error retrieving admin object metadata type=" + type + " ra=" + rarName, t); 127 return null; } 129 } 130 131 138 protected Object createAdminObject(AdminObjectMetaData aomd) throws DeploymentException 139 { 140 try 141 { 142 return AdminObjectFactory.createAdminObject(jndiName, rarName, aomd, properties); 143 } 144 catch (Throwable t) 145 { 146 DeploymentException.rethrowAsDeploymentException("Error creating admin object metadata type=" + type + " ra=" + rarName, t); 147 return null; } 149 } 150 151 157 protected void bind(Object object) throws Exception 158 { 159 InitialContext ctx = new InitialContext (); 160 try 161 { 162 Util.bind(ctx, jndiName, object); 163 log.info("Bound admin object '" + object.getClass().getName() + "' at '" + jndiName + "'"); 164 } 165 finally 166 { 167 ctx.close(); 168 } 169 } 170 171 176 protected void unbind() throws Exception 177 { 178 InitialContext ctx = new InitialContext (); 179 try 180 { 181 Util.unbind(ctx, jndiName); 182 log.info("Unbound admin object at '" + jndiName + "'"); 183 } 184 finally 185 { 186 ctx.close(); 187 } 188 } 189 } 190 | Popular Tags |