01: /*
02: * <copyright>
03: *
04: * Copyright 2002-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.servicediscovery.description;
28:
29: import org.cougaar.planning.ldm.plan.Role;
30:
31: import org.cougaar.util.log.Logger;
32: import org.cougaar.util.log.Logging;
33: import org.cougaar.util.TimeSpan;
34:
35: public class MMRoleQuery extends MMRoleQueryBase {
36: private static Logger logger = Logging.getLogger(MMRoleQuery.class);
37:
38: private ServiceInfoScorer myServiceInfoScorer = null;
39:
40: private static ServiceInfoScorer DEFAULT_SCORER = new ServiceInfoScorer() {
41: public int scoreServiceInfo(ServiceInfo serviceInfo) {
42: return -1;
43: }
44: };
45:
46: public MMRoleQuery(Role role, ServiceInfoScorer serviceInfoScorer) {
47: super (role);
48: myServiceInfoScorer = serviceInfoScorer;
49: }
50:
51: public MMRoleQuery(Role role, ServiceInfoScorer serviceInfoScorer,
52: TimeSpan timeSpan) {
53: super (role, timeSpan);
54: myServiceInfoScorer = serviceInfoScorer;
55: }
56:
57: public ServiceInfoScorer getServiceInfoScorer() {
58: if (myServiceInfoScorer == null) {
59: return DEFAULT_SCORER;
60: } else {
61: return myServiceInfoScorer;
62: }
63: }
64:
65: public void setServiceInfoScorer(ServiceInfoScorer serviceInfoScorer) {
66: if (myServiceInfoScorer != null) {
67: logger
68: .warn("setServiceInfoScorer: ignoring attempt to change ServiceInfoScorer from "
69: + myServiceInfoScorer
70: + " to "
71: + serviceInfoScorer);
72: } else {
73: myServiceInfoScorer = serviceInfoScorer;
74: }
75: }
76:
77: public String toString() {
78: return "Role: " + getRole() + " ServiceInfoScorer: "
79: + myServiceInfoScorer + " TimeSpan: " + getTimeSpan()
80: + " Obsolete: " + getObsolete();
81: }
82:
83: public boolean equals(Object o) {
84: if (o instanceof MMRoleQuery) {
85: MMRoleQuery query = (MMRoleQuery) o;
86: return ((super .equals(o)) && (query.getServiceInfoScorer()
87: .equals(myServiceInfoScorer)));
88: }
89: return false;
90:
91: }
92: }
|