Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

Search: 

  Tutorial: Frameworks save the day - JavaWorld September 2000

Frameworks save the day - JavaWorld September 2000

Tutorial Details:

Frameworks save the day
Frameworks save the day
By: By Humphrey Sheil
Use an extensible, vendor-independent framework to accomplish the top tasks in server-side development
n server-side development, a number of core tasks crop up over and over again. Most developers know that such tasks can and should be pulled into a core framework, built and tested once, and reused across multiple projects. However, knowing something and doing it are two different things.
The framework concept has been kicking around in software development for a long time in one form or another. In its simplest form, a framework is simply a body of tried and tested code that is reused in multiple software development projects. Smart companies invest formally in frameworks and good developers build up a library of components that they use often. Such actions reduce development time while improving delivered software quality -- which means that developers can spend more time concentrating on the business-specific problem at hand rather than on the plumbing code behind it. A good framework also enhances the maintainability of software through API consistency, comprehensive documentation, and thorough testing.
At one level, the framework showcased in this article does the simple things you need every day: logging, exception handling, JNDI lookup, configuration, and database management. Delving deeper into the design and implementation however, you will see that the framework also provides application server independence, future hooks for adding management services, and a well-defined extension mechanism.
Note: To download the framework's complete source code in zip format, go to the Resources section below.
Goals for the framework
Before setting out to build the framework, it's worthwhile to set out some basic objectives against which we can measure success:
The framework should be simple. The number of objects should be minimal, with simple methods and shallow inheritance hierarchies. Furthermore, the API must be consistent across different framework modules to minimize the ramp-up time required to start effectively using the framework.
A developer should be able to add new services to the framework easily. You can be sure that your framework will grow over time, becoming a balkanized hodge-podge reflecting the designers' and developers' personal coding styles. If from the start you lay down a well-defined extension mechanism that is powerful enough to meet the needs of your framework providers, you've laid a sound base on which to build and extend the framework over time.
The framework should have solid documentation. This may sound obvious, but it rarely happens in practice. At the very least, users will expect a good level of javadoc commenting and an overall block diagram outlining the major components in the system, along with sample code showing how the components can be used.
The framework should be usable from any J2EE component. This includes EJBs, servlets, JMS listeners, and regular Java classes. Accomplishing this is not difficult, but it needs to be kept in mind during development.
Developers should be able to deploy the framework to multiple application servers. A really useful framework will offer developers the same level of functionality no matter what application server they work on. For example, if a vendor claims that its environment is EJB 1.1 compliant, then I expect certain things to be present in that environment. In the same way, if a framework is available on application server X, then it should be fully functional on that server, no ifs or buts. Above all, this complexity should be hidden from the end user wherever possible.
Framework assumptions
In order to make our framework easier to maintain, some assumptions are made:
Supported databases: The only component that uses a database directly is the DbConnectionService . Any database that has a JDBC driver will work.
Supported JDK versions: 1.2.2 or higher. JDK 1.1.x is explicitly not supported. JDK 1.3-specific APIs are not used, as the 1.3 JDK has still not gained widespread acceptance as a production VM.
Target application servers: BEA WebLogic 5.1 and jBoss. This point is not so much a restriction, more a declaration of what comes working (and tested) out of the box. There is no reason why the framework couldn't be extended to other application servers as required (in fact, it is designed in such a way to make this as clear and easy as possible).
Vendor-specific functionality: Vendor-specific functionality would clash with the stated goal of providing a vendor-independent framework. Though in some cases vendors have added proprietary extensions to their product that would enhance performance or flexibility, such extensions have been eschewed here in favor of complete vendor independence.
The framework's five basic components
Next, we look at the five core components -- logging, JNDILookup, configuration, database connection management, and exception handling -- that make up the framework. These are the hosted services that can be leveraged by business-specific code, as seen in Figure 1.
Figure 1. The current framework consists of five components.
The logging service serves a core function
in that the other services depend on its existence.
Logging
Logging represents the framework's single most important component. Apart from the value it adds to users, it is crucial to debugging the framework itself. Put simply, a system without a logging component and an accompanying set of logging guidelines built into the coding standards will take a long time to develop (and debug) and will be very difficult to maintain.
So what are the requirements for logging?
Simplicity: A logging component must be simple to use, or developers won't use it. Instead, they'll use System.out.println , thus impairing performance. With that in mind, only one import statement and one line should be necessary to use the logging service, no more.
Flexible output formatting: Systems regularly go live without any reporting features built in. It typically isn't critical to the main system functionality to have things like usage patterns, audit trails, and so on reported; such features are thus instead penciled in for phase two or even phase three releases. Though you may not think you need this functionality now, wouldn't it would help a lot if your plain old logging module could handle it already? Most third-party reporting tools can read your output logs as long as they are structured -- the logging service should be able to handle this in a configurable way.
Support for output to different channels: In development, piping output to stdout as well as a file is helpful; in production, this should be turned off to improve performance.
The design and construction of a logging service could take up a complete article in itself. Instead of spending time building one, I have picked one off the shelf that I consider to be best of the breed: log4j (see Resources for more details). Although most vendors (including jBoss and WebLogic) provide a logging service as part of their products, their services aren't used here because they would affect the cross-platform portability of the framework.
In the framework lifecycle, two incarnations of the LogService exist. Initially, the FrameworkManager and the logging service itself use the BootLogger , as neither component can assume that the fully-fledged logging service has been located and bootstrapped. Once the main logging service has been initialized, the other framework components use it in preference to the BootLogger , which possesses a subset of the main service's functionality.
Finding objects/references stored on a JNDI tree
Next, let's look at the JNDILookup component. JNDI trees serve as the telephone directories of the enterprise Java world. Looking for that hot new bean in town or the latest connection pool? You will find them in the JNDI environment as named and configured by the application assembler/deployer. The framework provides a window into this world that hides the vendor- and location-specific details from developers when they don't need to or want to be aware of them. This service also serves as an example of how to use the framework's ability to detect the current application server to configure a client service appropriately. See the JNDIService javadoc for more details on this functionality.
Using a configuration lookup to avoid hardcoding variables
Our third component is the configuration lookup. Although EJBs can use the java:comp/env JNDI context to store information that should live outside the codebase, this is not so easy to do for non-EJB components. With the ConfigService , all J2EE components can retrieve values from a central file-based repository. Thus, you won't have to hardwire these values or use J2EE component-specific mechanisms.
Database connection pooling
We next turn our attention to the framework's fourth component, the database connection manager. Databases are a commodity in the enterprise Java world. Most of the time, developers don't need or want to know where a database is; they simply want a connection to talk to it. As the relational world becomes more in tune with the object world, eventually a service like this will filter completely behind the scenes; knowing that your objects are persisted to a database would be like knowing where a spool file for email lives on a server -- you don't care, you just want to use email. Until that happy day, however, we need a database-connection finder service.
Exception handling
A consistent exception handling strategy is a core requirement for any distributed system. Put simply, each framework components should be honest in all its dealings. In other words, if I ask the JNDILookup to find a bean for me, I don't want to get a null reference in return! In a better world, the framework would either return a valid object or explicitly in


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Frameworks save the day - JavaWorld September 2000

View Tutorial:
Frameworks save the day - JavaWorld September 2000

Related Tutorials:

Displaying 1 - 50 of about 745 Related Tutorials.

Find the Day of the Week
Find Day of Week,Determine Day of Week in Java,Example to Find the Day of Week Find the Day of the Week  ...; This example finds the specified date of  an year and a day of a week from calendar
 
Open Source Frameworks
Open Source Frameworks Open Source Frameworks Open Source Web Frameworks in Java The core of the Struts framework... enterprise with open source frameworks Any software developer worth
 
Find Day of Month
Find Day of Month,Java Code to Find Day of Month,Example to Determine Day of Month Find Day of Month   ... explores how to find the day of a month and the day of a week 
 
Day Format Example
Day Format Example Day Format Example...;  This example shows how to format day using Format class. In this program we use a pattern of special characters to day format. Description
 
Ajax Frameworks Types
Ajax Frameworks Types Ajax Frameworks Types...; There are two types of Ajax based frameworks used in the web... framework programming. Nearby all the frameworks in server-side accepts
 
Determining the Day-of-Week for a Particular Date
Determining the Day-of-Week for a Particular Date Determining the Day-of-Week for a Particular Date   ... simply show the current day in word i.e. the Day of Week for a particular date
 
Java get Next Day
Java get Next Day Java get Next Day...; In this section, you will study how to get the next day in java using... the string of days of week. To get the current day, we have used the Calendar
 
URL file Download and Save in the Local Directory
URL file Download and Save in the Local Directory URL file Download and Save in the Local Directory   ... file download  from  URL and save this Url File in the specified
 
Get Last Day of The Month
Get Last Day of The Month Get Last Day of The Month... and a set of integer fields such as YEAR, MONTH, DAY, HOUR.. A Date object ... to describe you a code that helps you in getting the last day of the month. For this we
 
Save Any Eclipse Editor as HTML
Save Any Eclipse Editor as HTML Save Any Eclipse...;      Often I have wanted to save Java.... The HTML is stored in a file and also in the clipboard. You can cancel the save file
 
Task Scheduling in JAVA
after one day and make reports according to the entries then save all entries
 
Get first day of week
Get First Day of Week,Java First Day of Week Example,Getting First Day of Week in Java Get first day of week...; In this section, we will learn how to get the first day of  week in Java
 
Open Source Web Frameworks in Java
Open Source Web Frameworks in Java Open Source Web Frameworks in Java Struts Struts Frame work... frameworks) have brought the separation between View and Model and Controler
 
Struts Frameworks
Struts Frameworks Struts Frameworks The StrutsLive Framework The StrutsLive framework builds upon several ideas introduced in the book Struts Live. One of the primary building blocks is a set
 
Struts Frameworks
Struts Frameworks Struts Frameworks The StrutsLive Framework The StrutsLive framework builds upon several ideas introduced in the book Struts Live. One of the primary building blocks is a set
 
Struts File Upload and Save
Struts File Upload and Save Struts File Upload and Save        ... illustrating how to  save the file on the server . Now, the current example
 
Create and Save Excel File in JSP
Create Excel File in JSP,How to Create and Save Excel Spreadsheet File in JSP Create and Save Excel File in JSP             
 
Learn Java in a day
Learn Java in a Day Learn Java in a day                         
 
Softabar Password Manager
generation helps you in your day to day tasks. Optionally accounts and passwords can...: Windows 2000 or XP for Windows installer. Java 5.0. Linux, Apple Mac OS X
 
Jupe
and reverse engineering. The plugin is based on the GEF and UML2 frameworks... of UML diagrams based on the source code (reverse engineering) load and save
 
Getting Previous, Current and Next Day Date
Get previous Day Date,Jav Next Day Date,Getting Previous and Next Day Date in Java Getting Previous, Current and Next Day Date...; subtract a day in MILLIS_IN_DAY and add a day for getting the next date.  
 
Struts Alternative
the frameworks that can be used as an alternative to the struts framework... the first few lines of code were committed to the Struts CVS repository in June 2000
 
Sql Date and Time Functions
;   The Tutorial illustrate a function to extract the day of week, name of month, name of day, day of year, number of week. Understand... Functions'. Query (DAYOFWEEK) :-Here is the query for extracting the day of week
 
Open Source Aspect-Oriented Frameworks written in Java

 
Open Source Web Frameworks written in Java

 
Open Source Aspect-Oriented Frameworks written in Java

 
Open Source Aspect-Oriented Frameworks written in Java

 
JFreeChart - An Introduction
java chart library. David Gilbert founded the JFreeChart project in February 2000
 
How many hours a day/a week do you work?
How many hours a day/a week do you work? How many hours a day/a week do you work?                  
 
Damn Small Linux 2.3 RC1 has been released now
Small Linux 2.3 RC1 has been released now New check and prompt to save APSFILTER printer setup; new check and prompt to save wireless setup; new MyDSL is now.../HTTPD server right off of a live CD. In our quest to save space and have a fully
 
Avoid Internet Theft, Fraud and Phishing
. Online services such as Internet banking save time and money. However, from... three different lotteries every single day, but if you get in contact
 
Test Performance Tools Platform (TPTP) Training
over the powerful frameworks and services for an open platform i.e. TPTP. TPTP
 
Hibernate Quickly
Hibernate Quickly,Hibernate Quick Start,Hibernate QuickStart,Hibernate Quick Reference,Hibernate Reference Hibernate Quickly In this fast changing programming world, each day new technologies are coming
 
Features of Servlet 2.5
; This version has been released on September 26, 2005 by the Sun MicroSystems
 
Insert Image into Mysql Database through Simple Java Code
; This is detailed simple java code that how save image into mysql database. Before running this java code you need to create data base and table to save image...' and table 'save_image'. Structure of table 'save_image' First create database
 
Open Source Ajax
- The Open Source Ajax frameworks for developing cutting edge web 2.0 applications to satisfy your clients. There are many Open Source Ajax frameworks available... websites. The Open Source Ajax Frameworks has given the ability to develop rich
 
Struts 2, JPA and Hibernate Training
and Hibernate in a combined 5 day online course that makes you expert... them understand the latest technologies like Struts2, JPA and Hibernate. Day 1... in hibernate Day 2 Course JPA Introduction to JPA JPA Basics
 
Dojo Inline Edit Box
provides the better facility for editing any data and save it.  Try Online... then it open as an editable mode. In this mode, you edit the text and save it. Whenever you don't save the editable text then it can't be save so, after editing
 
Database books Page12
to prepare for and run an installation on a Windows NT, Windows 2000, Solaris, AIX
 
Button Pressing Example
;   f.add(b = new Button("Good Day"), ...;java ButtonPressDemo Good Morning clicked Good Day clicked
 
More About the CronTrigger
and that is separated by the white-space. : Seconds Minutes Hours Day-of-Month Month Day-of-Week Example: The Cron-expression string is "0 ...;Month" field that means "every month" and "Day-Of-Week"
 
JFileChooser
to create file choosers for selecting files or directories to open or save... = fc.showSaveDialog(owner); // button labeled "Save" r = fc.showDialog(owner
 
Eclipse Plugin- Editor
and navigation tools to save time and maximize control over code. Context Tagging...;      htmlSave-Editor Often I have wanted to save... a simple action o?n the file menu to save the active text editor as HTML.  
 
Simplified Application Development with Struts, Hibernate and Spring
by combining all the three mentioned frameworks e.g. Struts, Hibernate and Spring... process by using all the above-mentioned frameworks. It also describes different
 
Jdbc batch update
is used when you want to  save all the modify or changes  values
 
SWT
the java.util.Calendar class. The class CLabel allows to write the day and the days of week.... We are using this class to write the day and the days of week.  
 
How JSF Fits For Web Applications?
many  advantages over other existing frameworks that makes it a better
 
SlickEdit
_boxshotand navigation tools to save time and maximize control over code. Context
 
Week Days Format Example
day. Description of the code : SimpleDateFormat() : SimpleDateFormat class use
 
Year Format Example
. In this program we use a pattern of special characters to format week day
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.