/**
   * Write credential into a document. as is a mime media-type specification and provides the form
   * of the document which is being requested. Two standard document forms are defined. "text/text"
   * encodes the document in a form nice for printing out and "text/xml" which provides an XML
   * format.
   *
   * @param as The mime media type of the encoding format being requested.
   * @return the StructuredDocument which represents this credential.
   * @throws Exception When errors occur.
   */
  public StructuredDocument getDocument(MimeMediaType as) throws Exception {

    StructuredDocument doc = StructuredDocumentFactory.newStructuredDocument(as, "jxta:Cred");

    if (doc instanceof Attributable) {
      ((Attributable) doc).addAttribute("xmlns:jxta", "http://jxta.org");
      ((Attributable) doc).addAttribute("xml:space", "preserve");
      ((Attributable) doc).addAttribute("type", "AuthenticationCredential");
    }

    Element e = doc.createElement("Method", getMethod());

    doc.appendChild(e);

    e = doc.createElement("PeerGroupID", getPeerGroupID().toString());
    doc.appendChild(e);

    e = doc.createElement("PeerID", getPeerID().toString());
    doc.appendChild(e);

    if (null != identityInfo) {
      e = doc.createElement("IdentityInfo");
      doc.appendChild(e);

      StructuredDocumentUtils.copyElements(doc, e, identityInfo);
    }

    return doc;
  }
Example #2
0
  /**
   * {@inheritDoc}
   *
   * <p>
   *
   * <p><emphasis>NB</emphasis>: we do not try to enforce dependency rules such as Proxy only when
   * router, because we want to convey the complete configuration, even items corresponding to not
   * currently enabled features. HttpTransport will gracefully disregard items that have no use in
   * the current context.
   */
  @Override
  public Document getDocument(MimeMediaType encodeAs) {
    if (serverEnabled && (0 == listenPort)) {
      throw new IllegalStateException(
          "Dynmaic port selection not supported with incoming connections.");
    }

    if ((listenPort < -1) || (listenPort > 65535)) {
      throw new IllegalStateException("Illegal Listen Port Value");
    }

    if (!Arrays.asList(CONFIGMODES).contains(configMode)) {
      throw new IllegalStateException("Unsupported configuration mode.");
    }

    // XXX 20050118 bondolo Some versions apparently don't initialize this field. Eventually make it
    // required.
    if (null == getProtocol()) {
      setProtocol("http");
    }

    StructuredDocument adv = (StructuredDocument) super.getDocument(encodeAs);

    if (adv instanceof Attributable) {
      // Only one flag for now. Easy.
      if (publicAddressOnly) {
        ((Attributable) adv).addAttribute(FlagsTag, PublicAddressOnlyAttr);
      }
    }

    Element e1 = adv.createElement(ProtocolTag, getProtocol());

    adv.appendChild(e1);

    if (null != getInterfaceAddress()) {
      Element e2 = adv.createElement(IntfAddrTag, getInterfaceAddress());

      adv.appendChild(e2);
    }

    Element e3 = adv.createElement(ConfModeTag, getConfigMode());

    adv.appendChild(e3);

    Element e4 = adv.createElement(PortTag, Integer.toString(getPort()));

    adv.appendChild(e4);

    Element ext;

    if (proxy != null) {
      ext = adv.createElement(ProxyTag, proxy);
      adv.appendChild(ext);
    }

    // If disabled, say it; otherwise it is assumed on. In published
    // advs, we only keep data for items that are ON, so we do not
    // have to clutter them with the flag.
    if (!proxyEnabled) {
      ext = adv.createElement(ProxyOffTag);
      adv.appendChild(ext);
    }

    if (server != null) {
      ext = adv.createElement(ServerTag, server);
      adv.appendChild(ext);
    }

    // If disabled, say it; otherwise it is assumed on. In published
    // advs, we only keep data for items that are ON, so we do not
    // have to clutter them with the flag.
    if (!serverEnabled) {
      ext = adv.createElement(ServerOffTag);
      adv.appendChild(ext);
    }

    // If disabled, say it; otherwise it is assumed on. In published
    // advs, we only keep data for items that are ON, so we do not
    // have to clutter them with the flag.
    if (!clientEnabled) {
      ext = adv.createElement(ClientOffTag);
      adv.appendChild(ext);
    }

    return adv;
  }