001: /*
002: * <copyright>
003: *
004: * Copyright 2002-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.servicediscovery.description;
028:
029: import org.cougaar.planning.ldm.asset.Asset;
030: import org.cougaar.planning.ldm.plan.Role;
031:
032: import java.util.ArrayList;
033: import java.util.Collection;
034: import java.util.Collections;
035: import java.util.Iterator;
036:
037: /*
038: import org.cougaar.util.log.Logger;
039: import org.cougaar.util.log.Logging;
040: */
041:
042: /**
043: * The ServiceContract describes the particular service which the client agent
044: * woul like to receive from the provider agent.
045: */
046:
047: public class ServiceContractImpl implements ServiceContract,
048: java.io.Serializable {
049: // private static Logger logger = Logging.getLogger(ServiceContractImpl.class);
050:
051: private Asset myProvider;
052: private Role myServiceRole;
053: private Collection myServicePreferences;
054: private boolean isRevoked;
055: private transient String myToString = null;
056:
057: public ServiceContractImpl() {
058: }
059:
060: public ServiceContractImpl(Asset provider, Role serviceRole,
061: Collection preferences) {
062: setProvider(provider);
063: setServiceRole(serviceRole);
064: setServicePreferences(preferences);
065: isRevoked = false;
066: }
067:
068: /**
069: * Returns the asset representing the provider
070: */
071: public Asset getProvider() {
072: return myProvider;
073: }
074:
075: /**
076: * Sets the asset representing the provider
077: *
078: */
079: public void setProvider(Asset provider) {
080: // Must be cloned by caller
081: myProvider = provider;
082: }
083:
084: /**
085: * Returns the provided service role
086: * service.
087: */
088: public Role getServiceRole() {
089: return myServiceRole;
090: }
091:
092: /**
093: * Sets the provided service role
094: *
095: */
096: public void setServiceRole(Role serviceRole) {
097: myServiceRole = serviceRole;
098: }
099:
100: /**
101: * Returns a read only collection of Preferences for the provided service.
102: */
103: public Collection getServicePreferences() {
104: if (myServicePreferences == null) {
105: return Collections.EMPTY_LIST;
106: } else {
107: return Collections
108: .unmodifiableCollection(myServicePreferences);
109: }
110: }
111:
112: /**
113: * Sets the provided service preferences for this service.
114: */
115: public void setServicePreferences(Collection servicePreferences) {
116: myServicePreferences = new ArrayList(servicePreferences);
117: }
118:
119: /**
120: * Indicate that this service contract has been revoked
121: */
122: public void revoke() {
123: isRevoked = true;
124: }
125:
126: /**
127: * Returns a boolean indicating whether this service contract has been revoked
128: */
129: public boolean isRevoked() {
130: return isRevoked;
131: }
132:
133: public String toString() {
134: if (myToString == null) {
135: StringBuffer buf = new StringBuffer();
136: buf.append("[");
137: for (Iterator iterator = getServicePreferences().iterator(); iterator
138: .hasNext();) {
139: Object o = iterator.next();
140: buf.append(o);
141: if (iterator.hasNext())
142: buf.append(",");
143: }
144: buf.append("]");
145: myToString = "<ServiceContractImpl: Provider="
146: + getProvider() + ", Role=" + getServiceRole()
147: + ", Preferences=" + getServicePreferences().size()
148: + " : " + buf + (isRevoked() ? " Revoked " : "")
149: + ">";
150: }
151: return myToString;
152: }
153: }
|