FileDocCategorySizeDatePackage
ConnectionFactoryBindingService.javaAPI DocJBoss 4.2.15161Fri Jul 13 21:01:18 BST 2007org.jboss.resource.connectionmanager

ConnectionFactoryBindingService

public class ConnectionFactoryBindingService extends org.jboss.system.ServiceMBeanSupport implements ConnectionFactoryBindingServiceMBean
Handles the binding of the connection factory into jndi
author
Adrian Brock
version
$Revision: 57189 $

Fields Summary
private static final Logger
log
The logger
protected ObjectName
cm
The connection manager
protected String
jndiName
The jndi name
protected String
bindName
The bind name
protected boolean
useJavaContext
Whether to use the java naming context
protected Object
cf
The connection factory
Constructors Summary
Methods Summary
protected voidbindConnectionFactory()
Bind the connection factory into jndi

      InitialContext ctx = new InitialContext();
      try
      {
         log.debug("Binding object '" + cf + "' into JNDI at '" + bindName + "'");
         Name name = ctx.getNameParser("").parse(bindName);
         NonSerializableFactory.rebind(name, cf, true);
         log.info("Bound ConnectionManager '" + serviceName + "' to JNDI name '" + bindName + "'");
      }
      catch (NamingException ne)
      {
         throw new DeploymentException("Could not bind ConnectionFactory into jndi: " + bindName, ne);
      }
      finally
      {
         ctx.close();
      }
   
protected voidcreateConnectionFactory()
Create the connection factory

      try
      {
         BaseConnectionManager2 bcm = (BaseConnectionManager2) server.getAttribute(cm, "Instance");
         BaseConnectionManager2.ConnectionManagerProxy cmProxy = new BaseConnectionManager2.ConnectionManagerProxy(bcm, cm);
         cf = bcm.getPoolingStrategy().getManagedConnectionFactory().createConnectionFactory(cmProxy);
      }
      catch (ResourceException re)
      {
         throw new DeploymentException("Could not create ConnectionFactory for adapter: " + cm);
      }
   
protected voiddetermineBindName()
Determine the bind name

      bindName = jndiName;
      if( useJavaContext && jndiName.startsWith("java:") == false )
         bindName = "java:" + jndiName;
   
public java.lang.StringgetBindName()

      return bindName;
   
public javax.management.ObjectNamegetConnectionManager()

      return cm;
   
public java.lang.StringgetJndiName()

      return jndiName;
   
public booleanisUseJavaContext()

      return useJavaContext;
   
public voidsetConnectionManager(javax.management.ObjectName cm)

      this.cm = cm;
   
public voidsetJndiName(java.lang.String jndiName)

      this.jndiName = jndiName;
   
public voidsetUseJavaContext(boolean useJavaContext)

      this.useJavaContext = useJavaContext;
   
protected voidstartService()

   
       
   
      determineBindName();
      createConnectionFactory();
      bindConnectionFactory();
   
protected voidstopService()

      unbindConnectionFactory();
   
protected voidunbindConnectionFactory()
Unbind the connection factory into jndi

      InitialContext ctx = new InitialContext();
      try
      {
         ctx.unbind(bindName);
         NonSerializableFactory.unbind(bindName);
         log.info("Unbound ConnectionManager '" + serviceName + "' from JNDI name '" + bindName + "'");
      }
      catch (NamingException ne)
      {
         log.error("Could not unbind managedConnectionFactory from jndi: " + bindName, ne);
      }
      finally
      {
         ctx.close();
      }