Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

edu.virtualschool.jwaa.xml.Controller Class Reference

Inheritance diagram for edu.virtualschool.jwaa.xml.Controller:

edu.virtualschool.jwaa.GenericPage Collaboration diagram for edu.virtualschool.jwaa.xml.Controller:

Collaboration graph
[legend]
List of all members.

Detailed Description

Controller is the interface between velocity code and the rest of the Java runtime. It define the execution environment for the execution of each page and provides a large number of convenience methods to aid velocity code in accessing the rest of the system.

In MVC terminology, if a page instance is the model, the velocity code is the view and the Controller is the controller for a specific presentation of that page to a browser. It inherits most of the code and data for doing this from GenericPage; the http request and response instances and the servlet instance being particularly important.

The controller determines the application by parsing the pageInfo string and uses that to find the requested page in the application's pageMap, first calling the root instance's update command to ensure that page and application XML files are reloaded when they change.

The controller constructs a Velocity context object by adding all form parameters to the context, plus two additional variables, a $self variable that identifies the controller instance, and a $person variable with the GenericPerson object for the currently logged in user or GenericPerson.Null for external pages that don't require logging in. It obtains the text of the page, which was constructed at XML load/reload time by converting the DOM model to text), filters it through the application's VelocityEngine instance, and sends the resulting string to the browser.

The controller ($self) and the GenericPerson instance ($person) are the only access the velocity code has to the rest of the system. Accordingly the controller provides several methods designed to simplify velocity's access to other key objects.

Definition at line 67 of file Controller.java.

Public Member Functions

final void run () throws Fault
final void fault (String text, Throwable e)
final void gotoPage (String pageID)
final PageElement findPage (String id)
final ApplicationElement getApplication ()
final PageElement getPage ()
final DB getDB ()
String getNavigationBar ()
final PageElement getNextPage ()
final PageElement getPrevPage ()
String link (String key)
final void logout ()

Static Public Attributes

final edu.virtualschool.jwaa.MetaPage meta

Package Attributes

DB dbms
PageElement page
HashMap dictionary
final HashMap param = new HashMap()
final VelocityContext context = new VelocityContext()

Static Package Attributes

final Logger logger = Logger.getLogger(Controller.class.getName())
final VirtualSchoolNavigationBar topRow = new VirtualSchoolNavigationBar("JWAA")


Member Function Documentation

final PageElement edu.virtualschool.jwaa.xml.Controller.findPage String  id  ) 
 

Find a page by id

Parameters:
id: the desired page's id
Returns:
PageElement

Definition at line 180 of file Controller.java.

References edu.virtualschool.jwaa.xml.ApplicationElement.findPage(), and edu.virtualschool.jwaa.xml.Controller.getApplication().

00181   {
00182     return getApplication().findPage(id);
00183   }

final ApplicationElement edu.virtualschool.jwaa.xml.Controller.getApplication  ) 
 

Get the application of the current page

Returns:
ApplicationElement

Definition at line 188 of file Controller.java.

References edu.virtualschool.jwaa.xml.PageElement.getApplication().

Referenced by edu.virtualschool.jwaa.xml.Controller.findPage().

00189   {
00190     return page.getApplication();
00191   }

final DB edu.virtualschool.jwaa.xml.Controller.getDB  ) 
 

Get the database instance

Returns:
DB

Definition at line 204 of file Controller.java.

00205   {
00206     return dbms;
00207   }

final PageElement edu.virtualschool.jwaa.xml.Controller.getPage  ) 
 

Get the current page

Returns:
PageElement

Definition at line 196 of file Controller.java.

00197   {
00198     return page;
00199   }

String edu.virtualschool.jwaa.xml.Controller.link String  key  ) 
 

Convenience class required by velocity code in the SOURCES page.

Definition at line 271 of file Controller.java.

00272   {
00273     String uri = (String)dictionary.get(key);
00274     if (uri != null)
00275       return (String)httpResponse.encodeURL(uri);
00276     logger.error(key + " not found in application dictionary");
00277     return "<b>("+key+" not found in dictionary)</b>";
00278   }

final void edu.virtualschool.jwaa.xml.Controller.logout  ) 
 

Convenience class required by velocity code in the LOGOUT page.

Definition at line 283 of file Controller.java.

00284   {
00285     super.setAccount(DemoAccountBean.Null);
00286   }

final void edu.virtualschool.jwaa.xml.Controller.run  )  throws Fault [virtual]
 

Servlet calls this to run the page. Every subclass overrides this to send html to the browser, to process form parameters, and so forth.

Exceptions:
IOFault upon IOException
ServletFault upon ServletException
DB.Fault upon all other exceptions

Implements edu.virtualschool.jwaa.GenericPage.

Definition at line 86 of file Controller.java.

References edu.virtualschool.jwaa.MetaPage.allowsAccessBy(), edu.virtualschool.jwaa.dbms.DB.close(), edu.virtualschool.jwaa.dbms.DB.commit(), edu.virtualschool.jwaa.xml.VelocityEngine.evaluate(), edu.virtualschool.jwaa.xml.RootDirectory.findPath(), edu.virtualschool.jwaa.GenericPage.getAccount(), edu.virtualschool.jwaa.xml.PageElement.getApplication(), edu.virtualschool.jwaa.xml.ApplicationElement.getDBMS(), edu.virtualschool.jwaa.xml.ApplicationElement.getDictionary(), edu.virtualschool.jwaa.xml.PageElement.getFormInstance(), edu.virtualschool.jwaa.xml.ApplicationElement.getRefusePage(), edu.virtualschool.jwaa.xml.JwaaServlet.getRoot(), edu.virtualschool.jwaa.xml.PageElement.getText(), edu.virtualschool.jwaa.xml.ApplicationElement.getVelocityEngine(), edu.virtualschool.jwaa.dbms.DB.rollback(), and edu.virtualschool.jwaa.GenericPage.send().

00087   {
00088     String path = httpRequest.getPathInfo();
00089     
00090     JwaaServlet servlet = (JwaaServlet)this.servlet;
00091     RootDirectory root = servlet.getRoot();
00092     this.page = root.findPath(path);
00093     if (page == null)
00094       throw new Fault(path+" is not a valid application");
00095       
00096     ApplicationElement app = page.getApplication();
00097     AccountAbstraction account = getAccount();
00098     if (!page.allowsAccessBy(account))
00099       page = app.getRefusePage();
00100       
00101     try
00102     {
00103       this.dbms = app.getDBMS();
00104       this.dictionary = app.getDictionary();
00105 
00106       GenericForm form = page.getFormInstance(this);
00107       this.context.put("self", this);
00108       this.context.put("account", account);
00109       this.context.put("dbms", dbms);
00110       this.context.put("form", form);
00111       
00112       VelocityEngine engine = app.getVelocityEngine();
00113       String pageText = page.getText();
00114       String evalText = engine.evaluate(pageText, this.context);
00115       send(evalText);
00116       dbms.commit();
00117     }
00118     catch (Fault e)
00119     {
00120       logger.error(e, e);
00121       if (dbms != null)
00122         dbms.rollback();
00123       throw e;
00124     }
00125     finally
00126     {
00127       if (dbms != null)
00128         dbms.close();
00129     }
00130   }


Member Data Documentation

final edu.virtualschool.jwaa.MetaPage edu.virtualschool.jwaa.xml.Controller.meta [static]
 

Initial value:

 new edu.virtualschool.jwaa.MetaPage(
      Controller.class,
      "/jwaa/xml",
      "Controller",
      "Jwaa XML Page Controller"
    )

Reimplemented from edu.virtualschool.jwaa.GenericPage.

Definition at line 76 of file Controller.java.

final VirtualSchoolNavigationBar edu.virtualschool.jwaa.xml.Controller.topRow = new VirtualSchoolNavigationBar("JWAA") [static, package]
 

Return a string containing the navigation bar for this page

Returns:
String

Definition at line 212 of file Controller.java.


The documentation for this class was generated from the following file: