FileDocCategorySizeDatePackage
ToolApp.javaAPI DocExample1831Thu Apr 05 20:26:36 BST 2001None

ToolApp

public class ToolApp extends Object implements Application

Fields Summary
private Log
log
private Tool[]
tools
Constructors Summary
Methods Summary
public java.lang.ObjectcreateContext(ApplicationRequest request, ApplicationResponse response)

    return new ToolContext(request, response, this);
  
public voiddestroy()

  
public java.lang.ClassgetContextType()

    return ToolContext.class;
  
public Tool[]getTools()

    // Normally the "application" would maintain or have access to a 
    // pre-existing database connection.  Here, for simplicity, we use XML.
    return tools;
  
public Tool[]getTools(java.lang.String state)

    // Return only tools of a given state
    // (submitted, live, rejected, or dead)
    List list = new LinkedList();
    for (int i = 0; i < tools.length; i++) {
      if (tools[i].getStateFlag().equalsIgnoreCase(state)) {
        list.add(tools[i]);
      }
    }
    return (Tool[]) list.toArray(new Tool[0]);
  
public voidinit(ApplicationConfig config)

    // Keep a log of events specific to this application
    log = config.getLog();

    // Load the tool data in our init for simplicity
    String toolsFile = config.getInitParameter("toolsFile");
    if (toolsFile == null) {
      throw new ServletException(
        "A tools data file must be specified as the toolsFile init parameter");
    }
    log.debug("Loading tools from " + toolsFile);
    try {
      tools = Tool.loadTools(toolsFile);
      if (tools.length == 0) {
        log.warn("No tools found in " + toolsFile);
      }
    }
    catch (Exception e) {
      log.error(e);
      throw new ServletException(e);
    }