2 * Copyright (c) 2001-2007 Sun Microsystems, Inc. All rights reserved.
4 * The Sun Project JXTA(TM) Software License
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * 3. The end-user documentation included with the redistribution, if any, must
17 * include the following acknowledgment: "This product includes software
18 * developed by Sun Microsystems, Inc. for JXTA(TM) technology."
19 * Alternately, this acknowledgment may appear in the software itself, if
20 * and wherever such third-party acknowledgments normally appear.
22 * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must
23 * not be used to endorse or promote products derived from this software
24 * without prior written permission. For written permission, please contact
25 * Project JXTA at http://www.jxta.org.
27 * 5. Products derived from this software may not be called "JXTA", nor may
28 * "JXTA" appear in their name, without prior written permission of Sun.
30 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
32 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SUN
33 * MICROSYSTEMS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
36 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
37 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
38 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
39 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 * JXTA is a registered trademark of Sun Microsystems, Inc. in the United
42 * States and other countries.
44 * Please see the license information page at :
45 * <http://www.jxta.org/project/www/license.html> for instructions on use of
46 * the license in source files.
48 * ====================================================================
50 * This software consists of voluntary contributions made by many individuals
51 * on behalf of Project JXTA. For more information on Project JXTA, please see
52 * http://www.jxta.org.
54 * This license is based on the BSD license adopted by the Apache Foundation.
56 package net.jxta.protocol;
60 import net.jxta.document.Document;
61 import net.jxta.document.MimeMediaType;
62 import net.jxta.document.StructuredDocument;
63 import net.jxta.id.ID;
66 * Generic Resolver Service message "Query".
68 * @see net.jxta.resolver.ResolverService
69 * @see net.jxta.protocol.ResolverResponseMsg
70 * @see <a href="https://jxta-spec.dev.java.net/nonav/JXTAProtocols.html#proto-prp" target="_blank">JXTA Protocols Specification : Peer Resolver Protocol</a>
72 public abstract class ResolverQueryMsg {
77 private StructuredDocument credential = null;
80 * Resolver query handler
82 private String handlername = null;
85 * Number of times a message has been forwarded, not propagated or walked
87 protected int hopcount = 0;
92 private String query = null;
95 * Query ID of this query. Unique to the originating node only, it can be
96 * utilized to match queries to responses.
98 protected int queryid = 0;
101 * issuer of the query
103 private ID srcPeerId = null;
106 * Optional route info about the issuer
108 private RouteAdvertisement srcPeerRoute = null;
111 * returns the credential
113 * @return String credential
115 public StructuredDocument getCredential() {
120 * Write advertisement into a document. asMimeType is a mime media-type
121 * specification and provides the form of the document which is being
122 * requested. Two standard document forms are defined. 'text/text' encodes
123 * the document in a form nice for printing out and 'text/xml' which
124 * provides an XML format.
126 * @param asMimeType mime-type requested representation for the returned
128 * @return Document document representing the advertisement
130 public abstract Document getDocument(MimeMediaType asMimeType);
133 * returns the handlername
135 * @return String handlername name
137 public String getHandlerName() {
142 * returns the hop count
144 * @return int hop count
146 public int getHopCount() {
151 * increment hop count
153 public void incrementHopCount() {
160 * @param newCount hop count
162 public void setHopCount(int newCount) {
169 * @return String value of the query
171 public String getQuery() {
176 * returns queryid value
178 * @return int queryid value
180 public int getQueryId() {
185 * Returns the source of the query
187 * @return String the peerid of the source of the query
188 * @deprecated Use {@link #getSrcPeer()} instead.
191 public String getSrc() {
192 return (null == srcPeerId) ? null : srcPeerId.toString();
196 * Returns the source of the query
198 * @return The peerid of the source of the query
200 public ID getSrcPeer() {
201 return (null == srcPeerId) ? null : srcPeerId;
205 * Returns the source route of the query
207 * @return RouteAdvertisement route to the issuer of the query
210 public RouteAdvertisement getSrcPeerRoute() {
211 if (srcPeerRoute == null) {
214 return srcPeerRoute.clone();
221 * @param cred string representing credential
223 public void setCredential(StructuredDocument cred) {
224 this.credential = cred;
228 * set the handlername
230 * @param name handler name
232 public void setHandlerName(String name) {
233 this.handlername = name;
237 * set the Query string
239 * @param Query string representing the query
241 public void setQuery(String Query) {
246 * set the query id. Each query has a unique id.
250 public void setQueryId(int id) {
255 * set the source route of the query
257 * @param route route advertisement of the source peer
259 public void setSrcPeerRoute(RouteAdvertisement route) {
260 srcPeerRoute = route;
264 * Set the source of the query
266 * @param src is a containing the peerid of the source
267 * @deprecated Use {@link #setSrcPeer(ID)} instead.
270 public void setSrc(String src) {
274 setSrcPeer(ID.create(URI.create(src)));
279 * Set the source of the query
281 * @param srcPeer the peerid of the source
283 public void setSrcPeer(ID srcPeer) {
288 * All messages have a type (in xml this is !doctype) which identifies the
291 * @return String "jxta:ResolverQuery"
293 public static String getAdvertisementType() {
294 return "jxta:ResolverQuery";
298 * Create a ResolverResponse from a ResolverQuery message. This method
299 * takes advantage of any internal information available in an incoming
300 * Resolver query to build a resolver response for that query. For instance,
301 * optional route information which may be available in the query will
302 * be used to bypass the route resolution to send the response.
304 * WARNING: A side effect of this call is that the following fields are
305 * transfered from the query to the response:
309 * @return ResolverResponseMsg resolverResponse built from the resolverQuery msg
311 public abstract ResolverResponseMsg makeResponse();