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.util.log.Logger;
034: import org.cougaar.util.log.Logging;
035:
036: /**
037: * The ServiceDescription describes a particular service that
038: * is provided by the provider agent.
039: */
040:
041: public class ServiceDescriptionImpl implements ServiceDescription,
042: java.io.Serializable {
043: private static Logger logger = Logging
044: .getLogger(ServiceDescriptionImpl.class);
045:
046: private String myProviderName;
047: private Collection myServiceClassifications;
048: private Collection myServiceBindings;
049:
050: public ServiceDescriptionImpl() {
051: }
052:
053: public ServiceDescriptionImpl(ServiceInfo serviceInfo) {
054: myProviderName = serviceInfo.getProviderName();
055: myServiceClassifications = serviceInfo
056: .getServiceClassifications();
057: myServiceBindings = serviceInfo.getServiceBindings();
058: }
059:
060: /**
061: * Returns the provider (agent) name.
062: */
063: public String getProviderName() {
064: return myProviderName;
065: }
066:
067: /**
068: * Sets the provider (agent) name.
069: * Name can only be set once.
070: */
071: public void setProviderName(String providerName) {
072: if (myProviderName != null) {
073: logger.error("Attempt to reset provider name.");
074: } else {
075: myProviderName = new String(providerName);
076: }
077: }
078:
079: /**
080: * Returns a read only collection of the service classifications for this
081: * service.
082: */
083: public Collection getServiceClassifications() {
084: if (myServiceClassifications == null) {
085: return Collections.EMPTY_LIST;
086: } else {
087: return Collections
088: .unmodifiableCollection(myServiceClassifications);
089: }
090: }
091:
092: /**
093: * Sets the service classifications for this service. Service
094: * classifications can only be set once.
095: */
096: public void setServiceClassifications(
097: Collection serviceClassifications) {
098: if (myServiceClassifications != null) {
099: logger.error("Attempt to reset service classifications.");
100: } else {
101: myServiceClassifications = new ArrayList(
102: serviceClassifications);
103: }
104: }
105:
106: /**
107: * Returns the ServiceBinding for this service
108: */
109: public Collection getServiceBindings() {
110: return myServiceBindings;
111: }
112:
113: /**
114: * Sets the ServiceBinding for this service. ServiceBinding can only be set
115: * once.
116: */
117: public void setServiceBinding(Collection serviceBindings) {
118: if (myServiceBindings != null) {
119: logger.error("Attempt to reset service bindings.");
120: } else {
121: myServiceBindings = new ArrayList(serviceBindings);
122: }
123: }
124: }
|