@Override
  final void execute(final CommandLine commandLine) throws Exception {
    ensureProxyExists(commandLine);
    final ConfProxyProperties conf = loadConf(commandLine);

    ConfigurationAnchor sourceAnchor = null;
    try {
      sourceAnchor = new ConfigurationAnchor(conf.getProxyAnchorPath());
    } catch (Exception ex) {
      fail("Could not load source anchor: ", ex);
    }
    String instance = sourceAnchor.getInstanceIdentifier();

    if (conf.getConfigurationProxyURL().equals("0.0.0.0")) {
      fail("configuration-proxy.address has not been" + " configured in 'local.ini'!", null);
    }

    if (conf.getKeyList().isEmpty()) {
      fail("No signing keys configured!", null);
    }

    if (commandLine.hasOption("filename")) {
      String filename = commandLine.getOptionValue("f");

      try {
        AtomicSave.execute(filename, "tmpanchor", out -> generateAnchorXml(conf, instance, out));
      } catch (AccessDeniedException ex) {
        fail("Cannot write anchor to '" + filename + "', permission denied. ", ex);
      }
      System.out.println("Generated anchor xml to '" + filename + "'");
    } else {
      printHelp();
    }
  }
  /**
   * Generates an achor xml file based on the provided proxy configuration properties and writes it
   * to the provided output stream.
   *
   * @param conf configuration proxy properties instance
   * @param instanceIdentifier instance identifier of the resulting anchor
   * @param out the output stream for writing the generated xml
   * @throws Exception if xml generation fails
   */
  private void generateAnchorXml(
      final ConfProxyProperties conf, final String instanceIdentifier, final OutputStream out)
      throws Exception {
    JAXBContext jaxbCtx = JAXBContext.newInstance(ObjectFactory.class);
    Marshaller marshaller = jaxbCtx.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    ObjectFactory factory = new ObjectFactory();
    ConfigurationSourceType sourceType = factory.createConfigurationSourceType();
    sourceType.setDownloadURL(
        conf.getConfigurationProxyURL() + "/" + OutputBuilder.SIGNED_DIRECTORY_NAME);
    for (byte[] cert : conf.getVerificationCerts()) {
      sourceType.getVerificationCert().add(cert);
    }
    ConfigurationAnchorType anchorType = factory.createConfigurationAnchorType();
    anchorType.setInstanceIdentifier(instanceIdentifier);
    GregorianCalendar gcal = new GregorianCalendar();
    gcal.setTimeZone(TimeZone.getTimeZone("UTC"));
    XMLGregorianCalendar xgcal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal);
    anchorType.setGeneratedAt(xgcal);
    anchorType.getSource().add(sourceType);
    JAXBElement<ConfigurationAnchorType> root = factory.createConfigurationAnchor(anchorType);

    marshaller.marshal(root, out);
  }