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.mts;
028:
029: import java.io.Externalizable;
030: import java.net.URI;
031:
032: import org.cougaar.util.annotations.Cougaar;
033:
034: /**
035: * An address for a {@link Message} sender or receiver.
036: */
037: public abstract class MessageAddress implements Externalizable {
038:
039: /** @return the attributes associated with the address, or null */
040: public MessageAttributes getMessageAttributes() {
041: return null;
042: }
043:
044: /** @see #toAddress */
045: public String getAddress() {
046: return toAddress();
047: }
048:
049: /**
050: * @return a string representation of this address, which may not be
051: * human readable or parsable.
052: */
053: public abstract String toAddress();
054:
055: /** @see #toAddress */
056: public String toString() {
057: return toAddress();
058: }
059:
060: /** @see #getPrimary */
061: public int hashCode() {
062: return super .hashCode();
063: }
064:
065: /** @see #getPrimary */
066: public boolean equals(Object o) {
067: return super .equals(o);
068: }
069:
070: /**
071: * Return the primary address associated with this {@link
072: * MessageAddress}, suitable for hashing.
073: * <p>
074: * For example, if an address has MessageAttributes, getPrimary() will
075: * return the Address without the attributes.
076: * @note This is usually an identity operation.
077: */
078: public MessageAddress getPrimary() {
079: return this ;
080: }
081:
082: //
083: // factory items
084: //
085:
086: /** @deprecated */
087: public static final MessageAddress NULL_SYNC = getMessageAddress("NULL");
088: public static final MessageAddress MULTICAST_SOCIETY = MulticastMessageAddress
089: .getMulticastMessageAddress("SOCIETY");
090: public static final MessageAddress MULTICAST_COMMUNITY = MulticastMessageAddress
091: .getMulticastMessageAddress("COMMUNITY");
092: public static final MessageAddress MULTICAST_LOCAL = MulticastMessageAddress
093: .getMulticastMessageAddress("LOCAL");
094:
095: /** @return an address with the specified name */
096: @Cougaar.Resolver()
097: public static final MessageAddress getMessageAddress(String address) {
098: return SimpleMessageAddress.getSimpleMessageAddress(address);
099: }
100:
101: /** @return an address with the specified name and attributes */
102: public static final MessageAddress getMessageAddress(
103: String address, MessageAttributes mas) {
104: return MessageAddressWithAttributes
105: .getMessageAddressWithAttributes(address, mas);
106: }
107:
108: /** @return an address plus the specified attributes */
109: public static final MessageAddress getMessageAddress(
110: MessageAddress address, MessageAttributes mas) {
111: return MessageAddressWithAttributes
112: .getMessageAddressWithAttributes(address, mas);
113: }
114:
115: /** @deprecated Why would you want a MessageAddress that only has attributes? */
116: public static final MessageAddress getMessageAddress(
117: MessageAttributes mas) {
118: return MessageAddressWithAttributes
119: .getMessageAddressWithAttributes(mas);
120: }
121:
122: /** @see #getMessageAddress(String) for agent addresses */
123: public static final MessageAddress getMessageAddress(URI uri) {
124: return URIMessageAddress.getURIMessageAddress(uri);
125: }
126:
127: /** @see #getMessageAddress(String) for agent addresses */
128: public static final MessageAddress getMessageAddress(URI uri,
129: MessageAttributes mas) {
130: MessageAddress ma = URIMessageAddress.getURIMessageAddress(uri);
131: return new MessageAddressWithAttributes(ma, mas);
132: }
133: }
|