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.Collection;
030: import java.util.Iterator;
031:
032: /**
033: * Contains Service information returned from a registry query.
034: */
035:
036: public class ServiceInfo {
037: String serviceName = null;
038: String serviceId = null;
039: Collection serviceClassifications = null;
040: Collection serviceBindings = null;
041: String providerName = null;
042: Collection businessClassifications = null;
043:
044: public ServiceInfo() {
045: }
046:
047: /**
048: * Constructs a ServiceInfo object.
049: * @param serviceName name of this service
050: * @param serviceId unique indentifier of this service
051: * @param serviceClassifications all classifications of this service
052: * @param serviceBindings all service bindings for this service
053: * @param providerName provider of this service
054: * @param businessClassifications all classifications of the provider
055: */
056: public ServiceInfo(String serviceName, String serviceId,
057: Collection serviceClassifications,
058: Collection serviceBindings, String providerName,
059: Collection businessClassifications) {
060: this .serviceName = serviceName;
061: this .serviceId = serviceId;
062: this .serviceClassifications = serviceClassifications;
063: this .serviceBindings = serviceBindings;
064: this .providerName = providerName;
065: this .businessClassifications = businessClassifications;
066: }
067:
068: /**
069: * Sets the name of this service.
070: * @param serviceName name of this service
071: */
072: public void setServiceName(String serviceName) {
073: this .serviceName = serviceName;
074: }
075:
076: /**
077: * Return the name of this service.
078: * @return String name of this service
079: */
080: public String getServiceName() {
081: return serviceName;
082: }
083:
084: public void setServiceId(String serviceId) {
085: this .serviceId = serviceId;
086: }
087:
088: public String getServiceId() {
089: return serviceId;
090: }
091:
092: /**
093: * Sets all ServiceClassifications of this service.
094: * @param serviceClassifications Collection of ServiceClassifications.
095: */
096: public void setServiceClassifications(
097: Collection serviceClassifications) {
098: this .serviceClassifications = serviceClassifications;
099: }
100:
101: /**
102: * Returns all ServiceClassifications of this service.
103: * @return Collection of ServiceClassifications, null if none exist.
104: */
105: public Collection getServiceClassifications() {
106: return serviceClassifications;
107: }
108:
109: /**
110: * Set the service bindings for this service.
111: * @param serviceBindings Collection of ServiceBindings.
112: */
113: public void setServiceBindings(Collection serviceBindings) {
114: this .serviceBindings = serviceBindings;
115: }
116:
117: /**
118: * Returns all ServiceBindings of this service.
119: * @return Collection of ServiceBindings, null if none exist.
120: */
121: public Collection getServiceBindings() {
122: return serviceBindings;
123: }
124:
125: public void setProviderName(String providerName) {
126: this .providerName = providerName;
127: }
128:
129: public String getProviderName() {
130: if (this .providerName != null) {
131: return this .providerName;
132: } else {
133: return getMessageAddress();
134: }
135: }
136:
137: /**
138: * Sets all BusinessClassifications of this service.
139: * @param businessClassifications Collection of BusinessClassifications.
140: */
141: public void setBusinessClassifications(
142: Collection businessClassifications) {
143: this .businessClassifications = businessClassifications;
144: }
145:
146: /**
147: * Returns all BusinessClassifications of this service.
148: * @return Collection of BusinessClassifications, empty if none exist.
149: */
150: public Collection getBusinessClassifications() {
151: return businessClassifications;
152: }
153:
154: /**
155: * Compares with other ServiceInfo object.
156: * ServiceInfo objects are considered to be equal if the provider name
157: * and serviceId are the same.
158: */
159: public boolean equals(Object obj) {
160: if (obj instanceof ServiceInfo) {
161: ServiceInfo other = (ServiceInfo) obj;
162: String this One = this .getProviderName() + this .serviceId;
163: return this One.equals(other.getProviderName()
164: + other.getServiceId());
165: }
166: return false;
167: }
168:
169: /**
170: * Temporary method to provide another way to get the provider name from the UDDI registry
171: * that is less costly. The other code is using provider name as a means to contact the
172: * provider. Provider names in Cougaar are often, but not limited to, the MessageAddress i.e.,
173: * the address of the agent providing the service. Provider name may not be the correct usage
174: * in terms of how one agent accesses a another agent's service and we should rethink the usage
175: * of this API.
176: * @return String address of the agent.
177: */
178: private String getMessageAddress() {
179: String messageAddress = null;
180: if (this .serviceBindings != null) {
181: for (Iterator iter = this .serviceBindings.iterator(); iter
182: .hasNext();) {
183: ServiceBinding serviceBinding = (ServiceBinding) iter
184: .next();
185: messageAddress = serviceBinding.getMessageAddress();
186: }
187: }
188: return messageAddress;
189: }
190: }
|