]> sjero.net Git - linphone/blob - p2pproxy/dependencies-src/jxse-src-2.5/api/src/net/jxta/protocol/PipeAdvertisement.java
remove mediastreamer2 and add it as a submodule instead.
[linphone] / p2pproxy / dependencies-src / jxse-src-2.5 / api / src / net / jxta / protocol / PipeAdvertisement.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
57 package net.jxta.protocol;
58
59
60 import net.jxta.document.ExtendableAdvertisement;
61 import net.jxta.document.Element;
62 import net.jxta.document.MimeMediaType;
63 import net.jxta.document.StructuredDocument;
64 import net.jxta.document.StructuredDocumentFactory;
65 import net.jxta.document.StructuredDocumentUtils;
66 import net.jxta.id.ID;
67
68
69 /**
70  *  Describes a JXTA Pipe. A pipe is described by a pipe id and by a pipe type.
71  *  A pipe can also optionally have a name and/or a description.
72  *
73  *  @see net.jxta.pipe.PipeService
74  *  @see <a href="https://jxta-spec.dev.java.net/nonav/JXTAProtocols.html#proto-pbp" target="_blank">JXTA Protocols Specification : Pipe Binding Protocol</a>
75  */
76 public abstract class PipeAdvertisement extends ExtendableAdvertisement implements Cloneable {
77
78     /**
79      * XML tag to store the PipeID
80      */
81     public static final String IdTag = "Id";
82
83     /**
84      * XML tag to store the Pipe Type
85      */
86     public static final String TypeTag = "Type";
87
88     /**
89      * XML tag to store the name of the Pipe
90      */
91     public static final String NameTag = "Name";
92
93     /**
94      * XML tag to store the name of the Pipe
95      */
96     public static final String descTag = "Desc";
97
98     private transient ID pipeId = ID.nullID;
99     private String type = null;
100     private String name = null;
101
102     /**
103      * Descriptive meta-data about this pipe.
104      */
105     private Element description = null;
106
107     /**
108      *  Returns the identifying type of this Advertisement.
109      *
110      *  @return String the type of advertisement
111      */
112     public static String getAdvertisementType() {
113         return "jxta:PipeAdvertisement";
114     }
115
116     /**
117      *  {@inheritDoc}
118      */
119     @Override
120     public PipeAdvertisement clone() {
121         try {
122             PipeAdvertisement likeMe = (PipeAdvertisement) super.clone();
123
124             likeMe.setPipeID(getPipeID());
125             likeMe.setType(getType());
126             likeMe.setName(getName());
127             likeMe.setDesc(getDesc());
128
129             return likeMe;
130         } catch (CloneNotSupportedException impossible) {
131             throw new Error("Object.clone() threw CloneNotSupportedException", impossible);
132         }
133     }
134
135     /**
136      *  {@inheritDoc}
137      */
138     @Override
139     public boolean equals(Object obj) {
140
141         if (this == obj) {
142             return true;
143         }
144
145         if (obj instanceof PipeAdvertisement) {
146             PipeAdvertisement likeMe = (PipeAdvertisement) obj;
147
148             if (!getPipeID().equals(likeMe.getPipeID())) {
149                 return false;
150             }
151
152             if (!getType().equals(likeMe.getType())) {
153                 return false;
154             }
155
156             String pipeName = getName();
157
158             if (pipeName == null ? likeMe.getName() != null : !pipeName.equals(likeMe.getName())) {
159                 return false;
160             }
161
162             String pipeDescription = getDescription();
163
164             return !(pipeDescription == null ? likeMe.getDescription() != null : pipeDescription.equals(likeMe.getDescription()));
165         }
166         return false;
167     }
168
169     /**
170      *  {@inheritDoc}
171      */
172     @Override
173     public int hashCode() {
174
175         int result = 17;
176
177         result = 37 * result + getPipeID().hashCode();
178         result = 37 * result + getType().hashCode();
179         String pipeName = getName();
180
181         if (pipeName != null) {
182             result = 37 * result + pipeName.hashCode();
183         }
184         String pipeDescription = getDescription();
185
186         if (pipeDescription != null) {
187             result = 37 * result + pipeDescription.hashCode();
188         }
189         return result;
190     }
191
192     /**
193      * {@inheritDoc}
194      */
195     @Override
196     public final String getBaseAdvType() {
197         return getAdvertisementType();
198     }
199
200     /**
201      *  {@inheritDoc}
202      *
203      *  <p/>The PipeID uniquely identifies this ADV.
204      */
205     @Override
206     public ID getID() {
207         ID result = getPipeID();
208
209         if (null == result) {
210             result = ID.nullID;
211         }
212         return result;
213     }
214
215     /**
216      *  Return the pipe ID for the pipe described by this advertisement.
217      *
218      *  @return The pipe ID for the pipe described by this advertisement.
219      */
220     public ID getPipeID() {
221         return pipeId;
222     }
223
224     /**
225      *  Set the pipe ID for the pipe described by this advertisement.
226      *
227      *  @param pipeId The pipe ID for the pipe described by this advertisement.
228      */
229     public void setPipeID(ID pipeId) {
230         this.pipeId = pipeId;
231     }
232
233     /**
234      *  Return the pipe type for the pipe described by this advertisement.
235      *
236      *  @return The pipe type for the pipe described by this advertisement.
237      */
238     public String getType() {
239         return type;
240     }
241
242     /**
243      * Set the pipe type for the pipe described by this advertisement.
244      *
245      *  @param type The pipe type for the pipe described by this advertisement.
246      */
247     public void setType(String type) {
248         this.type = type;
249     }
250
251     /**
252      * Return the symbolic name for the pipe described by this advertisement.
253      *
254      * @return String The symbolic name for the pipe described by this advertisement.
255      */
256     public String getName() {
257         return name;
258     }
259
260     /**
261      *  Set the symbolic name for the pipe described by this advertisement.
262      *
263      *  @param name The symbolic name for the pipe described by this advertisement.
264      */
265     public void setName(String name) {
266         this.name = name;
267     }
268
269     /**
270      * Returns the description
271      *
272      * @return String the description
273      */
274     public String getDescription() {
275         if (null != description) {
276             return (String) description.getValue();
277         }
278         return null;
279     }
280
281     /**
282      * Set the description meta-data for the pipe described by this advertisement.
283      *
284      * @param description The description meta-data for the pipe described by this advertisement.
285      */
286     public void setDescription(String description) {
287
288         if (null != description) {
289             StructuredDocument newdoc = StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, "Desc", description);
290
291             setDesc(newdoc);
292         } else {
293             this.description = null;
294         }
295     }
296
297     /**
298      *  Return the description meta-data for the pipe described by this advertisement.
299      *
300      *  @return The description meta-data for the pipe described by this advertisement.
301      */
302     public StructuredDocument getDesc() {
303         if (null != description) {
304             StructuredDocument newDoc = StructuredDocumentUtils.copyAsDocument(description);
305
306             return newDoc;
307         }
308         return null;
309     }
310
311     /**
312      *  Set the description meta-data for the pipe described by this advertisement.
313      *
314      *  @param desc The description meta-data for the pipe described by this advertisement.
315      */
316     public void setDesc(Element desc) {
317
318         if (null != desc) {
319             this.description = StructuredDocumentUtils.copyAsDocument(desc);
320         } else {
321             this.description = null;
322         }
323     }
324 }