/** {@inheritDoc} */ @Override public Document getDocument(MimeMediaType asMimeType) { StructuredDocument adv = StructuredDocumentFactory.newStructuredDocument(asMimeType, getAdvertisementType()); if (adv instanceof XMLDocument) { XMLDocument xmlDoc = (XMLDocument) adv; xmlDoc.addAttribute("xmlns:jxta", "http://jxta.org"); xmlDoc.addAttribute("xml:space", "preserve"); } Element e; e = adv.createElement(typeTag, Integer.toString(getDiscoveryType())); adv.appendChild(e); int threshold = getThreshold(); if (threshold < 0) { throw new IllegalStateException("threshold must be >= 0"); } e = adv.createElement(thresholdTag, Integer.toString(threshold)); adv.appendChild(e); PeerAdvertisement peerAdv = getPeerAdvertisement(); if ((peerAdv != null)) { e = adv.createElement(peerAdvTag, peerAdv.toString()); adv.appendChild(e); } String attr = getAttr(); if ((attr != null) && (attr.length() > 0)) { e = adv.createElement(queryAttrTag, attr.trim()); adv.appendChild(e); String value = getValue(); if ((value != null) && (value.length() > 0)) { e = adv.createElement(queryValueTag, value.trim()); adv.appendChild(e); } else { if (threshold < 0) { throw new IllegalStateException("Attribute specified, but no value was specified."); } } } return adv; }
/** * {@inheritDoc} * * @param encodeAs Description of the Parameter * @return The document value */ public Document getDocument(MimeMediaType encodeAs) { StructuredDocument adv = (StructuredDocument) super.getDocument(encodeAs); if (hasALoop()) { throw new IllegalStateException("I won't write a doc for a route with a loop"); } PeerID pid = getDestPeerID(); AccessPointAdvertisement dest = getDest(); if ((null != pid) && (null != dest) && (null != dest.getPeerID())) { if (!pid.equals(dest.getPeerID())) { throw new IllegalStateException( "Destination peer id and destination access point adv don't refer to the same peer"); } } // HACK Backwards Compatibility if ((null == pid) && (null != dest)) { pid = dest.getPeerID(); } if (pid != null) { Element e0 = adv.createElement(DEST_PID_TAG, pid.toString()); adv.appendChild(e0); } if (dest != null) { // create the copy without the PID AccessPointAdvertisement ap = (AccessPointAdvertisement) AdvertisementFactory.newAdvertisement( AccessPointAdvertisement.getAdvertisementType()); ap.setEndpointAddresses(dest.getVectorEndpointAddresses()); StructuredTextDocument xptDoc = (StructuredTextDocument) ap.getDocument(encodeAs); Element e1 = adv.createElement("Dst"); adv.appendChild(e1); StructuredDocumentUtils.copyElements(adv, e1, xptDoc); } // only include hops if we have some if (getHops().hasMoreElements()) { Element e2 = adv.createElement("Hops"); adv.appendChild(e2); for (Enumeration e = getHops(); e.hasMoreElements(); ) { AccessPointAdvertisement hop = (AccessPointAdvertisement) e.nextElement(); if (hop != null) { StructuredTextDocument xptDoc = (StructuredTextDocument) hop.getDocument(encodeAs); StructuredDocumentUtils.copyElements(adv, e2, xptDoc); } } } return adv; }