Notes
Slide Show
Outline
1
xDoclet – Overview
By - Al Wick
  • Attribute Oriented Programming
2
Overview
  • What is xDoclet
  • How to Use
3
What is xDoclet
  • Attribute Oriented Programming
    • Allows you to add meta-data to your attributes
  • Uses JavaDoc extensions to define how your methods are going to be used
  • Does code generation for a variety of platforms ( EJB, Servlets, descriptor files, etc )
  • Extensible
  • http://xdoclet.sourceforge.net
4
Advantages
  • You don’t need to handle building/maintaining descriptor files
  • The developer only has to work with one Java source file instead of many
  • Reduction of development time because of the first 2 points
5
Using xDoclet
  • How to use in your code
    • EJBs
    • Web Applications
  • Generation via Ant
6
Example Overview
7
Session Bean Class Tags
8
Generated Mapping
  • <!-- Session Beans -->
  • <session >
  •       <description><![CDATA[Stateless Contact Server example bean]]></description>


  •        <ejb-name>ContactServer</ejb-name>


  •        <home>com.wickidcool.contacts.server.ContactServerHome</home>
  •        <remote>com.wickidcool.contacts.server.ContactServer</remote>
  •        <local-home>com.wickidcool.contacts.server.ContactServerLocalHome</local-home>
  •        <local>com.wickidcool.contacts.server.ContactServerLocal</local>
  •        <ejb-class>com.wickidcool.contacts.server.ContactServerSession</ejb-class>
  •        <session-type>Stateless</session-type>
  •        <transaction-type>Container</transaction-type>
  • </session>


9
Method tags
  •  /**
  •   * Create a new contact.
  •   *
  •   * @ejb.interface-method view-type="remote"
  •   */
  • public ContactVO createInstance() throws RemoteException {


  • // Some Code in here


  • }
10
Generated Classes
  • ContactServerHome
  • ContactServer
  • ContactServerLocalHome
  • ContactServerLocal
  • ContactServerSession
    • Subclasses your EJB class
11
Adding References
  •  *
  •  * @ejb.ejb-ref      ejb-name="User"
  •  *                   ref-name="ejb/UserLocal"
  •  *                   view-type="local"
  •  *
  •  * @ejb.ejb-ref      ejb-name="Contact"
  •  *                   ref-name="ejb/ContactLocal"
  •  *                   view-type="local"
12
Generated Mappings
  •      <ejb-local-ref >
  •             <ejb-ref-name>ejb/UserLocal</ejb-ref-name>
  •             <ejb-ref-type>Entity</ejb-ref-type>
  •             <local-home>com.wickidcool.contacts.server.UserLocalHome</local-home>
  •             <local>com.wickidcool.contacts.server.UserLocal</local>
  •             <ejb-link>User</ejb-link>
  •          </ejb-local-ref>
  •          <ejb-local-ref >
  •             <ejb-ref-name>ejb/ContactLocal</ejb-ref-name>
  •             <ejb-ref-type>Entity</ejb-ref-type>
  •             <local-home>com.wickidcool.contacts.server.ContactLocalHome</local-home>
  •             <local>com.wickidcool.contacts.server.ContactLocal</local>
  •             <ejb-link>Contact</ejb-link>
  •     </ejb-local-ref>
13
Servlet Tags
  • /**
  •  * Servlet for handling deletion of contact.
  •  *
  •  *  @web.servlet
  •  *     display-name="Delete Contact Servlet"
  •  *     name="deleteContact"
  •  *
  •  * @web.servlet-mapping
  •  *     url-pattern="/deleteContact/*"
  •  *
  •  * @author alwick
  •  */
14
Generating the Output
  • Done Using Ant
  • Uses xDoclet properties and libraries
  • Define classpath
  • Define the tasks (init)
  • Execute ejbdoclet against your code to generate Home/Remote interfaces and the deployment descriptor
  • Execute webdoclet to build web descriptor file
  • Compile the generated code with your source code
  • Refresh Eclipse project
15
Installing xDoclet
  • Go to http://xdoclet.sf.net
  • Download latest version (1.0.2b3)
  • Unzip into c:\java\xdoclet directory



16
Demo
  • Go through Source Code . You can download the code from here.
  • View the Ant Script and analyze the target/tasks
  • Execute Ant build script
  • View output
    • Generated Source code
      • Util class
      • Local and Remote framework
    • EJB descriptor files
    • Web descriptor file