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.
56 package net.jxta.peergroup;
61 import net.jxta.id.ID;
62 import net.jxta.id.IDFactory;
66 * This class implements a PeerGroup ID. Each peer group is assigned a
70 * @see net.jxta.id.IDFactory
71 * @see net.jxta.peer.PeerID
75 public abstract class PeerGroupID extends ID {
78 * Creates an ID by parsing the given URI.
80 * <p>This convenience factory method works as if by invoking the
81 * {@link net.jxta.id.IDFactory#fromURI(URI)} method; any
82 * {@link java.net.URISyntaxException} thrown is caught and wrapped in a
83 * new {@link IllegalArgumentException} object, which is then thrown.
85 * <p> This method is provided for use in situations where it is known that
86 * the given string is a legal ID, for example for ID constants declared
87 * within in a program, and so it would be considered a programming error
88 * for the URI not to parse as such. The {@link net.jxta.id.IDFactory},
89 * which throws {@link java.net.URISyntaxException} directly, should be used
90 * situations where a ID is being constructed from user input or from some
91 * other source that may be prone to errors.
93 * @param fromURI The URI to be parsed into an ID
96 * @throws NullPointerException If {@code fromURI} is {@code null}.
97 * @throws IllegalArgumentException If the given URI is not a valid ID.
99 public static PeerGroupID create(URI fromURI) {
100 return (PeerGroupID) ID.create(fromURI);
106 public PeerGroupID intern() {
107 return (PeerGroupID) super.intern();
111 * The well known Unique Identifier of the world peergroup.
112 * This is a singleton within the scope of a VM.
114 public final static PeerGroupID worldPeerGroupID = (new WorldPeerGroupID()).intern();
117 * The well known Unique Identifier of the net peergroup.
118 * This is a singleton within the scope of this VM.
120 public final static PeerGroupID defaultNetPeerGroupID = (new NetPeerGroupID()).intern();
123 * Returns the parent peer group id of this peer group id, if any.
125 * @return the id of the parent peergroup or null if this group has no
128 public abstract PeerGroupID getParentPeerGroupID();
132 final class WorldPeerGroupID extends PeerGroupID {
135 * The name associated with this ID Format.
137 final static String JXTAFormat = "jxta";
139 private static final String UNIQUEVALUE = "WorldGroup";
142 * WorldPeerGroupID is not intended to be constructed. You should use the
143 * {@link PeerGroupID.worldPeerGroupID} constant instead.
145 WorldPeerGroupID() {}
151 public boolean equals(Object target) {
152 return (this == target); // worldPeerGroupID is only itself.
156 * deserialization has to point back to the singleton in this VM
158 private Object readResolve() {
159 return PeerGroupID.worldPeerGroupID;
166 public String getIDFormat() {
174 public Object getUniqueValue() {
175 return getIDFormat() + "-" + UNIQUEVALUE;
182 public PeerGroupID getParentPeerGroupID() {
188 final class NetPeerGroupID extends PeerGroupID {
191 * The name associated with this ID Format.
193 final static String JXTAFormat = "jxta";
195 private static final String UNIQUEVALUE = "NetGroup";
198 * NetPeerGroupID is not intended to be constructed. You should use the
199 * {@link PeerGroupID.defaultNetPeerGroupID} constant instead.
207 public boolean equals(Object target) {
208 return (this == target); // netPeerGroupID is only itself.
212 * deserialization has to point back to the singleton in this VM
214 private Object readResolve() {
215 return PeerGroupID.defaultNetPeerGroupID;
222 public String getIDFormat() {
230 public Object getUniqueValue() {
231 return getIDFormat() + "-" + UNIQUEVALUE;
238 public PeerGroupID getParentPeerGroupID() {
239 return PeerGroupID.worldPeerGroupID;