public void deleteResource() throws Exception {
   JBossASServerComponent jbossASComponent = getResourceContext().getParentResourceComponent();
   File deploymentFile =
       jbossASComponent.getDeploymentFilePath(getResourceContext().getResourceKey());
   assert deploymentFile.exists()
       : "Deployment file "
           + deploymentFile
           + " doesn't exist for resource "
           + getResourceContext().getResourceKey();
   ConnectionFactoryConfigurationEditor.deleteConnectionFactory(deploymentFile, this.name);
   jbossASComponent.redeployFile(deploymentFile);
 }
  @Override
  public void updateResourceConfiguration(ConfigurationUpdateReport report) {
    JBossASServerComponent parentComponent = getResourceContext().getParentResourceComponent();

    File deploymentFile =
        parentComponent.getDeploymentFilePath(getResourceContext().getResourceKey());

    if (deploymentFile == null) {
      report.setErrorMessage(
          "Parent resource is currently down. Unable to complete update of connection factory "
              + this.name);
      report.setStatus(ConfigurationUpdateStatus.FAILURE);
    } else {
      if (!deploymentFile.exists()) {
        deploymentFile = new File(parentComponent.getConfigurationPath(), this.name + "-ds.xml");
      }

      ConnectionFactoryConfigurationEditor.updateConnectionFactory(
          deploymentFile, this.name, report);
    }
  }
  public CreateResourceReport createResource(CreateResourceReport report) {

    JBossASServerComponent parentResourceComponent =
        getResourceContext().getParentResourceComponent();

    String resourceTypeName = report.getResourceType().getName();

    String objectNamePreString;
    boolean isTopic = false;
    if (resourceTypeName.contains("Topic")) {
      objectNamePreString = TOPIC_MBEAN_NAME;
      isTopic = true;
    } else {
      objectNamePreString = QUEUE_MBEAN_NAME;
    }

    Configuration config = report.getResourceConfiguration();

    String name = config.getSimple("MBeanName").getStringValue();
    PropertySimple nameTemplateProp = report.getPluginConfiguration().getSimple("nameTemplate");
    String rName = nameTemplateProp.getStringValue();
    //noinspection ConstantConditions
    rName = rName.replace("{name}", name);

    EmsConnection connection = parentResourceComponent.getEmsConnection();

    if (DeploymentUtility.isDuplicateJndiName(connection, objectNamePreString, name)) {
      report.setStatus(CreateResourceStatus.FAILURE);
      report.setErrorMessage("Duplicate JNDI Name, a resource with that name already exists");
      return report;
    }
    PropertySimple pluginNameProperty = new PropertySimple("name", rName);
    getResourceContext().getPluginConfiguration().put(pluginNameProperty);

    File deployDir = new File(parentResourceComponent.getConfigurationPath() + "/deploy");
    File deploymentFile =
        new File(deployDir, FileNameUtility.formatFileName(name) + "-destination-service.xml");

    xmlEditor = new JBossMessagingConfigurationEditor(resourceTypeName);
    xmlEditor.updateConfiguration(deploymentFile, name, report);
    try {
      parentResourceComponent.deployFile(deploymentFile);
    } catch (Exception e) {
      JBossASServerComponent.setErrorOnCreateResourceReport(report, e.getLocalizedMessage(), e);
      return report;
    }

    // This key needs to be the same as the object name string used in discovery, defined in the
    // plugin descriptor
    //   jboss.messaging.destination:service=<Queue|Topic>,name=%name%
    String serviceString = (isTopic ? "Topic" : "Queue");

    String objectName = "jboss.messaging.destination:name=" + name + ",service=" + serviceString;
    try {
      // IMPORTANT: The object name must be canonicalized so it matches the resource key that
      //            MBeanResourceDiscoveryComponent uses, which is the canonical object name.
      objectName = getCanonicalName(objectName);
      report.setResourceKey(objectName);
    } catch (MalformedObjectNameException e) {
      log.warn("Invalid key [" + objectName + "]: " + e.getMessage());
      return report;
    }
    report.setResourceName(rName);

    try {
      Thread.sleep(5000L);
    } catch (InterruptedException e) {
      log.info("Sleep after datasource create interrupted", e);
      Thread.currentThread().interrupt();
    }

    return report;
  }