001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.core.service.wp;
028:
029: import java.io.Serializable;
030: import java.net.URI;
031:
032: /**
033: * An AddressEntry represents a single entry in the white pages.
034: * <p>
035: * Address entries are immutable.
036: */
037: public final class AddressEntry implements Serializable {
038:
039: private final String name;
040: private final String type;
041: private final URI uri;
042: private final Cert cert;
043: private transient int _hc;
044:
045: private AddressEntry(String name, String type, URI uri, Cert cert) {
046: this .name = name;
047: this .type = type;
048: this .uri = uri;
049: this .cert = cert;
050: if (name == null || type == null || uri == null | cert == null) {
051: throw new IllegalArgumentException("Null argument");
052: }
053: // validate name?
054: }
055:
056: public static AddressEntry getAddressEntry(String name,
057: String type, URI uri) {
058: return getAddressEntry(name, type, uri, Cert.NULL);
059: }
060:
061: public static AddressEntry getAddressEntry(String name,
062: String type, URI uri, Cert cert) {
063: return new AddressEntry(name, type, uri, cert);
064: }
065:
066: /** @return the non-null name (e.g.: "foo.bar") */
067: public String getName() {
068: return name;
069: }
070:
071: /** @return the non-null type (e.g.: "mts") */
072: public String getType() {
073: return type;
074: }
075:
076: /** @return the non-null uri (e.g.: "rmi://foo.com:123/xyz") */
077: public URI getURI() {
078: return uri;
079: }
080:
081: /** @return the non-null cert (e.g.: Cert.NULL) */
082: public Cert getCert() {
083: return cert;
084: }
085:
086: public boolean equals(Object o) {
087: if (o == this ) {
088: return true;
089: } else if (!(o instanceof AddressEntry)) {
090: return false;
091: } else {
092: AddressEntry ae = (AddressEntry) o;
093: return name.equals(ae.name) && type.equals(ae.type)
094: && uri.equals(ae.uri) && cert.equals(ae.cert);
095: }
096: }
097:
098: public int hashCode() {
099: if (_hc == 0) {
100: int h = 0;
101: h = 31 * h + name.hashCode();
102: h = 31 * h + type.hashCode();
103: h = 31 * h + uri.hashCode();
104: h = 31 * h + cert.hashCode();
105: _hc = h;
106: }
107: return _hc;
108: }
109:
110: public String toString() {
111: return "(name=" + name + " type=" + type + " uri=" + uri
112: + " cert=" + cert + ")";
113: }
114:
115: private Object readResolve() {
116: return getAddressEntry(name, type, uri, cert);
117: }
118:
119: //
120: // deprecated, to be removed in Cougaar 10.4.1+
121: //
122:
123: /** @deprecated use "getAddressEntry(name, type, uri)" */
124: public AddressEntry(String name, Application app, URI uri,
125: Cert cert, long ttl) {
126: this (name, app.toString(), uri, cert);
127: }
128:
129: /** @deprecated use "String getType()" */
130: public Application getApplication() {
131: return Application.getApplication(type);
132: }
133:
134: /** @deprecated use "URI getURI()" */
135: public URI getAddress() {
136: return getURI();
137: }
138:
139: /** @deprecated the TTL is a wp-internal variable */
140: public long getTTL() {
141: return 0;
142: }
143: }
|