]> sjero.net Git - linphone/blob - p2pproxy/dependencies-src/jxse-src-2.5/api/src/net/jxta/protocol/ResolverQueryMsg.java
1ad545aeec37f33c26a62034198c2b4b545e5cd3
[linphone] / p2pproxy / dependencies-src / jxse-src-2.5 / api / src / net / jxta / protocol / ResolverQueryMsg.java
1 /*
2  * Copyright (c) 2001-2007 Sun Microsystems, Inc.  All rights reserved.
3  *  
4  *  The Sun Project JXTA(TM) Software License
5  *  
6  *  Redistribution and use in source and binary forms, with or without 
7  *  modification, are permitted provided that the following conditions are met:
8  *  
9  *  1. Redistributions of source code must retain the above copyright notice,
10  *     this list of conditions and the following disclaimer.
11  *  
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.
15  *  
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.
21  *  
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.
26  *  
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.
29  *  
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.
40  *  
41  *  JXTA is a registered trademark of Sun Microsystems, Inc. in the United 
42  *  States and other countries.
43  *  
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.
47  *  
48  *  ====================================================================
49  *  
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.
53  *  
54  *  This license is based on the BSD license adopted by the Apache Foundation. 
55  */
56 package net.jxta.protocol;
57
58 import java.net.URI;
59
60 import net.jxta.document.Document;
61 import net.jxta.document.MimeMediaType;
62 import net.jxta.document.StructuredDocument;
63 import net.jxta.id.ID;
64
65 /**
66  * Generic Resolver Service message "Query".
67  *
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>
71  */
72 public abstract class ResolverQueryMsg {
73
74     /**
75      * credential
76      */
77     private StructuredDocument credential = null;
78
79     /**
80      * Resolver query handler
81      */
82     private String handlername = null;
83
84     /**
85      * Number of times a message has been forwarded, not propagated or walked
86      */
87     protected int hopcount = 0;
88
89     /**
90      * Resolver query
91      */
92     private String query = null;
93
94     /**
95      * Query ID of this query. Unique to the originating node only, it can be
96      * utilized to match queries to responses.
97      */
98     protected int queryid = 0;
99
100     /**
101      * issuer of the query
102      */
103     private ID srcPeerId = null;
104
105     /**
106      * Optional route info about the issuer
107      */
108     private RouteAdvertisement srcPeerRoute = null;
109
110     /**
111      * returns the credential
112      *
113      * @return String credential
114      */
115     public StructuredDocument getCredential() {
116         return credential;
117     }
118
119     /**
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.
125      *
126      * @param asMimeType mime-type requested representation for the returned
127      *                   document
128      * @return Document document representing the advertisement
129      */
130     public abstract Document getDocument(MimeMediaType asMimeType);
131
132     /**
133      * returns the handlername
134      *
135      * @return String handlername name
136      */
137     public String getHandlerName() {
138         return handlername;
139     }
140
141     /**
142      * returns the hop count
143      *
144      * @return int hop count
145      */
146     public int getHopCount() {
147         return hopcount;
148     }
149
150     /**
151      * increment hop count
152      */
153     public void incrementHopCount() {
154         hopcount++;
155     }
156
157     /**
158      * Set hop count
159      *
160      * @param newCount hop count
161      */
162     public void setHopCount(int newCount) {
163         hopcount = newCount;
164     }
165
166     /**
167      * returns the query
168      *
169      * @return String value of the query
170      */
171     public String getQuery() {
172         return query;
173     }
174
175     /**
176      * returns queryid value
177      *
178      * @return int queryid value
179      */
180     public int getQueryId() {
181         return queryid;
182     }
183
184     /**
185      * Returns the source of the query
186      *
187      * @return String the peerid of the source of the query
188      * @deprecated Use {@link #getSrcPeer()} instead.
189      */
190     @Deprecated
191     public String getSrc() {
192         return (null == srcPeerId) ? null : srcPeerId.toString();
193     }
194
195     /**
196      * Returns the source of the query
197      *
198      * @return The peerid of the source of the query
199      */
200     public ID getSrcPeer() {
201         return (null == srcPeerId) ? null : srcPeerId;
202     }
203
204     /**
205      * Returns the source route of the query
206      *
207      * @return RouteAdvertisement route to the issuer of the query
208      */
209
210     public RouteAdvertisement getSrcPeerRoute() {
211         if (srcPeerRoute == null) {
212             return null;
213         } else {
214             return srcPeerRoute.clone();
215         }
216     }
217
218     /**
219      * set the credential
220      *
221      * @param cred string representing credential
222      */
223     public void setCredential(StructuredDocument cred) {
224         this.credential = cred;
225     }
226
227     /**
228      * set the handlername
229      *
230      * @param name handler name
231      */
232     public void setHandlerName(String name) {
233         this.handlername = name;
234     }
235
236     /**
237      * set the Query string
238      *
239      * @param Query string representing the query
240      */
241     public void setQuery(String Query) {
242         this.query = Query;
243     }
244
245     /**
246      * set the query id. Each query has a unique id.
247      *
248      * @param id int id
249      */
250     public void setQueryId(int id) {
251         queryid = id;
252     }
253
254     /**
255      * set the source route of the query
256      *
257      * @param route route advertisement of the source peer
258      */
259     public void setSrcPeerRoute(RouteAdvertisement route) {
260         srcPeerRoute = route;
261     }
262
263     /**
264      * Set the source of the query
265      *
266      * @param src is a containing the peerid of the source
267      * @deprecated Use {@link #setSrcPeer(ID)} instead.
268      */
269     @Deprecated
270     public void setSrc(String src) {
271         if (null == src) {
272             setSrcPeer(null);
273         } else {
274             setSrcPeer(ID.create(URI.create(src)));
275         }
276     }
277
278     /**
279      * Set the source of the query
280      *
281      * @param srcPeer the peerid of the source
282      */
283     public void setSrcPeer(ID srcPeer) {
284         srcPeerId = srcPeer;
285     }
286
287     /**
288      * All messages have a type (in xml this is !doctype) which identifies the
289      * message
290      *
291      * @return String "jxta:ResolverQuery"
292      */
293     public static String getAdvertisementType() {
294         return "jxta:ResolverQuery";
295     }
296
297     /**
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.
303      * <p/>
304      * WARNING: A side effect of this call is that the following fields are
305      * transfered from the query to the response:
306      * - HandlerName
307      * - QueryId
308      *
309      * @return ResolverResponseMsg resolverResponse built from the resolverQuery msg
310      */
311     public abstract ResolverResponseMsg makeResponse();
312 }