Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: net/jxta/codat/Codat.java


1   /*
2    * Copyright (c) 2001 Sun Microsystems, Inc.  All rights
3    * reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *0
9    * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12   * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in
14   *    the documentation and/or other materials provided with the
15   *    distribution.
16   *
17   * 3. The end-user documentation included with the redistribution,
18   *    if any, must include the following acknowledgment:
19   *       "This product includes software developed by the
20   *       Sun Microsystems, Inc. for Project JXTA."
21   *    Alternately, this acknowledgment may appear in the software itself,
22   *    if and wherever such third-party acknowledgments normally appear.
23   *
24   * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must
25   *    not be used to endorse or promote products derived from this
26   *    software without prior written permission. For written
27   *    permission, please contact Project JXTA at http://www.jxta.org.
28   *
29   * 5. Products derived from this software may not be called "JXTA",
30   *    nor may "JXTA" appear in their name, without prior written
31   *    permission of Sun.
32   *
33   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
34   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36   * DISCLAIMED.  IN NO EVENT SHALL SUN MICROSYSTEMS OR
37   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
40   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
41   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
43   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44   * SUCH DAMAGE.
45   * ====================================================================
46   *
47   * This software consists of voluntary contributions made by many
48   * individuals on behalf of Project JXTA.  For more
49   * information on Project JXTA, please see
50   * <http://www.jxta.org/>.
51   *
52   * This license is based on the BSD license adopted by the Apache Foundation.
53   *
54   * $Id: Codat.java,v 1.14 2002/10/02 19:07:28 hamada Exp $
55   */
56  
57  package net.jxta.codat;
58  
59  import java.io.IOException;
60  
61  import net.jxta.id.ID;
62  import net.jxta.id.IDFactory;
63  import net.jxta.peergroup.PeerGroupID;
64  import net.jxta.document.Document;
65  
66  /**
67   * Codats are container objects that can hold both data or code and are
68   * associated with a JXTA ID.  The Codat class is offered as a standard way for
69   * applications and services to exchange any kind of contents via a common API and
70   * associate a unique JXTA id to these contents.
71   *
72   * <p>Codats are containers objects that are used to hold any kinds of
73   * objects or data. A codat can represent a file, a class file, the saved
74   * state of an application, a loadable C library. Codats are handled
75   * transparently by the JXTA platform, and are used as placeholders for
76   * any types of data. Codats hold Document that represent the data that
77   * they hold.</p>
78   *
79   * <p>Codats are published in peer groups. A Codat can belong to only one peer
80   * group. Multiple copies of a codat can be made to be published in multiple
81   * peer groups.</p>
82   *
83   * <p>Codats are uniquely identified via a unique CodatID. This Id
84   * is guaranteed to be unique within the JXTA world.</p>
85   *
86   * <p>The core manipulates two main types of codats:</p>
87   *      <ul type-disc>
88   *      <li><b>Codat</b> - hold data or code</li>
89   *      <li><b>Metadata</b> - hold information about another Codat</li>
90   *      </ul>
91   *
92   * <p>The JXTA platform defines Codat as the unit of information shared and
93   * exchanged within a JXTA group.  All instances of Codats reside within a
94   * peer group. The PeerGroup content caching service provides storage and retrieval
95   * methods for codats using codatId as index.</p>
96   *
97   * @see     net.jxta.codat.CodatID
98   * @see     net.jxta.document.Document
99   * @see     net.jxta.document.StructuredDocument
100  * @see     net.jxta.document.StructuredTextDocument
101  *
102  **/
103 public class Codat {
104     
105     /**
106      * Id of this Codat. This is the "address" which may be used to
107      * refer to this Codat. see {@link net.jxta.codat.CodatID}
108      **/
109     protected ID id = ID.nullID;
110     
111     /**
112      * Codat Id of a Codat to which this Codat is related. This may be the
113      * Codat Id of another codat in the same Peer Group or nullID
114      **/
115     protected ID metaId = ID.nullID;
116     
117     /**
118      * A JXTA Document which contains the data held by this Codat.
119      **/
120     protected Document doc = null;
121     
122     /**
123      * Makes a new Codat with a new CodatId given a PeerGroupID and a document.
124      *
125      * @param groupID   PeerGroupID the group to which this
126      *         codat will belong.
127      * @param about CodatId for which this Codat is metadata
128      * @param document Document held by this codat.
129      * @throws IOException if there is an error accessing the document.
130      **/
131     public Codat( PeerGroupID groupID, ID about, Document document) throws IOException {
132         
133         this.id = IDFactory.newCodatID( groupID, document.getStream() );
134         
135         this.metaId = about;
136         this.doc = document;
137     }
138     
139     /**
140      *  Makes a new Codat instance from an existing Codat,
141      *  with a given CodatID and a document.
142      *
143      *  @param id CodatId of the new codat
144      *  @param about CodatID for which this Codat is metadata
145      *  @param document Document hold by this codat
146      **/
147     public Codat( CodatID id, CodatID about, Document document) {
148         this.id = id;
149         this.metaId = about;
150         this.doc = document;
151     }
152     
153     /**
154      *  Returns the CodatId associated with this Codat.
155      *
156      *  @return  CodateID associated with this codat
157      **/
158     public ID getCodatID() {
159         return id;
160     }
161     
162     /**
163      *  Returns Codat id of related codat associated with this metadata Codat.
164      *
165      *  @return  CodateID associated with this codat
166      *
167      **/
168     public ID getMetaID() {
169         return metaId;
170     }
171     
172     /**
173      *  Returns the Document associated with this Codat.
174      *
175      *
176      *  @return Document associated with this Codat
177      **/
178     public Document getDocument() {
179         return doc;
180     }
181 }