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: /**
030: * A marker class for multicasting messages.
031: * <p>
032: * Will likely be deprecated in the future, to be replaced
033: * with an enhanced implementation.
034: * <p>
035: * Used by constant addresses in MessageAddress.
036: */
037: public class MulticastMessageAddress extends SimpleMessageAddress {
038: // for Externalizable use only
039: public MulticastMessageAddress() {
040: }
041:
042: protected MulticastMessageAddress(String address) {
043: super (address);
044: }
045:
046: public boolean hasReceiverClass() {
047: return false;
048: }
049:
050: public Class getReceiverClass() {
051: return null;
052: }
053:
054: // factory methods
055:
056: public static final MulticastMessageAddress getMulticastMessageAddress(
057: String address) {
058: return new MulticastMessageAddress(address);
059: }
060:
061: public static final MulticastMessageAddress getMulticastMessageAddress(
062: Class clientClass) {
063: return new MMAWithClass(clientClass);
064: }
065:
066: /**
067: * @deprecated Why would you want a MessageAddress that only has attributes?
068: */
069: public static final MessageAddress getMulticastMessageAddress(
070: MessageAttributes ma) {
071: return MessageAddressWithAttributes
072: .getMessageAddressWithAttributes(ma);
073: }
074:
075: public static final MessageAddress getMulticastMessageAddress(
076: String address, MessageAttributes attrs) {
077: MessageAddress ma = MessageAddress.getMessageAddress(address);
078: return MessageAddressWithAttributes
079: .getMessageAddressWithAttributes(ma, attrs);
080: }
081:
082: public static final MessageAddress getMulticastMessageAddress(
083: Class clientClass, MessageAttributes attrs) {
084: MessageAddress ma = getMulticastMessageAddress(clientClass);
085: return MessageAddressWithAttributes
086: .getMessageAddressWithAttributes(ma, attrs);
087: }
088:
089: // private classes
090: private static class MMAWithClass extends MulticastMessageAddress {
091: private transient Class _myclass = null;
092:
093: public MMAWithClass() {
094: }
095:
096: public MMAWithClass(Class clazz) {
097: super (clazz.getName());
098: }
099:
100: public boolean hasReceiverClass() {
101: return true;
102: }
103:
104: public synchronized Class getReceiverClass() {
105: if (_myclass != null) {
106: return _myclass;
107: } else {
108: try {
109: _myclass = Class.forName(toAddress());
110: return _myclass;
111: } catch (ClassNotFoundException cnf) {
112: return null;
113: }
114: }
115: }
116: }
117: }
|