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 java.util.ArrayList;
030: import java.util.Collection;
031: import java.util.Collections;
032:
033: import org.cougaar.planning.ldm.asset.Asset;
034: import org.cougaar.planning.ldm.plan.Role;
035:
036: /*
037: import org.cougaar.util.log.Logger;
038: import org.cougaar.util.log.Logging;
039: */
040:
041: /**
042: * The ServiceRequest describes the particular service which the client agent
043: * woul like to receive from the provider agent.
044: */
045:
046: public class ServiceRequestImpl implements ServiceRequest,
047: java.io.Serializable {
048: //private static Logger logger = Logging.getLogger(ServiceRequestImpl.class);
049:
050: private Asset myClient;
051: private Role myServiceRole;
052: private Collection myServicePreferences;
053: private transient String myToString = null;
054:
055: public ServiceRequestImpl() {
056: }
057:
058: public ServiceRequestImpl(Asset client, Role serviceRole,
059: Collection preferences) {
060: setClient(client);
061: setServiceRole(serviceRole);
062: setServicePreferences(preferences);
063: }
064:
065: /**
066: * Returns the asset representing the client
067: */
068: public Asset getClient() {
069: return myClient;
070: }
071:
072: /**
073: * Sets the asset representing the client
074: *
075: */
076: public void setClient(Asset client) {
077: // Must be cloned by caller
078: myClient = client;
079: }
080:
081: /**
082: * Returns the requested service role
083: * service.
084: */
085: public Role getServiceRole() {
086: return myServiceRole;
087: }
088:
089: /**
090: * Sets the asset representing the client
091: *
092: */
093: public void setServiceRole(Role serviceRole) {
094: myServiceRole = serviceRole;
095: }
096:
097: /**
098: * Returns a read only collection Preferences for the requested service
099: * service.
100: */
101: public Collection getServicePreferences() {
102: if (myServicePreferences == null) {
103: return Collections.EMPTY_LIST;
104: } else {
105: return Collections
106: .unmodifiableCollection(myServicePreferences);
107: }
108: }
109:
110: /**
111: * Sets the service preferences for this service.
112: */
113: public void setServicePreferences(Collection servicePreferences) {
114: myServicePreferences = new ArrayList(servicePreferences);
115: }
116:
117: public String toString() {
118: if (myToString == null)
119: myToString = "<ServiceRequestImpl: Role: " + myServiceRole
120: + ", Client: " + getClient() + ", # ServicePrefs: "
121: + getServicePreferences().size() + ">";
122: return myToString;
123: }
124: }
|