/** @see Command */
 public void execute() {
   results = new ArrayList();
   validatateXml();
   if (isValidateNested()) {
     List archives = archive.getArchiveFiles();
     for (int i = 0; i < archives.size(); i++) {
       Archive a = (Archive) archives.get(i);
       if (!a.isModuleFile()) continue;
       ModuleFile m = (ModuleFile) a;
       ValidateXmlCommand cmd = new ValidateXmlCommand(m);
       cmd.execute();
       results.addAll(cmd.getResult());
     }
   }
 }
  protected void validatateXml() {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Resource res = archive.getStandardDeploymentDescriptor().eResource();
    XmlValidationResult result = new XmlValidationResult();
    result.setArchive(archive);
    try {
      res.save(bos, new java.util.HashMap());
    } catch (Exception ex) {
      throw new org.eclipse.jst.j2ee.commonarchivecore.internal.exception.ArchiveRuntimeException(
          ex);
    }
    ByteArrayInputStream inStream = new ByteArrayInputStream(bos.toByteArray());
    InputSource source = new InputSource(inStream);
    CollectingErrorHandler handler = new CollectingErrorHandler();
    XmlDocumentReader parseAdapter = new XmlDocumentReader(source, null, handler);

    // the following try/catch clause is added to handle the case
    // when SAX parser throws a fatal exception (type SAXException)
    // for unmatching end tag that results in a RuntimeException to
    // be thrown. Need to catch it so we can get the parser exceptions
    // and display them to the user.
    try {
      parseAdapter.parseDocument();
    } catch (RuntimeException re) {

      if (handler.getCaughtExceptions() != null) {
        result.setArchive(archive);
        result.setCaughtExceptions(handler.getCaughtExceptions());
        results.add(result);
      }

      throw re;
    }

    result.setArchive(archive);
    result.setCaughtExceptions(handler.getCaughtExceptions());
    results.add(result);
  }