com.objectwave.appArch.admin
Class HTTPCommandImpl

java.lang.Object
  |
  +--com.objectwave.appArch.admin.HTTPCommandImpl
All Implemented Interfaces:
ReplyHandler

public class HTTPCommandImpl
extends java.lang.Object
implements ReplyHandler

Expose Command Callback functions through HTTP.

Version:
1.0
Author:
Dave Hoag

Nested Class Summary
static class HTTPCommandImpl.Test
           
 
Constructor Summary
HTTPCommandImpl()
           
 
Method Summary
protected  void addCommandChildren(TreeCollection tree, java.lang.Object node, java.lang.String divName, java.lang.StringBuffer result)
          While similar to FormatCommands, this method builds the child nodes in the tree.
protected  java.io.InputStream fileFetch(java.lang.String fileName)
          Not the most efficient way to serve a file to the browser, but this should not be used under heavy load.
protected  void formatCommands(TreeCollection tree, java.lang.StringBuffer result)
          Format the BODY portion of the HTML document for all of the commands.
 Command[] getAllCommands()
          Get the callback commands from the CallbackService.
protected  java.lang.String getAllCommandsHTML()
          Create an HTML body that will represent all of the regestered commands.
 java.lang.String getDocHeader(java.lang.String title, java.lang.String javascript, java.lang.String bodyAttributes)
          Start the HTML document and fill in the required fields.
protected  java.lang.String getSeedString()
          The seedstring will be included in the HTML header of the getAllCommands request.
 java.lang.String getTail()
           
 void initialize()
           
protected  java.io.InputStream processCommandWork(java.lang.String commandString, java.lang.String argString)
          Process the command and return the results.
protected  java.io.InputStream processFormRequest(java.lang.String urlRequest, int idx)
          The URL request was the result of a Form 'get' method.
 java.io.InputStream processRequest(java.lang.String urlRequest)
          Process an incomming URL request.
protected  java.io.InputStream processRequest(java.lang.String urlRequest, int idx)
          Process the urlRequest as a either a noArg request, or a request that was formatted to a custom style.
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTTPCommandImpl

public HTTPCommandImpl()
Method Detail

getDocHeader

public java.lang.String getDocHeader(java.lang.String title,
                                     java.lang.String javascript,
                                     java.lang.String bodyAttributes)
Start the HTML document and fill in the required fields.

Parameters:
title - The title to use for the HTML document.
javascript - The data to place in the HEAD portion of the html document.
bodyAttributes - A string to put within the BODY tag. Can be used to specify an 'onLoad' event handler.
Returns:
The DocHeader value

getTail

public java.lang.String getTail()
Returns:
The Tail value

getAllCommands

public Command[] getAllCommands()
Get the callback commands from the CallbackService.

Returns:
The AllCommands value
See Also:

getAllCommandsHTML

protected java.lang.String getAllCommandsHTML()
Create an HTML body that will represent all of the regestered commands. This body uses DIV tags and JavaScript to create a collapseable tree like structure for displaying the commands.

Returns:
String All of the commands in a predefined formatted HTML document that will work with the JavaScript.

getSeedString

protected java.lang.String getSeedString()
The seedstring will be included in the HTML header of the getAllCommands request.

Returns:
String JavaScript that will setup the expanding command tree.

initialize

public void initialize()

shutdown

public void shutdown()

processRequest

public java.io.InputStream processRequest(java.lang.String urlRequest)
Process an incomming URL request. This is basically anything that is after the URL Port Number http://localhost:2003/one The command would be '/one'.

Specified by:
processRequest in interface ReplyHandler
Parameters:
urlRequest - The command received from the browser.
Returns:

processFormRequest

protected java.io.InputStream processFormRequest(java.lang.String urlRequest,
                                                 int idx)
The URL request was the result of a Form 'get' method. Extract the command and the arguments from the URL and pass this onto the processCommandWork method.

Parameters:
urlRequest - A URL that is a form 'get' request.
idx - The index of the start of the arguments in the URL
Returns:
InputStream A stream that is the result of the request.
See Also:
processCommandWork(java.lang.String, java.lang.String)

processRequest

protected java.io.InputStream processRequest(java.lang.String urlRequest,
                                             int idx)
Process the urlRequest as a either a noArg request, or a request that was formatted to a custom style. The custom style should not be used,and is kept around for legacy reasons. Extract the command and the arguments from the URL and pass this onto the processCommandWork method.

Parameters:
urlRequest - A URL that should identify a command in the command callback service.
idx - int The index of a ":" in the urlRequest. This was the original mechanism for parameter processing.
Returns:
InputStream A stream that is the result of the request.
See Also:
processCommandWork(java.lang.String, java.lang.String)

fileFetch

protected java.io.InputStream fileFetch(java.lang.String fileName)
Not the most efficient way to serve a file to the browser, but this should not be used under heavy load.

Parameters:
fileName - The name of resource to return as an InputStream.
Returns:
InputStream The data found in the provided resource.

processCommandWork

protected java.io.InputStream processCommandWork(java.lang.String commandString,
                                                 java.lang.String argString)
Process the command and return the results. The command may not actually be a command, it may be a resource (like an image) that the browser needs for display.

Parameters:
commandString - A known registered command or a file resource.
argString - Comma separated arguments.
Returns:
InputStream A stream that is the result of the request.

formatCommands

protected void formatCommands(TreeCollection tree,
                              java.lang.StringBuffer result)
Format the BODY portion of the HTML document for all of the commands. The commands have been placed into a Tree structure to facilitate the building of the body.

Parameters:
tree - com.objectwave.utility.TreeCollection A tree datastructure containing all of the commands.
result - The formatted body will be built upon this buffer provided as this parameter.

addCommandChildren

protected void addCommandChildren(TreeCollection tree,
                                  java.lang.Object node,
                                  java.lang.String divName,
                                  java.lang.StringBuffer result)
While similar to FormatCommands, this method builds the child nodes in the tree. This method is called recursively building all of the commands.

Parameters:
tree - com.objectwave.utility.TreeCollection A tree datastructure containing all of the commands.
node - The node in the TreeCollection that is being processed.
divName - This is the name the JavaScript will use to identify this command.
result - The formatted child commands will be built upon this buffer provided as this parameter.