001: /*
002: * <copyright>
003: *
004: * Copyright 1997-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.servlet;
028:
029: import org.cougaar.servicediscovery.description.LineageEchelonScorer;
030: import org.cougaar.servicediscovery.description.MMRoleQuery;
031: import org.cougaar.servicediscovery.transaction.MMQueryRequest;
032: import org.cougaar.servicediscovery.util.UDDIConstants;
033:
034: /**
035: * <pre>
036: *
037: * The MilitaryServiceQueryTranslator is a concrete class that one can
038: * translate a Military Entity query string into or out of.
039: * The object contains the key bits of information that are
040: * in the query.
041: *
042: *
043: **/
044:
045: public class MilitaryServiceQueryTranslator extends
046: QueryToHTMLTranslator {
047:
048: private String clientName;
049: private String minimumEchelon;
050: private String classCode;
051: private String classScheme;
052: private float lineageRelaxationPenalty;
053:
054: public static String QUERY_TYPE = "MilitaryServiceQuery";
055: private static String QUERY_TITLE = "Military Service Query";
056:
057: public MilitaryServiceQueryTranslator(String aClientName,
058: String anMinimumEchelon, String aClassCode,
059: String aClassScheme, float relaxationPenalty) {
060: clientName = aClientName;
061: minimumEchelon = anMinimumEchelon;
062: classCode = aClassCode;
063: classScheme = aClassScheme;
064: lineageRelaxationPenalty = relaxationPenalty;
065: }
066:
067: public String getClientName() {
068: return clientName;
069: }
070:
071: public String getMinimumEchelon() {
072: return minimumEchelon;
073: }
074:
075: public String getClassCode() {
076: return classCode;
077: }
078:
079: public String getClassScheme() {
080: return classScheme;
081: }
082:
083: public float getLineageRelaxationPenalty() {
084: return lineageRelaxationPenalty;
085: }
086:
087: public String toQueryString() {
088: return "";
089: }
090:
091: public String toString() {
092: return ("MilitaryServiceQueryTranslator - clientName="
093: + clientName + " minimumEchelon=" + minimumEchelon
094: + " classCode=" + classCode + " classScheme="
095: + classScheme + " lineageRelaxationPenalty=" + lineageRelaxationPenalty);
096: }
097:
098: public String queryType() {
099: return QUERY_TYPE;
100: }
101:
102: public String queryTitle() {
103: return QUERY_TITLE;
104: }
105:
106: public String beginHTMLQueryTable(String title, String subTitle) {
107: String retStr = ("<table border=1 cellpadding=3 cellspacing=1 width=\"100%\">\n"
108: + "<tr bgcolor=lightblue><th align=left colspan=1>");
109: retStr = retStr + title;
110: if (subTitle != null) {
111: retStr = retStr
112: + ("  <tt><i>"
113: + subTitle + "</i></tt>");
114: }
115:
116: return retStr;
117:
118: }
119:
120: public String getHTMLQueryText() {
121: return ("Find " + getMinimumEchelon()
122: + "-level or higher of type " + getClassCode()
123: + " (using " + getClassScheme() + ")");
124: }
125:
126: public String toHTMLQueryTableRow() {
127: return ("<tr align=left><td>" + getHTMLQueryText() + "</td></tr>\n");
128: }
129:
130: public String endHTMLQueryTable() {
131: return ("</table>\n" + "<p>\n");
132: }
133:
134: public String beginHTMLQueriesTable(String title, String subTitle) {
135: String retStr = ("<table border=1 cellpadding=3 cellspacing=1 width=\"100%\">\n"
136: + "<tr bgcolor=lightblue><th align=left colspan=3>");
137: retStr = retStr + title;
138: if (subTitle != null) {
139: retStr = retStr
140: + (" <tt><i>"
141: + subTitle + "</i></tt>");
142: }
143: return (retStr + "</th></tr>\n" + "<tr>" + "<th>UID</th>"
144: + "<th>Query</th>" + "<th>Has Result?</th>" + "</tr>\n");
145: }
146:
147: public String toHTMLQueriesTableRow(String queryUID,
148: MMQueryRequest mmqr) {
149: String retStr = ("<tr align=center><td>"
150: + "\n<a href=\"matchmaker_query?viewType=viewSpecificQuery&queryType="
151: + queryType() + "&UID=" + queryUID + "\">" + queryUID + "</a>\n");
152: retStr = retStr
153: + ("</td><td align=left>" + getHTMLQueryText() + "</td><td>");
154: if (mmqr.getResult() == null) {
155: retStr += "No";
156: } else {
157: retStr += "Yes";
158: }
159: return (retStr + "</td></tr>\n");
160: }
161:
162: public String endHTMLQueriesTable() {
163: return ("</table>\n" + "<p>\n");
164: }
165:
166: public static MilitaryServiceQueryTranslator createFromMMRoleQuery(
167: MMRoleQuery rq) {
168: String minimumEchelon = "";
169: if (rq.getServiceInfoScorer() instanceof LineageEchelonScorer) {
170: minimumEchelon = ((LineageEchelonScorer) rq
171: .getServiceInfoScorer()).getMinimumEchelon();
172: }
173: return new MilitaryServiceQueryTranslator(null, minimumEchelon,
174: rq.getRole().getName(),
175: UDDIConstants.MILITARY_SERVICE_SCHEME, 10);
176:
177: }
178:
179: }
|