![]() |
|
URL of the article:
Delving into EJOSA - Part II
A Look into the Architecture and Development Process using the Magic Template
by Blasius Lofi Dewanto
The first part of this series introduced us to the EJOSA magic template - a solution for J2EE beginners who wish to overcome the complexity of J2EE application development by using Open Source Software (OSS). In the second part of this series, we will move further into the workings of EJOSA Template and look at the specification directory, which is the most important part of EJOSA Template; the business layer, where you implement the specification with available Java technologies; the presentation layer that represents the view of the business logics; and the road ahead for the EJOSA Template.
The previous instalment looked at what makes the development of J2EE applications so complicated and inconvenient. The article took a detailed look at the directory structure of the EJOSA Template and developed a simple "PiggyBank" example to go through the directories. In this article, the author will step you through the specification directory, which is the most important part of EJOSA Template; the business layer, where you implement the specification with available Java technologies; the presentation layer that represents the view of the business logics; and the roadmap for the EJOSA Template. The EJOSA template consists of Enhydra (Web container), JOnAS (EJB container) and HypersonicSQL (data container for development) or Firebird DBMS (data container for production). The Specification The specification directory is the most important part of the EJOSA Template. In this directory, developers only produce the specification of the component and make no implementation. This directory contains mostly Java interfaces and Java utility classes. The component specification is the result of the design phase of component-based software engineering [2] [3]. You can easily use interfaces and build the whole specification totally independent from the implementation part. The result of the specification is often called the Application Programming Interface (API). So how do you build the specification? We can start with analysing the domain and designing the application with UML as explained in the Model section. The UML models, are built using the PoseidonUML Community Edition, which is free (it has its origins in the ArgoUML Java-based Open Source tool). At the end of this activity we will find two types of interfaces (see Figure 1):
![]() Fig. 1: Building the Specification After finding the system and business interfaces, it needs to be deployed in the Java interface. There are three ways to do this:
The EJOSA Template offers a structured directory and some reusable Ant scripts for the component specification. In the build directory you will find the following build files:
In the example we have defined UserActivity as a System Interface and Coin as a Business Interface. All the specification files can be generated from the model (although it is not a must). We also choose to use the totally independent interfaces (please refer to the specification/src-generated directory for more detail). So the next step is to compile and build the whole specification by running specification/build/apply-all-build.xml. Once this is done, a component implementor can implement the specification JAR file, which consists of Java interfaces, with a chosen business implementation technology. The Business Layer The business layer is the implementation of the specification with available Java technologies. After building the system and business interfaces, they have to be implemented with chosen Java technologies. The session objects implement the system interfaces and entity objects implement the business interfaces. There are many options for implementing both interfaces, so we may define many-to-many relationships between session and entity implementation types (see Figure 3). In EJB technology, we can employ Session Beans (SB) and Message Driven Beans (MDB) for system interfaces and Entity Beans (EB) for business interfaces. EJOSA Template recommends J2EE beginners to use the following options, since the result is used in a production environment:
I chose the JOnAS EJB container for EJOSA Template because of the following advantages:
The business directory structure in EJOSA Template looks very similar to the specification directory (see Figure 2). Since it is possible to execute the business layer (in case of EJB container) as a stand-alone process, EJOSA Template adds a binary executable directory. This directory includes an Ant script that can be used to start JOnAS in debug mode. We use several configuration files inside the conf directory to configure JOnAS. EJOSA Template offers a build-jonas.xml build file, inside the build directory, to start the creation of the stubs and skeletons by using the GenIC compiler. ![]() Fig. 2: Business Directory Structure Example: In our example we need to implement the specification with stateless SessionBean for the System Interface and Hibernate POJO for the Business Interface. Some steps to follow:
Extension with inheritance is one of the key methods to extend the generated files to fulfil your needs. Using an IDE with good code analyzing support, like Eclipse, will help you to create missing methods or rename changed methods. Thanks to Ant for build and execution management, we can use our favourite IDE or a pure Linux shell to do those tasks. In MDA, it is important to understand what source codes have been created in src-generated and how you will use those created codes to fulfil your task. The Presentation Layer The presentation layer represents the view of the business logic. EJOSA Template urges the presentation layer to use only the specification directory and does not link directly to the business implementation directory, so it's possible to change the implementation of the business layer without changing the presentation code. Just like the business layer implementation, there are many options to implement the presentation layer, especially for the server side presentation layer that runs within a Web container. To build the presentation layer we need the following:
Frameworks and views have a many-to-many relationship (see Figure 3), so it's possible - with a little effort - to combine different views with different frameworks. Note: SourceForge's Wafer http://sourceforge.net/projects/wafer/ project sums up the view and framework techniques. ![]() Fig. 3: Relationships in Business and Presentation Techniques EJOSA Template uses two main techniques from Enhydra for the presentation layer: XMLC for the view and Enhydra Application Framework (EAF) for the framework. I chose Enhydra because of following advantages:
The presentation directory structure of EJOSA Template looks similar to the directory of the business implementation layer. EJOSA Template uses the resource directory to manage resources like HTML files, graphics, and text for multi-language support. The presentation layer supports Swing applications too. The build directory holds two directories - enhydra and common. Within the enhydra directory you can use the build-enhydra.xml Ant file to compile HTML and other XML derivatives into Java DOM files by using XMLC. The common directory also holds a build-jdepend.xml Ant file that can be used to show the dependencies of the presentation layer; you can verify whether the presentation layer only depends on the specification and not directly on any business layer implementation. Example: The PiggyBank example can be used to generate Enhydra Framework codes (in src-generated) from the modem, which can be used (by inheritance) just like the business layer implementation:
The presentation implementation layer has the same rules as the business implementation layer: inheritance, separation of src-generated files, and understanding what has been generated and what should be implemented. To see and test the PiggyBank Web application, point to http://localhost:9000/servlet in your Web browser. You can also build and deploy the specification, business and presentation as an application (one ear file) by executing the build file application/build/apply-all-build.xml. To run the Web application, execute application/bin/jonas/jonas-bin.xml and point your browser to the application context: http://localhost:9000/application. Figure 4 shows the PiggyBank application in action. ![]() Fig. 4: PiggyBank (in Linux and Eclipse) in Action Conclusion and Future Direction One aspect that hasn't been explained in detail is that EJOSA Template also supports J2EE beginners with unit tests, which are integrated with JUnit and JUnitDoclet. First, JUnitDoclet generates the skeletons of all unit tests for the business layer implementation. Then developers have to write the unit test code, which can be executed directly within JUnit. After finishing the component we have to load test to see whether the component will work in a production environment under high load. Figure 5 depicts the general process of building J2EE applications using the EJOSA Template. ![]() Fig. 5: Process Matrix Using EJOSA Template As a beginner in J2EE development you don't need to understand all the processes mentioned in Figure 5, in one go. You can put a beginner's perspective on the top of the EJOSA process and pick the important parts first. An example of a beginner's perspective would be Figure 6. In this perspective, you can directly implement the specification part by using the simplest possibility that consists of the EJB-dependent interfaces: EJBHome, EJBLocalHome, EJBObject, and EJBLocalObject. Later, you can implement the presentation, business and data layer consecutively. You can ignore all the other steps, to begin with. You can open new steps and parts as you wish to create new perspectives. This concept of having your own perspectives is actually what makes Eclipse very powerful. Adding an Eclipse plug-in which supports this multi-perspectivity concept within EJOSA Template would be very interesting, although not a must, since the most important thing is to understand the underlying concept. ![]() Fig. 6: Beginner's Perspective: Process Matrix Using EJOSA Template for Beginners The EJOSA Template can be of great use to J2EE beginners. A set of reusable build and execution Ant scripts, pre-configured Open Source external libraries, and standardization of the component directory structure and package naming structure (based on multi-tier architecture) simplify the development process. Using Ant for execution and build management allows us not only to be independent of the IDE (NetBeans, Eclipse, Linux shell and DOS prompt), but also allows us the possibility to execute everything automatically (automatic compile, build, run, test and deploy). Adding Open Source MDA on top of development slims the coding activity and makes the development process life cycle with J2EE more agile. The standardization of UML and J2EE is an advantage for OSS engineering. UML and J2EE application developers can leverage OSS without adding dependency to the product itself. As the model (XMI), Web container (presentation), EJB container (business) and database (data) container are standardized; they can be exchanged without us having to rewrite the whole application. This surely increases the acceptance of OSS. In addition, the Open Source products, which EJOSA Template uses, are suitable for production environments. For instance, the Learning Management System OpenUSS is an application implemented using EJOSA Template and presently it provides eLearning services for more than 17,000 users. Future plans include extending the EJOSA Template with some new programming techniques, like using AspectJ language in J2EE application development. Also, the existence of an Open Source MDA tool like MTL, which enables us to transform one source model to another target model (Model-to-Model transformation), will help in processing available, well-established reference models to serve our domain model needs. The next part in this JAX Magazine series will show precisely how to use the combination of Model to Model and Model to Code Transformation for building a simple J2EE application - using the familiar PiggyBank example - with the use of MTL and AndroMDA. Blasius Lofi Dewanto is a Professor Assistant at the Institute for Business Informatics and Controlling, at the University of Münster, Germany. Reach him via e-mail. References
1. Development
|
||
|