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
advertisement
Average Rating: 3.7/5 | Rate this item | 3 users have rated this item.
Email this articleEmail this article
 
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.

      Next Page: Webdoclet and Ejbdoclet


    Page 1: IntroductionPage 3: Where to Keep Your Generated Code
    Page 2: Webdoclet and Ejbdoclet 
    Untitled
    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
    Intel PDF: Virtualization Delivers Data Center Efficiency
    Intel eBook: Managing the Evolving Data Center
    Microsoft Article: BitLocker Brings Encryption to Windows Server 2008
    Symantec eBook: The Guide to E-Mail Archiving and Management
    Microsoft Article: RODCs Transform Branch Office Security
    Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
    Avaya Article: Advancing the State of the Art in Customer Service
    Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
    Avaya Article: Avaya AE Services Provide Rapid Telephony Integration with Facebook
    Go Parallel Article: Getting Started with TBB on Windows
    HP eBook: Storage Networking , Part 1
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Seminar: Efficiencies in Hardware/Software Virtualization
    HP Webcast: Disaster Recovery Planning
    Go Parallel Video: Performance and Threading Tools for Game Developers
    HP Video: StorageWorks EVA4400 and Oracle
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    IBM TCO eKIT: Your IT Budget is Under Attack, Get in Control
    IBM Energy Efficiency eKIT: Learn How to Reduce Costs
    30-Day Trial: SPAMfighter Exchange Module
    Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    Microsoft Article: Silverlight Streaming--Free Video Hosting for All
    Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
    HP Demo: StorageWorks EVA4400
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES