/**
  * Retrieves the listener properties from the server.xml file, then creates the jmx.url based on
  * the properties.
  *
  * @param config The ConfigResponse object.
  * @param basePath The base file path of the configuration, "/conf/server.xml" is added to this.
  * @return Whether the configuration was found and set on the config response object.
  * @throws PluginException
  */
 private boolean configureListenerMxURL(ConfigResponse config, String basePath)
     throws PluginException {
   boolean found = false;
   XmlPropertiesFileRetriever propertiesRetriever = new ServerXmlPropertiesRetriever();
   try {
     Map<String, String> listenerProperties =
         propertiesRetriever.getPropertiesFromFile(
             basePath + "/conf/server.xml",
             "Listener",
             "className",
             "com.springsource.tcserver.serviceability.rmi.JmxSocketListener");
     if (!listenerProperties.isEmpty()) {
       String addressProperty = listenerProperties.get("address");
       if (addressProperty == null) {
         addressProperty = listenerProperties.get("bind");
       }
       String bindAddressValue = getValueFromPropertiesFile(basePath, addressProperty);
       String portValue = getValueFromPropertiesFile(basePath, listenerProperties.get("port"));
       config.setValue(
           mxUtil.getJmxUrlProperty(),
           "service:jmx:rmi:///jndi/rmi://" + bindAddressValue + ":" + portValue + "/jmxrmi");
       found = true;
     }
   } catch (PluginException e) {
     // the properties were not accessible
     config.setValue(mxUtil.getJmxUrlProperty(), DEFAULT_JMX_URL);
     logger.warn(
         "Unable to retrieve properties for discovery, using default "
             + mxUtil.getJmxUrlProperty()
             + "="
             + DEFAULT_JMX_URL);
     if (logger.isDebugEnabled()) {
       logger.debug(e.getMessage(), e);
     }
   }
   return found;
 }
  private ServerResource createTcRuntimeServerResource(
      String catalinaHome, String catalinaBase, String[] processArgs, MxProcess process)
      throws PluginException {

    String query = PROC_JAVA + ",Args.*.eq=-D" + getProcHomeProperty() + "=" + catalinaBase;

    // Create the server resource
    ServerResource server = newServerResource(catalinaBase);
    server.setDescription(getServerDescription(server.getInstallPath()));
    adjustClassPath(catalinaBase);

    ConfigResponse config = new ConfigResponse();
    ConfigSchema schema =
        getConfigSchema(getTypeInfo().getName(), ProductPlugin.CFGTYPE_IDX_PRODUCT);

    if (schema != null) {
      ConfigOption option = schema.getOption(PROP_PROCESS_QUERY);

      if (option != null) {
        // Configure process.query
        config.setValue(option.getName(), query);
      }
    }

    if (process.getURL() != null) {
      config.setValue(mxUtil.getJmxUrlProperty(), process.getURL());
    } else {
      String[] args = process.getArgs();
      for (int j = 0; j < args.length; j++) {
        if (configureListenerMxURL(config, catalinaBase)) {
          break;
        } else if (configureMxURL(config, args[j])) {
          break;
        } else if (configureLocalMxURL(config, args[j], query)) {
          // continue as .port might come later
        }
      }
    }

    storeProcessUserAndGroup(process, config);

    config.setValue(SERVER_RESOURCE_CONFIG_CATALINA_BASE, catalinaBase);
    config.setValue(SERVER_RESOURCE_CONFIG_CATALINA_HOME, catalinaHome);

    // default anything not auto-configured
    config.setValue("jmx.password", getJMXPassword(catalinaBase));
    setProductConfig(server, config, process.getPid());
    discoverServerConfig(server, process.getPid());

    server.setMeasurementConfig();
    // must set control config now so user doesn't have to enter config
    // properties prior to executing control actions
    server.setControlConfig();
    server.setName(
        getPlatformName()
            + " "
            + getServerName("tc Runtime")
            + " "
            + getBaseDirectoryName(catalinaBase));

    ConfigResponse controlConfig = new ConfigResponse();

    String controlProgram = determineControlProgram(catalinaHome, catalinaBase);
    controlConfig.setValue(ServerControlPlugin.PROP_PROGRAM, controlProgram);
    server.setControlConfig(controlConfig);
    return server;
  }