advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Is XDoclet Necessary?
Partners & Affiliates
advertisement
advertisement
Average Rating: 3.7/5 | Rate this item | 3 users have rated this item.
 Print Print
 
XDoclet Meets Eclipse: Code Generation Made Easy
In an earlier article, you learned how to use an Eclipse plugin that supports XDoclet to administer a JBoss application server. Now, take it to the next level: Learn how to use the XDoclet plugin to generate code via a simple servlet-driven, EJB-based example. 

 
advertisement
Doclet is a code generation engine that enables a concept known as Attribute-Oriented Programming. To use XDoclet, a programmer adds metadata (attributes) for classes and methods within the JavaDoc for their source. XDoclet can then scour your source files for these attributes and generates artifacts that are necessary for your application. XDoclet is executed from within Jakarta Ant, using a set of custom Ant tasks.


XDoclet can be used to generate files for Web applications, EJBs, Castor, Hibernate, JDO, Struts and a number of other tools.

In an earlier article, you learned about a plugin to the Eclipse environment that lets you configure and deploy to your JBoss application server. The same plugin will invoke the Xdoclet standard to let you automatically generate Java code for enterprise applications. (Please refer to the first article for instructions on how to install the plugin: http://www.devx.com/opensource/Article/20242.)

Author's Note: If you're running Eclipse 3.0 M7 release, the XDoclet portion of the plugin will not work. You must use Eclipse 3.0 M6 or earlier. See http://www.jboss.org/index.html?module=bb&op=viewtopic&t=46177.

XDoclet ships with modules for nearly all the leading Java application servers, including:

  • IBM WebSphere Application Server
  • JBoss
  • BEA WebLogic
  • Oracle IAS
  • Macromedia JRun
What are some of the benefits of code generation with XDoclet? Here are a few:
  • Minimizes the number of files that a developer has to maintain.
  • Reduced development time because developers write less code and maintain code in fewer places
  • Deployment files can be generated for multiple application servers, allowing for easier vendor independence
  • Developers can view deployment information in the source code, while the deployment team can still use the deployment descriptor
  • Metadata can be regenerated and integrated with the source code
  • (See more DevX articles and resources about code generation in the left column.)

    Big String, Small Code
    Stateless session EJBs are a great way of introducing a service layer into an application, but we all know how tedious it can be to generate five or six separate files just to implement an EJB with a single method. The wonderful thing about XDoclet is that the only file that you have to manually create is the EJB "bean" class. After providing attributes in the JavaDoc, XDoclet can generate all the interfaces and deployment descriptors necessary for the EJB to run in an application server.

    We wrote a stateless session EJB that does the extremely difficult task of (drum roll) capitalizing a string! We chose to invoke this EJB via a servlet so that we could showcase both the Web and EJB generation functionality provided by XDoclet. XDoclet will be used to generate a Web deployment descriptor, the EJB interfaces, and the EJB deployment descriptors.

    We will not cover the packaging features of the plugin in this article, but you can refer to the plugin's documentation for more details. (See http://heanet.dl.sourceforge.net/sourceforge/jboss/Tutorial-1.2.2.pdf. Editor's Note: If the preceding link fails to load the PDF, please copy and paste the URL into a new browser instance.) You should also download our source code, which includes the XDoclet configurations, the Packaging configurations, and all the files that XDoclet generates (see the download link in the left column).

    The two major classes you need to be concerned with are shown in listings 1 and 2. Listing 1 is the JavaDoc for the EJB, which has a method that capitalizes an incoming string. Listing 2 is the JavaDoc for the servlet, which simply performs a JNDI lookup of the EJB and makes a remote call to the EJB's capitalization method.

    For those familiar with EJBs, you will notice that the @ejb.bean tag contains information that is usually specified in the ejb-jar.xml file (i.e., our EJB deployment descriptor).

    Similar to our tag for our EJB, the XDoclet tags incorporated in the servlet help define the data that goes into the web.xml file, the Web deployment descriptor.

    Page 1 of 3


    advertisement
      Next Page: Webdoclet and Ejbdoclet
    Page 1: IntroductionPage 3: Where to Keep Your Generated Code
    Page 2: Webdoclet and Ejbdoclet 
    advertisement
    Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
    Microsoft Article: 7.0, Microsoft's Lucky Version?
    Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Windows Server 2008
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES