Sun ONE Application Framework (JATO)Getting Started |
This document and the associated tutorial introduce developers to the mechanics and techniques used to build web applications with JATO. They are intended for developers who are at least somewhat familiar with building web applications using existing J2EE web technologies (servlets and JSPs), but new to building web applications with JATO. This document and the tutorial assume Java expertise and familiarity with the development and deployment procedures for the specific servlet container and development tools being used.
This purpose of this document is to outline the mechanics of using JATO to build a J2EE web application.
Note, however, that because JATO is foremost a design pattern and a set of interfaces, the examples here show only the most basic way of creating a JATO application, by extending existing JATO implementation base classes and manually constructing certain application objects. Realize, though, that this is only one possible way to create a JATO application.
There are three reasons for not showing more advanced techniques in this document. First, starting at a fundamental level is the most direct way to impart how JATO works to someone new to the framework. Being able to see exactly how JATO interacts with the application is critical to getting the most out of JATO.
Second, the current release of JATO does not include other ways to construct an application. We are currently working on declarative application construction features for the next JATO release. These features will allow application construction using XML metadata, and allow JATO to be integrated with sophisticated application builder tools.
Finally, building an application using these fundamental techniques is a prerequisite to fully understand the many possible ways to build JATO applications. Features that extend JATO to add additional capabilities (like the declarative features described above) are built on the techniques we demonstrate in this document. This means that after understanding these basic examples, not only will you have a greater understanding of how these features extend and complement the JATO core, but you will be able to optionally decide not to use them and instead construct your own JATO extensions (or simply fall back to a more basic approach where necessary).
The ultimate goal of this document, then, is to introduce developers to the most fundamental way to build JATO applications, so that they become both familiar with JATO's interactions with applications built on top of it, and more fluent in JATO itself.
Writing a JATO application consists of first laying out an application structure and then incrementally adding JATO objects to that structure. Although this can be done entirely by hand, from scratch, we've simplified the task by including with the JATO distribution a number of templates that developers can use to more quickly begin writing their applications. With the assistance of these templates, creating a JATO application is a simple process of copying templates and customizing them to an application.
Before demonstrating the creation of a simple JATO application, let's cover the basics of how a JATO application is structured and the templates that are available with this document.
When talking about JATO applications, we use terms like application, module, and components. Unfortunately, these terms can be confusing because they are also used in more general non-JATO web architecture and development discussions. Therefore, we attempt to clarify below the most important terms we will be using in this document.
Term | Description |
---|---|
J2EE component* | Sometimes referred to as J2EE application components; concrete software components which are deployed, managed, and executed on a J2EE server including EJBs, Servlets, and Java Server Pages (JSPs); there are components including HTML and Applets which are also J2EE components but these are not relevant to the JATO web application discussion |
J2EE module* | Represents the basic unit of composition of a J2EE application. They consist of one or more J2EE components and one component-level deployment descriptor. J2EE modules can be deployed as stand-alone units or can be assembled with a J2EE application deployment descriptor and deployed as a J2EE application. Servlet and/or JSP components are packaged as a J2EE module and deployed as a WAR file. EJB components are packaged as a J2EE module and deployed as a JAR file. An arbitary number or WAR files and JAR files may be combined to form a J2EE application and deployed as a EAR file. WAR files (J2EE modules which are also known as J2EE web applications) may be deployed stand-alone on a J2EE server. |
J2EE web application* | Stand-alone J2EE modules containing J2EE components deployable in a J2EE servlet container (web application container). Depending on the context of the term application or J2EE application, the intent may be to refer to a J2EE web application; there are products such as iPlanet Web Server 6.0 and Apache Tomcat which support J2EE web applications in that they can manage J2EE modules consisting of Servlets and JSPs, but they cannot manage a complete J2EE application which may have EJB J2EE modules. |
J2EE application* | Consists of one or more J2EE modules and one J2EE application deployment
descriptor, packaged using the Java archive (JAR) file format into
a file with a .ear (enterprise archive) filename extension. |
JATO module | Refers to both a logical and physical partition of content and components within a JATO application; not to be confused with a J2EE module |
JATO application |
In informal terms, a JATO application is a J2EE web application that has been written using JATO. It consists of at least one J2EE module (the web application), but may also include other non-JATO J2EE components or modules. A minimal JATO application is a J2EE web application consisting of one WAR file. In formal terms, a JATO application is a collection of related JATO modules, all running in the same servlet context. In this sense, "JATO application" refers only to this logical JATO abstraction. |
* Refer to the Java 2 Platform Enterprise Edition Specification v1.2 (J2EE) section J2EE8.1 for detailed explaination of this term
JATO provides formal application and module entities. A JATO application is a base Java package that contains one or more sub-packages (JATO modules). It is perfectly acceptable for an application to consist of only one module, and this will likely be the common situation for smaller applications. Each module inherits behavior from its parent application-level components, and may also customize this behavior separately from other modules.
In J2EE web application container terms, a JATO application will correspond one-to-one with a servlet context, and thus will be subject to the constraints enforced by the container for servlet contexts.
Before beginning development of your application, you should first decide how it will be organized:
/webapps
directory
would bear this name. In iPlanet Application Server, the directory immediately
beneath the /ias/APPS/modules
directory would bear this name.
The deployed application name will be the same as the name of the WAR
file.Example: Suppose we have two JATO modules called “module1” and "module2”, which comprise a JATO application. We call this application “myapp”. The full application package name is “com.mycompany.myapp”.
com.mycompany.myapp
com.mycompany.myapp.module1
com.mycompany.myapp.module2
One final note about application and module naming conventions: In general, the application package name should be different from that of any of its modules. For example, your first instinct might be to name both your application and its primary module "foo". This can easily lead to confusion for someone trying to understand your application, as well as your application development tools. Instead, consider naming the application package something like “fooapp”, or calling the primary module something like "main" or "module1". This will make your application structure much easier to understand, especially when you add to it in the future.
The JATO distribution contains a set of templates you can use to begin building your JATO applications. The templates are organized into application- and module-level templates as follows:
/templates/1_2 /ApplicationTemplates /ModuleTemplates
Note, several of the JATO templates assume that you will be using QueryModels and accessing JDBC data sources, and.thus include some infrastructure code related to the initialization of model and connection managers. It does not hurt to leave that code in place even if you do not intend to use QueryModels and JDBC data sources. This code is minimal and harmless. However, you always have the option of removing any code that is not used.
The template files contain tokens that follow the following pattern
__<token name>__After copying a template to your application work area, these tokens should be replaced with values appropriate to your application and/or module.
Token | Replace With | Example |
---|---|---|
__appPackage__ |
Fully qualified application package name | com.mycompany.myapp |
__appName__ |
Unqualified application class name | MyApp |
__modulePackage__ |
Unqualified module package name (lowercase). The assumption here is that the module package name will be lowercase, but the module servlet class name used elsewhere may be uppercase. If the module package name is uppercase, there is no difference between __modulePackage__ and __moduleName__. | mymodule |
__moduleName__ |
Module servlet class name (mixedcase). The assumption here is that the module package name will be lowercase, but the module servlet class name used elsewhere may be mixed cass. If the module package name is mixed case, there may be no difference between __modulePackage__ and __moduleName__. | MyModule |
__page__ |
A page name | ListCustomers |
__tiledView__ |
A tiled view name | CustomerList |
__queryModel__ |
A model name | EditCustomersModel |
The application-level templates are located in the /templates/1_2/ApplicationTemplates
directory and include the following files:
Application Template | Description | Num Uses | Renamed Example |
---|---|---|---|
__appName__ServletBase.java |
Application servlet class template | Once per application | MyAppServletBase.java |
ModelTypeMapImpl.java |
Model type map class template | Once per application | ModelTypeMapImpl.java |
SQLConnectionManagerImpl.java |
SQL connection manager class template | Once per application | SQLConnectionManagerImpl.java |
web.xml |
Web deployment descriptor template | Once per application | web.xml |
The module-level templates are located in the /templates/1_2/ModuleTemplates
directory and include the following files:
Module Template | Description | Num Uses | Renamed Example |
---|---|---|---|
__moduleName__Servlet.java |
Module servlet class template | Once per module | FooModuleServlet.java |
__page__ViewBean.java |
ViewBean class template | Many times per module | ListCustomersViewBean.java |
__tiledView__TiledView.java |
TiledView class template | Many times per module | CustomerListTiledView.java |
__queryModel__.java |
QueryModel interface class template | Many times per module | EditCustomersModel.java |
__queryModel__Impl.java |
QueryModel implementation class template | Many times per module | EditCustomersModelImpl.java |
__page__.jsp |
JSP template | Many times per module | ListCustomers.jsp |
Let's develop a simple application to get a taste of using JATO. This application will consist of two pages: a login page, and a customer account page, and will demonstrate the following:
This tutorial breaks the steps required to develop the application into chapters and tasks. Each chapter addresses a broad topic, at the end of which you will have a runnable application. Each task within a chapter is a relatively self-contained topic and contains several more detailed steps.
In this chapter, we create the application infrastructure needed for all subsequent chapters, and add our first JATO page.
In this chapter, we expand the existing application by adding a SQL-based model, and a page to display that model's data. We then link the two application pages together so that they show coordinated data.