/**
   * Parse the specified VM node, create a VMStandin for it, and add this to the specified
   * container.
   */
  private static void legacyPopulateVMForType(
      IVMInstallType vmType, Element vmElement, VMDefinitionsContainer container) {
    String id = vmElement.getAttribute("name"); // $NON-NLS-1$
    if (id != null) {

      // Retrieve the 'path' attribute.  If none, skip this node.
      String installPath = vmElement.getAttribute("path"); // $NON-NLS-1$
      if (installPath == null) {
        return;
      }

      // Create a VMStandin for the node and set its 'name' & 'installLocation' attributes
      VMStandin vmStandin = new VMStandin(vmType, id);
      vmStandin.setName(id); // $NON-NLS-1$
      File installLocation = new File(installPath);
      //  If the path is to the executable (which it should be), chop off last part of path!
      if (installLocation.isFile()) {
        installLocation = installLocation.getParentFile(); // move up to "bin"
        if (installLocation != null && installLocation.getParentFile() != null) {
          installLocation =
              installLocation.getParentFile(); // this should now be ruby install location
        }
      }
      if (installLocation == null) return;
      vmStandin.setInstallLocation(installLocation);
      container.addVM(vmStandin);
    } else {
      LaunchingPlugin.log(
          LaunchingMessages.RubyRuntime_VM_element_specified_with_no_id_attribute_2);
    }
  }
  /**
   * Parse the specified VM node, create a VMStandin for it, and add this to the specified
   * container.
   */
  private static void populateVMForType(
      IVMInstallType vmType, Element vmElement, VMDefinitionsContainer container) {
    String id = vmElement.getAttribute("id"); // $NON-NLS-1$
    if (id != null) {

      // Retrieve the 'path' attribute.  If none, skip this node.
      String installPath = vmElement.getAttribute("path"); // $NON-NLS-1$
      if (installPath == null) {
        return;
      }

      // Create a VMStandin for the node and set its 'name' & 'installLocation' attributes
      VMStandin vmStandin = new VMStandin(vmType, id);
      vmStandin.setName(vmElement.getAttribute("name")); // $NON-NLS-1$
      File installLocation = new File(installPath);
      vmStandin.setInstallLocation(installLocation);
      container.addVM(vmStandin);

      // Look for subordinate nodes.  These may be 'libraryLocation',
      // 'libraryLocations' or 'versionInfo'.
      NodeList list = vmElement.getChildNodes();
      int length = list.getLength();
      for (int i = 0; i < length; ++i) {
        Node node = list.item(i);
        short type = node.getNodeType();
        if (type == Node.ELEMENT_NODE) {
          Element subElement = (Element) node;
          String subElementName = subElement.getNodeName();
          if (subElementName.equals("libraryLocation")) { // $NON-NLS-1$
            IPath loc = getLibraryLocation(subElement);
            vmStandin.setLibraryLocations(new IPath[] {loc});
            break;
          } else if (subElementName.equals("libraryLocations")) { // $NON-NLS-1$
            setLibraryLocations(vmStandin, subElement);
            break;
          }
        }
      }

      // vm Arguments
      String vmArgs = vmElement.getAttribute("vmargs"); // $NON-NLS-1$
      if (vmArgs != null && vmArgs.length() > 0) {
        vmStandin.setVMArgs(vmArgs);
      }
    } else {
      LaunchingPlugin.log(
          LaunchingMessages.RubyRuntime_VM_element_specified_with_no_id_attribute_2);
    }
  }
  /**
   * Return the VM definitions contained in this object as a String of XML. The String is suitable
   * for storing in the workbench preferences.
   *
   * <p>The resulting XML is compatible with the static method <code>parseXMLIntoContainer</code>.
   *
   * @return String the results of flattening this object into XML
   * @throws IOException if this method fails. Reasons include:
   *     <ul>
   *       <li>serialization of the XML document failed
   *     </ul>
   *
   * @throws ParserConfigurationException if creation of the XML document failed
   * @throws TransformerException if serialization of the XML document failed
   */
  public String getAsXML() throws ParserConfigurationException, IOException, TransformerException {

    // Create the Document and the top-level node
    Document doc = LaunchingPlugin.getDocument();
    Element config = doc.createElement("vmSettings"); // $NON-NLS-1$
    doc.appendChild(config);

    // Set the defaultVM attribute on the top-level node
    if (getDefaultVMInstallCompositeID() != null) {
      config.setAttribute("defaultVM", getDefaultVMInstallCompositeID()); // $NON-NLS-1$
    }

    // Create a node for each install type represented in this container
    Set vmInstallTypeSet = getVMTypeToVMMap().keySet();
    Iterator keyIterator = vmInstallTypeSet.iterator();
    while (keyIterator.hasNext()) {
      IVMInstallType vmInstallType = (IVMInstallType) keyIterator.next();
      Element vmTypeElement = vmTypeAsElement(doc, vmInstallType);
      config.appendChild(vmTypeElement);
    }

    // Serialize the Document and return the resulting String
    return LaunchingPlugin.serializeDocument(doc);
  }
  /**
   * For the specified vm type node, parse all subordinate VM definitions and add them to the
   * specified container.
   */
  private static void populateVMTypes(Element vmTypeElement, VMDefinitionsContainer container) {

    // Retrieve the 'id' attribute and the corresponding VM type object
    String id = vmTypeElement.getAttribute("id"); // $NON-NLS-1$
    IVMInstallType vmType = RubyRuntime.getVMInstallType(id);
    if (vmType != null) {

      // For each VM child node, populate the container with a subordinate node
      NodeList vmNodeList = vmTypeElement.getChildNodes();
      for (int i = 0; i < vmNodeList.getLength(); ++i) {
        Node vmNode = vmNodeList.item(i);
        short type = vmNode.getNodeType();
        if (type == Node.ELEMENT_NODE) {
          Element vmElement = (Element) vmNode;
          if (vmElement.getNodeName().equalsIgnoreCase("vm")) { // $NON-NLS-1$
            populateVMForType(vmType, vmElement, container);
          }
        }
      }
    } else {
      LaunchingPlugin.log(LaunchingMessages.RubyRuntime_VM_type_element_with_unknown_id_1);
    }
  }
 private IRubyInformation getRubyInformation() {
   return LaunchingPlugin.getRubyInformation();
 }