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.
57 package net.jxta.protocol;
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;
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.
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>
76 public abstract class PipeAdvertisement extends ExtendableAdvertisement implements Cloneable {
79 * XML tag to store the PipeID
81 public static final String IdTag = "Id";
84 * XML tag to store the Pipe Type
86 public static final String TypeTag = "Type";
89 * XML tag to store the name of the Pipe
91 public static final String NameTag = "Name";
94 * XML tag to store the name of the Pipe
96 public static final String descTag = "Desc";
98 private transient ID pipeId = ID.nullID;
99 private String type = null;
100 private String name = null;
103 * Descriptive meta-data about this pipe.
105 private Element description = null;
108 * Returns the identifying type of this Advertisement.
110 * @return String the type of advertisement
112 public static String getAdvertisementType() {
113 return "jxta:PipeAdvertisement";
120 public PipeAdvertisement clone() {
122 PipeAdvertisement likeMe = (PipeAdvertisement) super.clone();
124 likeMe.setPipeID(getPipeID());
125 likeMe.setType(getType());
126 likeMe.setName(getName());
127 likeMe.setDesc(getDesc());
130 } catch (CloneNotSupportedException impossible) {
131 throw new Error("Object.clone() threw CloneNotSupportedException", impossible);
139 public boolean equals(Object obj) {
145 if (obj instanceof PipeAdvertisement) {
146 PipeAdvertisement likeMe = (PipeAdvertisement) obj;
148 if (!getPipeID().equals(likeMe.getPipeID())) {
152 if (!getType().equals(likeMe.getType())) {
156 String pipeName = getName();
158 if (pipeName == null ? likeMe.getName() != null : !pipeName.equals(likeMe.getName())) {
162 String pipeDescription = getDescription();
164 return !(pipeDescription == null ? likeMe.getDescription() != null : pipeDescription.equals(likeMe.getDescription()));
173 public int hashCode() {
177 result = 37 * result + getPipeID().hashCode();
178 result = 37 * result + getType().hashCode();
179 String pipeName = getName();
181 if (pipeName != null) {
182 result = 37 * result + pipeName.hashCode();
184 String pipeDescription = getDescription();
186 if (pipeDescription != null) {
187 result = 37 * result + pipeDescription.hashCode();
196 public final String getBaseAdvType() {
197 return getAdvertisementType();
203 * <p/>The PipeID uniquely identifies this ADV.
207 ID result = getPipeID();
209 if (null == result) {
216 * Return the pipe ID for the pipe described by this advertisement.
218 * @return The pipe ID for the pipe described by this advertisement.
220 public ID getPipeID() {
225 * Set the pipe ID for the pipe described by this advertisement.
227 * @param pipeId The pipe ID for the pipe described by this advertisement.
229 public void setPipeID(ID pipeId) {
230 this.pipeId = pipeId;
234 * Return the pipe type for the pipe described by this advertisement.
236 * @return The pipe type for the pipe described by this advertisement.
238 public String getType() {
243 * Set the pipe type for the pipe described by this advertisement.
245 * @param type The pipe type for the pipe described by this advertisement.
247 public void setType(String type) {
252 * Return the symbolic name for the pipe described by this advertisement.
254 * @return String The symbolic name for the pipe described by this advertisement.
256 public String getName() {
261 * Set the symbolic name for the pipe described by this advertisement.
263 * @param name The symbolic name for the pipe described by this advertisement.
265 public void setName(String name) {
270 * Returns the description
272 * @return String the description
274 public String getDescription() {
275 if (null != description) {
276 return (String) description.getValue();
282 * Set the description meta-data for the pipe described by this advertisement.
284 * @param description The description meta-data for the pipe described by this advertisement.
286 public void setDescription(String description) {
288 if (null != description) {
289 StructuredDocument newdoc = StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, "Desc", description);
293 this.description = null;
298 * Return the description meta-data for the pipe described by this advertisement.
300 * @return The description meta-data for the pipe described by this advertisement.
302 public StructuredDocument getDesc() {
303 if (null != description) {
304 StructuredDocument newDoc = StructuredDocumentUtils.copyAsDocument(description);
312 * Set the description meta-data for the pipe described by this advertisement.
314 * @param desc The description meta-data for the pipe described by this advertisement.
316 public void setDesc(Element desc) {
319 this.description = StructuredDocumentUtils.copyAsDocument(desc);
321 this.description = null;