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.planning.ldm.PlanningFactory;
030: import org.cougaar.servicediscovery.description.MMQuery;
031: import org.cougaar.servicediscovery.description.MMRoleQuery;
032: import org.cougaar.servicediscovery.transaction.MMQueryRequest;
033:
034: /**
035: * <pre>
036: *
037: * The QueryToHTMLTranslator abstract class defines the method api
038: * for translators for each type of query that will be displayed
039: * in the MatchMakerQueryServlet.
040: *
041: *
042: **/
043:
044: public abstract class QueryToHTMLTranslator {
045:
046: protected PlanningFactory ldmFactory = null;
047:
048: public abstract String toQueryString();
049:
050: public abstract String toString();
051:
052: public abstract String queryType();
053:
054: public abstract String queryTitle();
055:
056: public abstract String beginHTMLQueryTable(String title,
057: String subTitle);
058:
059: public abstract String toHTMLQueryTableRow();
060:
061: public abstract String endHTMLQueryTable();
062:
063: public abstract String beginHTMLQueriesTable(String title,
064: String subTitle);
065:
066: public abstract String toHTMLQueriesTableRow(String queryUID,
067: MMQueryRequest mmqr);
068:
069: public abstract String endHTMLQueriesTable();
070:
071: public void setRootFactory(PlanningFactory ldmFactory) {
072: this .ldmFactory = ldmFactory;
073: }
074:
075: public static QueryToHTMLTranslator createTranslatorForQuery(
076: MMQuery mmq) {
077: if (mmq instanceof MMRoleQuery) {
078: return MilitaryServiceQueryTranslator
079: .createFromMMRoleQuery((MMRoleQuery) mmq);
080: } else {
081: return null;
082: }
083:
084: }
085:
086: public static String getQueryType(MMQuery mmq) {
087: if (mmq instanceof MMRoleQuery) {
088: return MilitaryServiceQueryTranslator.QUERY_TYPE;
089: } else {
090: return null;
091: }
092: }
093:
094: public String beginHTMLQueriesTable(String title) {
095: return beginHTMLQueriesTable(title, "Type: " + queryTitle());
096: }
097:
098: public static void printDiff(String str1, String str2) {
099: int ctr = 0;
100: boolean stillEqual = true;
101: while (stillEqual) {
102: stillEqual = (str1.charAt(ctr) == str2.charAt(ctr));
103: ctr++;
104: }
105: if (ctr < str1.length()) {
106: System.out.println("Rest of String 1: "
107: + str1.substring(ctr));
108: System.out.println("Rest of String 2: "
109: + str2.substring(ctr));
110: }
111:
112: }
113:
114: }
|