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.Element;
61 import net.jxta.document.ExtendableAdvertisement;
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 import net.jxta.platform.ModuleSpecID;
71 * A ModuleImplAdvertisement describes one of any number of published
72 * implementations for a given specification.
74 * Module specifications are referenced by their ModuleSpecID. Given a
75 * ModuleSpecID, a ModuleImplAdvertisement may be searched by means of JXTA
76 * Discovery, filtered according to the compatibility statement it contains,
77 * and if compatible, loaded and initialized. The {@code loadModule()} method of
78 * PeerGroup performs this task automatically, given a ModuleSpecID.
80 * One significant example of Modules referenced and loaded in that manner are
81 * the services and protocols that constitute a StdPeerGroup in the Java
82 * reference implementation.
85 * @see net.jxta.platform.ModuleSpecID
86 * @see net.jxta.document.Advertisement
87 * @see net.jxta.document.StructuredDocument
88 * @see net.jxta.document.Element
89 * @see net.jxta.protocol.ModuleSpecAdvertisement
90 * @see net.jxta.peergroup.PeerGroup
92 public abstract class ModuleImplAdvertisement extends ExtendableAdvertisement implements Cloneable {
94 private ModuleSpecID msid = null;
95 private StructuredDocument description = null;
96 private StructuredDocument compat = null;
97 private String code = null;
98 private String uri = null;
99 private String provider = null;
100 private StructuredDocument param = null;
103 * Returns the identifying type of this Advertisement.
105 * @return String the type of advertisement
107 public static String getAdvertisementType() {
115 public final String getBaseAdvType() {
116 return getAdvertisementType();
120 * Clone this ModuleImplAdvertisement
123 public ModuleImplAdvertisement clone() {
126 ModuleImplAdvertisement clone = (ModuleImplAdvertisement) super.clone();
128 clone.setModuleSpecID(getModuleSpecID());
129 clone.setDesc(getDescPriv());
130 clone.setCompat(getCompatPriv());
131 clone.setCode(getCode());
132 clone.setUri(getUri());
133 clone.setProvider(getProvider());
134 clone.setParam(getParamPriv());
137 } catch (CloneNotSupportedException impossible) {
138 throw new Error("Object.clone() threw CloneNotSupportedException", impossible);
143 * Returns the unique ID of that advertisement for indexing purposes.
144 * In that case we do not have any particular one to offer. Let the indexer
147 * @return ID the unique id
155 * Returns the id of the spec that this implements.
156 * @return ID the spec id
159 public ModuleSpecID getModuleSpecID() {
164 * Sets the id of the spec that is implemented
166 * @param msid The id of the spec
168 public void setModuleSpecID(ModuleSpecID msid) {
173 * returns the description
175 * @return String the description
177 public String getDescription() {
178 if (null != description) {
179 return (String) description.getValue();
186 * sets the description
188 * @param description the description
190 public void setDescription(String description) {
192 if (null != description) {
193 StructuredDocument newdoc = StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, "Desc", description);
197 this.description = null;
202 * returns the description
204 * @return the description
206 public StructuredDocument getDesc() {
207 if (null != description) {
208 StructuredDocument newDoc = StructuredDocumentUtils.copyAsDocument(description);
217 * Privileged version of {@link #getDesc()} that does not clone the elements.
219 * @return the description
221 public StructuredDocument getDescPriv() {
226 * sets the description
228 * @param desc the description
230 public void setDesc(Element desc) {
233 this.description = StructuredDocumentUtils.copyAsDocument(desc);
235 this.description = null;
240 * Returns the opaque compatibility statement for this advertisement. Each
241 * JXTA implementation has the ability to recognize and evaluate it's own
242 * compatibility statements (even though it may not be able to evaluate the
243 * compatibility statements of other implementations).
245 * @return The compatibility statement as a StructuredDocument of
246 * unspecified content.
248 public StructuredDocument getCompat() {
249 return (compat == null ? null : StructuredDocumentUtils.copyAsDocument(compat));
253 * Privileged version of {@link #getCompat()} that does not clone the elements.
255 * @return The compatibility statement as a StructuredDocument of
256 * unspecified content.
258 protected StructuredDocument getCompatPriv() {
263 * Sets the module impl. compatibility statement.
265 * @param compat Element of an unspecified content.
267 public void setCompat(Element compat) {
268 this.compat = (compat == null ? null : StructuredDocumentUtils.copyAsDocument(compat));
272 * returns the code; a reference to or representation of the executable code
273 * advertised by this advertisement.
275 * The appropriate interpretation of the code value is dependant upon the
276 * compatibility statement. Any compatible consumer of this advertisement
277 * will be able to correctly interpret code value. The standard group
278 * implementations of the JXSE reference implementation expect it to be a
279 * reference to a jar file.
281 * @return A reference to the executable code described by this
284 public String getCode() {
289 * Sets the reference for the executable code described by this
292 * @param code A reference to the executable code described by this
295 public void setCode(String code) {
300 * returns the uri; that is a reference to or representation of a package
301 * from which the executable code referenced by the getCode method may be
304 * The appropriate interpretation of the URI value is dependant upon the
305 * compatibility statement. Any compatible consumer of this advertisement
306 * will be able to correctly interpret the URI value. The standard group
307 * implementations of the JXSE reference implementation expect it to be a
308 * reference to a jar file.
310 * @return Location URI for the code described by this advertisement.
312 public String getUri() {
319 * @param uri Location URI for the code described by this advertisement.
321 public void setUri(String uri) {
326 * returns the provider
328 * @return String the provider
330 public String getProvider() {
337 * @param provider the provider
339 public void setProvider(String provider) {
340 this.provider = provider;
344 * returns the param element.
346 * The interpretation of the param element is entirely up to the code
347 * that this advertises. One valid use of it is to enable the code to
348 * be configured so that multiple specs or multiple implementations of
349 * one spec may use the same code.
351 * @return A standalone structured document of unspecified content.
353 public StructuredDocument getParam() {
354 return (param == null ? null : StructuredDocumentUtils.copyAsDocument(param));
358 * Privileged version of {@link #getParam()} that does not clone the elements.
360 * @return A standalone structured document of unspecified content.
362 protected StructuredDocument getParamPriv() {
367 * Sets the module param
369 * @param param Element of an unspecified content.
371 public void setParam(Element param) {
372 this.param = (param == null ? null : StructuredDocumentUtils.copyAsDocument(param));