/*
 * JBoss, Home of Professional Open Source
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jboss.management.j2ee.factory;

import org.jboss.management.j2ee.JTAResource;

import javax.management.MBeanServer;
import javax.management.ObjectName;

/**
 * The JSR77.3.30 JTAResource factory
 *
 * @author Scott.Stark@jboss.org
 * @version $Revision: 1.5.6.1 $
 */
public class JTAResourceFactory
        implements ManagedObjectFactory
{
   /**
    * Creates a JTAResource given an MBeanServerNotification
    *
    * @param server
    * @param data   A MBeanServerNotification
    * @return the JNDIResource ObjectName
    */
   public ObjectName create(MBeanServer server, Object data)
   {
      ObjectName serviceName = (ObjectName) data;
      String name = serviceName.getKeyProperty("service");
      ObjectName jsr77Name = JTAResource.create(server, name, serviceName);
      return jsr77Name;
   }

   /**
    * Destroys a JTAResource given an MBeanServerNotification
    *
    * @param server
    * @param data   A MBeanServerNotification
    * @return the JNDIResource ObjectName
    */
   public void destroy(MBeanServer server, Object data)
   {
      ObjectName serviceName = (ObjectName) data;
      String name = serviceName.getKeyProperty("service");
      JTAResource.destroy(server, name);
   }
}
