|
Comments
|
Today's Top SOA Links
Enterprise Shouldn't J2EE Be More Like Java? Building A Better Java Bean
The elegance of Java stems from how the language addresses a number of highly complex software engineering issues
By: Ken Kruszka
Jul. 31, 2005 07:30 PM
The elegance of Java stems from how the language addresses a number of highly complex software engineering issues in a seemingly consistent and easy-to-use paradigm. While there are a few potholes that you need to be mindful of, most caused by the differences between primitives and objects, the power and reach of standard Java are testaments to the principle of simplicity that is embodied within it. Unfortunately, when it comes to Java's enterprise platform, J2EE strays considerably from J2SE in a number of areas, creating unnecessary additional complexity and ambiguity. To make matters worse, J2EE 1.3 (EJB 2.0) introduced self-inconsistencies.
In the case of J2EE's most high-profile technology, Enterprise JavaBeans (EJBs), these digressions can be mitigated by extending and enhancing EJBs into what I'll term BetterEJBs (see the pullout at the end of this article). Just as application server deployment tools can transparently generate EJB stubs and skeletons, tools can likewise be developed to auto-generate the necessary artifacts that are derivable from the BetterBean. The benefit: a BetterEJB developer needs only implement a single class, cutting down on development time, complexity, and the potential for errors while increasing understandability through the consolidation of information in a single location. This article discusses a number of issues regarding the disparity between J2EE and J2SE, and spells out practical approaches and techniques that can be used to help return J2EE, specifically EJB, back to its Java roots. Additionally, this article illustrates the derivation of all supporting artifacts from the BetterBean, suggesting toolable functionality that could be realized to auto-generate the boilerplate constituent parts of the BetterEJB.
Structural Deviations Given the distributed nature of EJB deployment, which is realized through application server-generated Stubs and Skeletons, it's reasonable for enterprise-grade functionality to require a client-facing interface in addition to the bean class. But, the necessity of any additional artifacts is overly complex and error prone.
Declarative Programming Gone Awry The following code illustrates how the designation of a BetterEJB as stateless or stateful is accomplished through the use of a marker interface in the definition of the BetterBean class, BetterBeanA:
Because BetterBeanA implements the StatelessBetterBean marker interface, the derived deployment descriptor is for a <session> bean with <session-type> of Stateless, as shown in the following snippet:
The benefit of using marker interfaces is that it becomes possible to do build/compile-time checks on BetterBeanA, which can help eliminate the possibility of difficult-to-find runtime bugs or cryptic deployment-time errors.
Unnecessary Multitude of Interfaces But, is it not possble for a single interface to perform both functions? Such a combination is achieved by the BetterInterface, as is shown by the interface for BetterBeanA, BetterInterfaceA:
In addition to providing client-side signatures for all the methods implemented by BetterBeanA, this interface holds references for both remote EJB lookup and local EJB lookup. Passing these references to a lookup utility function (described later in this article) allows for retrieving either reference. In this way, only one interface is needed for both the lookup of and interaction with a BetterEJB. Reader Feedback: Page 1 of 1
Your Feedback
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||||||||