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: package org.cougaar.multicast;
027:
028: import java.io.Externalizable;
029: import java.io.IOException;
030: import java.io.ObjectInput;
031: import java.io.ObjectOutput;
032:
033: import org.cougaar.core.mts.MessageAddress;
034: import org.cougaar.core.mts.MessageAddressWithAttributes;
035: import org.cougaar.core.mts.MessageAttributes;
036:
037: /**
038: * Attribute Based Messaging support class,
039: * used in <code>Blackboard</code> for determining those
040: * directive destinations not specified by a
041: * <code>MessageAddress</code>
042: */
043: public class AttributeBasedAddress extends MessageAddress implements
044: Externalizable {
045: protected transient String myCommunityName;
046: protected transient String myAttributeType;
047: protected transient String myAttributeValue;
048:
049: public AttributeBasedAddress() {
050: }
051:
052: private AttributeBasedAddress(String commName, String attrType,
053: String attrValue) {
054: if (commName == null) {
055: myCommunityName = "";
056: } else {
057: myCommunityName = commName;
058: }
059: myAttributeType = attrType;
060: myAttributeValue = attrValue;
061: }
062:
063: public String getCommunityName() {
064: return myCommunityName;
065: }
066:
067: public String toAddress() {
068: return "ABA";
069: }
070:
071: public String toString() {
072: return "#<ABA '" + myCommunityName + "' " + myAttributeType
073: + "=" + myAttributeValue + ">";
074: }
075:
076: /**
077: * @deprecated Use getAttributeType instead.
078: **/
079: public String getAttributeName() {
080: return getAttributeType();
081: }
082:
083: public String getAttributeType() {
084: return myAttributeType;
085: }
086:
087: public String getAttributeValue() {
088: return myAttributeValue;
089: }
090:
091: public boolean isPersistable() {
092: return false;
093: }
094:
095: // override MessageAddress
096: public void writeExternal(ObjectOutput out) throws IOException {
097: out.writeObject(myCommunityName);
098: out.writeObject(myAttributeType);
099: out.writeObject(myAttributeValue);
100: }
101:
102: public void readExternal(ObjectInput in)
103: throws ClassNotFoundException, IOException {
104: myCommunityName = (String) in.readObject();
105: myAttributeType = (String) in.readObject();
106: myAttributeValue = (String) in.readObject();
107: }
108:
109: /*
110: // totally bogus - do correctly some time
111: protected Object readResolve() {
112: return new AttributeBasedAddress(myCommunityName, myAttributeType, myAttributeValue);
113: }
114: */
115:
116: //
117: // factories
118: //
119: public static AttributeBasedAddress getAttributeBasedAddress(
120: String commName, String attrType, String attrValue) {
121: return new AttributeBasedAddress(commName, attrType, attrValue);
122: }
123:
124: public static MessageAddress getAttributeBasedAddress(
125: String commName, String attrType, String attrValue,
126: MessageAttributes mas) {
127: MessageAddress prime = getAttributeBasedAddress(commName,
128: attrType, attrValue);
129: if (mas == null) {
130: return prime;
131: } else {
132: return MessageAddressWithAttributes
133: .getMessageAddressWithAttributes(prime, mas);
134: }
135: }
136:
137: }
|