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.planning.servlet;
028:
029: import java.io.PrintWriter;
030:
031: import org.cougaar.core.servlet.SimpleServletSupport;
032:
033: /**
034: * <pre>
035: * Servlet worker that gathers Organizational hierarchy information
036: * from a Cougaar society.
037: *
038: * Takes three parameters :
039: * - recurse, which controls whether to recurse down the hierarchy
040: * - format, which specifies whether the response is a data stream, xml, or html.
041: * - allRelationships, which returns all the relationships for an agent
042: * html is in the familiar CLUSTERS_R format.
043: *
044: * An example URL is :
045: *
046: * http://localhost:8800/$TRANSCOM/hierarchy?recurse=true&format=xml
047: *
048: * This says to recurse from the TRANSCOM agent and return an XML document.
049: *
050: * Example output from this query :
051: *
052: * <?xml version="1.0" ?>
053: * <Hierarchy RootID="TRANSCOM">
054: * <Org>
055: * <OrgID>TRANSCOM</OrgID>
056: * <Name>TRANSCOM</Name>
057: * <Rel OrgID="GlobalAir" Rel="0"/>
058: * <Rel OrgID="GlobalSea" Rel="0"/>
059: * </Org>
060: * <Org>
061: * <OrgID>GlobalAir</OrgID>
062: * <Name>GlobalAir</Name>
063: * <Rel OrgID="PlanePacker" Rel="0"/>
064: * </Org>
065: * ....
066: * </Hierarchy>
067: * </pre>
068: */
069: public class HierarchyServlet extends ServletBase {
070: public static boolean VERBOSE = false;
071: static {
072: VERBOSE = Boolean
073: .getBoolean("org.cougaar.mlm.ui.psp.transit.HierarchyServlet.verbose");
074: }
075:
076: /**
077: * This is the path for my Servlet, relative to the
078: * Agent's URLEncoded name.
079: * <p>
080: * For example, on Agent "X" the URI request path
081: * will be "/$X/hello".
082: */
083: private final String myPath = "/Hierarchy";
084:
085: /**
086: * Pretty to-String for debugging.
087: */
088: public String toString() {
089: return getClass().getName() + "(" + myPath + ")";
090: }
091:
092: protected ServletWorker createWorker() {
093: return new HierarchyWorker();
094: }
095:
096: /** <pre>
097: *
098: * USAGE
099: *
100: * Allows a number of choices:
101: * 1) Recursive or not
102: * 2) All relationships or just superior-subordinate
103: * 3) Format : html, xml, or serialized java objects
104: *
105: * Only called if no arguments are given.
106: * </pre>
107: */
108: public void getUsage(PrintWriter out, SimpleServletSupport support) {
109: out
110: .print("<HTML><HEAD><TITLE>Hierarchy Usage</TITLE></HEAD><BODY>\n"
111: + "<H2><CENTER>Hierarchy Usage</CENTER></H2><P>\n"
112: + "<FORM METHOD=\"GET\" ACTION=\"/$");
113: out.print(support.getEncodedAgentName());
114: out.print(support.getPath());
115: // choose between shallow and recursive displays
116: out.print("\">\n" + "Show organization hierarchy for:<p>\n"
117: + " <INPUT TYPE=\"radio\" NAME=\"recurse\" "
118: + "VALUE=\"true\" CHECKED>"
119: + " All related agents<p>\n"
120: + " <INPUT TYPE=\"radio\" NAME=\"recurse\" "
121: + "VALUE=\"false\">" + " Just ");
122: out.print(support.getAgentIdentifier());
123: // checkbox for showing all relationships
124: out
125: .print("<P>\n"
126: + " <INPUT TYPE=\"checkbox\" NAME=\"allRelationships\" "
127: + "VALUE=\"true\">"
128: + " Show complete relations (not just superior-subordinate)<p>\n");
129: // choose data format - html, xml, or java objects
130: out.print("<P>\nShow results as "
131: + " <INPUT TYPE=\"radio\" NAME=\"format\" "
132: + "VALUE=\"html\" CHECKED>" + " html ");
133: out.print("<INPUT TYPE=\"radio\" NAME=\"format\" "
134: + "VALUE=\"xml\">" + " xml ");
135: out.print("<INPUT TYPE=\"radio\" NAME=\"format\" "
136: + "VALUE=\"data\">" + " serialized Java objects ");
137: out.print("<P>\n"
138: + "<INPUT TYPE=\"submit\" NAME=\"Display\">\n"
139: + "</FORM></BODY></HTML>");
140: }
141: }
|