]> sjero.net Git - linphone/blob - p2pproxy/dependencies-src/jxse-src-2.5/api/src/net/jxta/protocol/ModuleImplAdvertisement.java
15f7e936c2f162b87894d1d10860ee5ff3c56333
[linphone] / p2pproxy / dependencies-src / jxse-src-2.5 / api / src / net / jxta / protocol / ModuleImplAdvertisement.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.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;
68
69
70 /**
71  * A ModuleImplAdvertisement describes one of any number of published
72  * implementations for a given specification.
73  * <p/>
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.
79  * <p/>
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.
83  *
84  * @see net.jxta.id.ID
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
91  */
92 public abstract class ModuleImplAdvertisement extends ExtendableAdvertisement implements Cloneable {
93     
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;
101     
102     /**
103      *  Returns the identifying type of this Advertisement.
104      *
105      * @return String the type of advertisement
106      */
107     public static String getAdvertisementType() {
108         return "jxta:MIA";
109     }
110     
111     /**
112      * {@inheritDoc}
113      */
114     @Override
115     public final String getBaseAdvType() {
116         return getAdvertisementType();
117     }
118     
119     /**
120      * Clone this ModuleImplAdvertisement
121      */
122     @Override
123     public ModuleImplAdvertisement clone() {
124         
125         try {
126             ModuleImplAdvertisement clone = (ModuleImplAdvertisement) super.clone();
127             
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());
135             
136             return clone;
137         } catch (CloneNotSupportedException impossible) {
138             throw new Error("Object.clone() threw CloneNotSupportedException", impossible);
139         }
140     }
141     
142     /**
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
145      * hash the document.
146      *
147      * @return ID the unique id
148      */
149     @Override
150     public ID getID() {
151         return null;
152     }
153     
154     /**
155      * Returns the id of the spec that this implements.
156      * @return ID the spec id
157      *
158      */
159     public ModuleSpecID getModuleSpecID() {
160         return msid;
161     }
162     
163     /**
164      * Sets the id of the spec that is implemented
165      * 
166      * @param msid The id of the spec
167      */
168     public void setModuleSpecID(ModuleSpecID msid) {
169         this.msid = msid;
170     }
171     
172     /**
173      * returns the description
174      *
175      * @return String the description
176      */
177     public String getDescription() {
178         if (null != description) {
179             return (String) description.getValue();
180         } else {
181             return null;
182         }
183     }
184     
185     /**
186      * sets the description
187      *
188      * @param description the description
189      */
190     public void setDescription(String description) {
191         
192         if (null != description) {
193             StructuredDocument newdoc = StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, "Desc", description);
194             
195             setDesc(newdoc);
196         } else {
197             this.description = null;
198         }
199     }
200     
201     /**
202      * returns the description
203      *
204      * @return the description
205      */
206     public StructuredDocument getDesc() {
207         if (null != description) {
208             StructuredDocument newDoc = StructuredDocumentUtils.copyAsDocument(description);
209             
210             return newDoc;
211         } else {
212             return null;
213         }
214     }
215     
216     /**
217      * Privileged version of {@link #getDesc()} that does not clone the elements.
218      *
219      * @return the description
220      */
221     public StructuredDocument getDescPriv() {
222         return description;
223     }
224     
225     /**
226      * sets the description
227      *
228      * @param desc the description
229      */
230     public void setDesc(Element desc) {
231         
232         if (null != desc) {
233             this.description = StructuredDocumentUtils.copyAsDocument(desc);
234         } else {
235             this.description = null;
236         }
237     }
238  
239     /**
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).  
244      *
245      * @return The compatibility statement as a StructuredDocument of 
246      * unspecified content.
247      */
248     public StructuredDocument getCompat() {
249         return (compat == null ? null : StructuredDocumentUtils.copyAsDocument(compat));
250     }
251     
252     /**
253      * Privileged version of {@link #getCompat()} that does not clone the elements.
254      *
255      * @return The compatibility statement as a StructuredDocument of 
256      * unspecified content.
257      */
258     protected StructuredDocument getCompatPriv() {
259         return compat;
260     }
261     
262     /**
263      * Sets the module impl. compatibility statement.
264      *
265      * @param compat Element of an unspecified content.
266      */
267     public void setCompat(Element compat) {
268         this.compat = (compat == null ? null : StructuredDocumentUtils.copyAsDocument(compat));
269     }
270     
271     /**
272      * returns the code; a reference to or representation of the executable code
273      * advertised by this advertisement.
274      * <p/>
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.
280      *
281      * @return A reference to the executable code described by this 
282      * advertisement.
283      */
284     public String getCode() {
285         return code;
286     }
287     
288     /**
289      * Sets the reference for the executable code described by this 
290      * advertisement.
291      *
292      * @param code A reference to the executable code described by this 
293      * advertisement.
294      */
295     public void setCode(String code) {
296         this.code = code;
297     }
298     
299     /**
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 
302      * loaded.
303      * <p/>
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.
309      *
310      * @return Location URI for the code described by this advertisement.
311      */
312     public String getUri() {
313         return uri;
314     }
315     
316     /**
317      * Sets the uri
318      *
319      * @param uri Location URI for the code described by this advertisement.
320      */
321     public void setUri(String uri) {
322         this.uri = uri;
323     }
324     
325     /**
326      * returns the provider
327      *
328      * @return String the provider
329      */
330     public String getProvider() {
331         return provider;
332     }
333     
334     /**
335      * sets the provider
336      *
337      * @param provider the provider
338      */
339     public void setProvider(String provider) {
340         this.provider = provider;
341     }
342     
343     /**
344      * returns the param element.
345      *
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.
350      *
351      * @return A standalone structured document of unspecified content.
352      */
353     public StructuredDocument getParam() {
354         return (param == null ? null : StructuredDocumentUtils.copyAsDocument(param));
355     }
356     
357     /**
358      * Privileged version of {@link #getParam()} that does not clone the elements.
359      *
360      * @return A standalone structured document of unspecified content.
361      */
362     protected StructuredDocument getParamPriv() {
363         return param;
364     }
365     
366     /**
367      * Sets the module param
368      *
369      * @param param Element of an unspecified content.
370      */
371     public void setParam(Element param) {
372         this.param = (param == null ? null : StructuredDocumentUtils.copyAsDocument(param));
373     }
374 }