/**
   * This routine will get the StandaloneServerConfig or ClusterConfig by the given target name.
   *
   * @param MBeanServerConnection
   * @param targetName
   * @return ObjectName
   */
  private ObjectName getTargetConfigObjectName(
      final MBeanServerConnection mbsc, final String targetName) throws CommandException {
    try {
      ObjectName scON = Util.newObjectName(SERVER_CONFIG_OBJECT_NAME + targetName);
      if (!mbsc.isRegistered(scON))
        scON = Util.newObjectName(CLUSTER_CONFIG_OBJECT_NAME + targetName);
      if (!mbsc.isRegistered(scON))
        throw new CommandException(getLocalizedString("InvalidTargetName"));

      return scON;
    } catch (RuntimeOperationsException roe) {
      throw new CommandException(roe);
    } catch (IOException ioe) {
      throw new CommandException(ioe);
    }
  }
  protected final AMXConfig createProgeny(final String name, final Map<String, String> options) {
    final String poolName =
        ConnectorConnectionPoolConfigTest.ensureDefaultInstance(getDomainConfig()).getName();

    assert (getDomainConfig().getConnectorResourceConfigMap().get(name) == null)
        : "A resource already exists with name: " + name;

    final Set<ResourceRefConfig> resourceRefs =
        getQueryMgr().queryJ2EETypeNameSet(XTypes.RESOURCE_REF_CONFIG, name);

    ConnectorResourceConfig config = null;

    final Set<ObjectName> resourceRefObjectNames = Util.toObjectNames(resourceRefs);
    if (resourceRefs.size() != 0) {
      assert (false);
      warning(
          "A DANGLING resource ref already exists with name: "
              + name
              + ", {"
              + CollectionUtil.toString(resourceRefObjectNames)
              + "} (SKIPPING TEST)");
    } else {
      config = getDomainConfig().createConnectorResourceConfig(name, poolName, options);

      final Set<ResourceRefConfig> refs =
          getQueryMgr().queryJ2EETypeNameSet(XTypes.RESOURCE_REF_CONFIG, name);
      if (resourceRefs.size() != 0) {
        final ResourceRefConfig ref = refs.iterator().next();

        warning(
            "A resource ref within "
                + Util.getObjectName(ref.getContainer())
                + " was automatically created when creating the ConnectorResourceConfig ");
      }
    }

    addReference(config);

    return (config);
  }
  /**
   * An abstract method that Executes the command
   *
   * @throws CommandException
   */
  public void runCommand() throws CommandException, CommandValidationException {
    if (!validateOptions()) throw new CommandValidationException("Validation is false");

    // use http connector
    MBeanServerConnection mbsc =
        getMBeanServerConnection(
            getHost(), getPort(),
            getUser(), getPassword());
    final String targetName = (String) getOption(TARGET_NAME);

    // if targetName is not null, then try to get the Config ObjectName of the
    // target before creating the resource because we don't want to create
    // the resource if the target does not exist.
    ObjectName scON =
        (targetName != null && !targetName.equals(DOMAIN))
            ? getTargetConfigObjectName(mbsc, targetName)
            : null;

    final Object[] params = getParamsInfo();
    final String operationName = getOperationName();
    final String[] types = getTypesInfo();

    try {
      Object returnValue =
          mbsc.invoke(Util.newObjectName(DOMAIN_CONFIG_OBJECT_NAME), operationName, params, types);
      if (scON != null) {
        // create reference to the target
        mbsc.invoke(
            scON,
            "createResourceRefConfig",
            new Object[] {new String((String) getOperands().get(0))},
            new String[] {"java.lang.String"});
      }
      CLILogger.getInstance()
          .printDetailMessage(getLocalizedString("CommandSuccessful", new Object[] {name}));

    } catch (Exception e) {
      displayExceptionMessage(e);
    }
  }