A Free Hotel Manager
Room Rack alpha library guide

Introduction

The library is designed mainly to eliminate the redundancy of coding forms in Room Rack. This guide also would like to urge the users to use the library and soon it would evolve into maturity. Hopefully the library through this documentation would be appealing to programmers and by reuse, it would flourish into a functional tool in developing Room Rack.

There are 3 main classes in the library. RequestManager, PageFactory and FreeForm each of them can be seen at the basic diagram of Room Rack http://roomrack.sourceforge.net/roomrack_design.jpg

RequestManager.java

This is the only servlet in the library. Inside doGet() it creates an instance of PageFactory and depending on the parameters;

String s_display_page = a_req.getParameter("display_page");

S_display_page is passed to PageFactory. The PageFactory then responses to the request and construct a PageBuilder. The term PageBuilder by the way, is a subclass from AbstractPageBuilder

public abstract class AbstractPageBuilder {

String thePage;

String BuilderName;

public String getHTMLPage() {

return thePage;

}

public String getBuilderName() {

return BuilderName;

}

}

 

Back to RequestManager. After it receives the PageBuilder from PageFactory. Request Manager stores it in session. For upon loopback, it checks again the session that if there is an existing builder stored inside. The following code analyses the request btn_submit that is invoked from HtmlToolBarBuilder() which is also a subclass from AbstractFormBuilder()

String s_btn_action = a_req.getParameter("btn_submit");

..

AbstractUpdateablePageBuilder page_builder = (AbstractUpdateablePageBuilder)session.getAttribute("object/page_builder");

..

if (s_display_page == null) {

if (page_builder != null) {

if (s_btn_action.equals(HtmlToolbarBuilder.TOP)) {

page_builder.top();

} else if (s_btn_action.equals(HtmlToolbarBuilder.PREV)) {

page_builder.prev();

} else if (s_btn_action.equals(HtmlToolbarBuilder.NEXT)) {

page_builder.next();

} else if s_btn_action.equals(HtmlToolbarBuilder.BOTTOM)) {

page_builder.bottom();

} else if (s_btn_action.equals(HtmlToolbarBuilder.SAVE)) {

page_builder.update(a_req);

} else if (s_btn_action.equals(HtmlToolbarBuilder.NEW)) {

page_builder.insert();

} else if (s_btn_action.equals(HtmlToolbarBuilder.DELETE)) {

page_builder.delete(a_req);

}

..

Now you might notice that instead of AbstractPageBuilder you see an AbstractUpdateablePageBuilder. Well AbstractUpdateablePageBuilder is a subclass from AbstractPageBuilder. It generally constitutes the class of any updateable form (FreeForm and Tabular).

public abstract class AbstractUpdateablePageBuilder extends AbstractPageBuilder{

public abstract int retrieve() throws SQLException;

public abstract int update(HttpServletRequest req);

public abstract int delete(HttpServletRequest req);

public abstract int insert();

	public abstract int top();

public abstract int prev();

public abstract int next();

public abstract int bottom();

public abstract int cancel();

}

So ReqestManager manages any incoming request. and there is only one

out.println(page_builder.getHTMLPage()); and each of the page builders generates their own html form.

PageFactory.java

Well it’s a design based from the Factory pattern. There are plenty of java design pattern articles on the net but this link was the only one saved in my bookmark http://rampages.onramp.net/~huston/dp/patterns.html try to figure out what pattern is also recommended in the library.

Basically a factory returns an object depending on the parameters it receives. Different parameter requests different objects are produced. This time another design pattern Builder Pattern is returned from the factory.

Often a Builder design is used for constructing widgets (scrollbars, TextBox) where inside a builder class the details on how the widget is built.

Use of common design patters removes the burden of analyzing code designs. And in this case PageFactory says: "I’ll return a PageBuilder depending on what you pass on my parameters" here’s a portion of PageFactory

public AbstractPageBuilder constructPage(int a_i_request)

throws IOException

{

switch (a_i_request) {

case LINK:

return new LinkBuilder();

case HOME:

return new SimplePageBuilder("HOME");

default:

return new SimplePageBuilder("Page Request Invalid");

}

}

public AbstractUpdateablePageBuilder constructPage(int a_i_request,String a_s_request_info,XMLPropertyManager a_xml_prop, ConnectToDB a_conn) throws IOException

{

if (a_i_request==FREE_FORM) {

return new FreeForm(a_s_request_info,a_xml_prop,a_conn);

} else {

return new TabularForm(a_s_request_info,a_xml_prop,a_conn);

}

}

FreeForm.java

In simple terms; transform maintenance tables(itemcode, itemtype, supplier codes.. etc) into forms. got this idea from my last employer where maintenance tables were generated in a wizard-like way. Imagine 20 maintenance pages were generated like crazy! In a few minutes they are done, just setting the field length of textboxes and setting the column labels and others are the programmers that have to do. It’s a waste of a programmers mind energy do do those routinal work. I’ll explain further. Get the column length properties in the table. And you got field length. What about validation? If it’s not null then it’s required. If it is a primary key it’s required. If another column is a foreign key it is required. But in FreeForm’s case it does not lookup into the column properties. Instead it retrieves information from an XML file (forms.xml inside the properties folder).

Now you might say: "Do not generalize!" yes if there are some custom maintenance pages just extend FreeForm and override which function should be customized.

FreeForm is a PageBuilder, meaning it generates its own page inside. It’s a subclass of AbstractUpdateablePageBuilder. So basic constitution of AbstractPageBuilder is FreeForm’s constitution. AbstractUpdateablePageBuilder’s method are called from RequestManager. See again above.