Some reader favorites:
EJB fundamentals and session beans
Create a scrollable virtual desktop in Swing
Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API
TEXTBOX: TEXTBOX_HEAD: Building a Java servlet framework using reflection: Read the whole series!
Many developers who have made the transition from CGI scripting to Java servlets have continued the CGI development style in Java, even though that style may not be the most efficient option available to them. Consider this example: programmers typically use servlets to interpret the input of a Web browser, determine an appropriate course of action, and then display results to the user. The process the servlet handles is thus fourfold: control, business logic, data access, and presentation. In the CGI framework, a single CGI script handled this entire process. Those who continue to program in a CGI style often create monolithic servlets to handle all four of these actions.
It doesn't need to be that way. This article will provide a tool which developers can use to create efficient, easy-to-maintain, server-side Java code.
Business logic: Executes business rules, like validation, in order to satisfy the request
Data logic: Provides access to any necessary databases, CORBA services, EJBs, or other back-office persistence mechanisms
Presentation logic: Displays the results to the client
This framework does not depend on the presence of Java servlets. All it needs is agreement among developers on the contracts among objects. Some developers should be responsible for the controller code, which can be servlets, CORBA or RMI servers, or Netscape Application Server AppLogics. The other development teams need not be bothered about the specific implementation of those controller components; they need only use the methods provided by the controller objects.
HttpservletRequest) or method is used by any noncontroller component. A segmented system can be completely self-contained. For example, the team developing the data components can work to make it satisfy the following interface (a simple case), or something similar:
public interface DataInterface
{
public void initializeDataObject();
public void beginTransaction();
public void commitTransaction();
public void rollbackTransaction();
public void executeSQL(String sqlString);
}
This is a simple interface for logging user actions or accepting user inputs to a database. Because all DataObjects must satisfy the DataInterface, it is possible for a single object to perform the duties associated with the database interaction. Again, no component outside
of the data functionality should have to deal with connection pooling or database parameters.
Similarly, it is possible to create objects to handle presentation-related issues using an interface similar to the following:
public interface PresentationInterface
{
public void initializePresentation(ProxyInterface proxy) throws IOException;
public void output(String text) throws IOException;
public void finalizePresentation() throws IOException;
}
Notice that this interface is implemented by any object responsible for presentation-related activities. Also notice the difference
between the two interfaces. The PresentationInterface lists a method with a parameter called PresentationService. The PresentationServicesInterface is the key to the framework, as it is the controller in the framework.
The implementor of the ProxyInterface is the single point of contact for all platform-dependent functionality. The Presentation object does not need to understand the details of implementing the presentation layer. Whether it is through applets, servlets,
or sockets, the methods of the interface must be satisfied.
The ProxyInterface shown below can obtain references for the other objects involved in the request-response pattern.
public interface ProxyInterface
{
public DataInterface getDataObject(String name);
public PresentationInterface getPresentationObject(String name);
public BusinessInterface getBusinessObject(String name);
}
Because this interface is quite generic, it may be used as a proxy for requests made to servlets or other server-side applications,
such as Netscape Application Server's AppLogics. The intention is to create a structure such that all the information specific
to the deployment platform is contained in the implementation of the ProxyInterface, or in a small subset of classes. This allows developers to write code independent of proprietary methods or variables, thereby
increasing the efficiency of the development team.
The last component of our expandable framework is the BusinessInterface:
public interface BusinessInterface
{
public void init(ProxyInterface proxy, Hashtable parameters) throws Exception;
}
An implementation of this interface is spawned for every request made to the framework. This interface contains a method through which the input parameters pass from the servlet to the business object. In addition, the proxy is passed to the business object in order to provide it with the tools necessary to perform its task.
We have created a framework through which we can launch business objects to perform the individual actions of the users -- including all data and presentation issues -- without any knowledge of the individual platform upon which they reside. Now, how do we know which business object to load?
Free Download - 5 Minute Product Review. When slow equals Off: Manage the complexity of Web applications - Symphoniq
![]()
Free Download - 5 Minute Product Review. Realize the benefits of real user monitoring in less than an hour. - Symphoniq