Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Power of XDoclet Darren Landoll CIS 764 - Database System Design Kansas State University.

Similar presentations


Presentation on theme: "The Power of XDoclet Darren Landoll CIS 764 - Database System Design Kansas State University."— Presentation transcript:

1 The Power of XDoclet http://xdoclet.sourceforge.net Darren Landoll CIS 764 - Database System Design Kansas State University

2 12/05/04Darren Landoll, CIS 7642 Overview Introduction Benefits XDoclet and Ant EJB Generation Web Generation Extending XDoclet DBills Example

3 12/05/04Darren Landoll, CIS 7643 Introduction - What is XDoclet? Code generation tool Metadata added to source code (JavaDoc) Parses source code like JavaDoc

4 12/05/04Darren Landoll, CIS 7644 Introduction - Concepts Write one Java class for each major component Save time by using XDoclet to generate redundant code XDoclet’s extensibility – add custom modules

5 12/05/04Darren Landoll, CIS 7645 Benefits Reduce redundant work J2EE made easy Support for leading servers and tools Extensible Open, distributed development *Listed on XDoclet’s home page [1]

6 12/05/04Darren Landoll, CIS 7646 XDoclet and Ant Ant task invokes XDoclet XDoclet tags in build.xml http://ant.apache.org … <ejbdoclet destdir="${samples.gen-src.dir}" mergedir="parent-fake-to-debug" excludedtags="@version,@author,@todo" addedtags="@xdoclet-generated at ${TODAY},@copyright The XDoclet Team,@author XDoclet,@version ${version}" ejbspec="2.0" force="${samples.xdoclet.force}" verbose="false" > …

7 12/05/04Darren Landoll, CIS 7647 EJB Generation ejbdoclet task Generates remote and/or local interfaces Generate value objects Generate BMP and/or CMP beans Generate XML descriptor files EJB example later in this presentation

8 12/05/04Darren Landoll, CIS 7648 Web Generation webdoclet task Servlet info Authentication info Page mappings

9 12/05/04Darren Landoll, CIS 7649 Web Example [3] The servlet mappings can also be defined with the XDoclet JavaDoc tags as follows: * @web.servlet-mapping url-pattern="/Basic/*" * @web.servlet-mapping url-pattern="*.Basic" * @web.servlet-mapping url-pattern="/BasicServlet"... */ public class BasicServlet extends HttpServlet { These would generate the following entries in the web.xml file: BasicServlet /Basic/* BasicServlet *.Basic BasicServlet /BasicServlet

10 12/05/04Darren Landoll, CIS 76410 Extending XDoclet Non-J2EE Example: Command line arguments Create XDoclet template to generate argument handling code See: http://www.cais.ntu.edu.sg/~liuzh/xdoclet_tutorial/

11 12/05/04Darren Landoll, CIS 76411 Extending XDoclet, Cont. public class CLArguments {... /** * @clarguments.argname longname="inputurl" shortname="u" shortdesc="input_url“ */ protected String inputURL = null; /** * @clarguments.argname * longname="outputtype" * shortname="o“ * shortdesc="output_type“ */ protected String outputType = null;... }

12 12/05/04Darren Landoll, CIS 76412 DBills Example Simple EJB for a bill management system Ant build.xml Directory/File structure EJB annotated with XDoclet tags Generated files

13 12/05/04Darren Landoll, CIS 76413 DBills build.xml <taskdef name="ejbdoclet" classname="xdoclet.modules.ejb.EjbDocletTask" classpathref="base.path" /> <ejbdoclet destdir="${build.generate.dir}" excludedtags="@version,@author" ejbspec="${ejb.version}" mergedir="${src.resources.dir}/xdoclet" force="${xdoclet.force}" >

14 12/05/04Darren Landoll, CIS 76414 DBills build.xml, cont. <jboss version="3.0" xmlencoding="UTF-8" typemapping="mySQL" datasource="java:/BigDDS" destdir="${build.dir}/META-INF" validateXml="false" />

15 12/05/04Darren Landoll, CIS 76415 DBills Directory/File Structure build –classes (compiled Java classes) –generate (generated source files by XDoclet) –META-INF (generated descriptor files) ejb-jar.xml jbosscmp-jdbc.xml jboss.xml src –etc WEB-INF (static web descriptor files) –main ejb (EJB source files) servlet (Servlet source files) –web (JSP files)

16 12/05/04Darren Landoll, CIS 76416 DBills EJB Source Code Class header /** * BillAcctBean represents an account you have with a company * * @ejb.bean name="BillAcct" * local-jndi-name="ejb/BillAcctBean" * type="CMP" * view-type="local" * schema="billAcctSchema" * cmp-version="2.x" * * @ejb.pk class="java.lang.Object" * @ejb.persistence * table-name="bill_acct" * * @ejb.finder * query="SELECT OBJECT(a) FROM billAcctSchema as a" * signature="java.util.Collection findAll()" * * @ejb.value-object * name="BillAcct" * match="*" * extends="dbills.interfaces.AbstractValue“ **/ public abstract class BillAcctBean implements EntityBean

17 12/05/04Darren Landoll, CIS 76417 DBills EJB Source Code Method headers for each field in the table /** * Returns the billAcctDesc * @return the billAcctDesc * * @ejb.persistent-field * @ejb.persistence * column-name="bill_acct_desc" * sql-type="VARCHAR" * * @ejb.interface-method */ public abstract java.lang.String getBillAcctDesc(); /** * Sets the billAcctDesc * * @param java.lang.String the new billAcctDesc value * * @ejb.interface-method */ public abstract void setBillAcctDesc(java.lang.String billAcctDesc);

18 12/05/04Darren Landoll, CIS 76418 DBills Generated Files BillAcctBean –BillAcctCMP (complete CMP entity bean) –BillAcctLocalHome (interface) –BillAcctLocal (interface) –BillAcctValue (value object) Descriptor Files –ejb-jar.xml –jbosscmp-jdbc.xml –jboss.xml

19 12/05/04Darren Landoll, CIS 76419 Review Benefits Integration with Ant EJB Generation Web Generation DBills Example

20 12/05/04Darren Landoll, CIS 76420 References [1] XDoclet home page http://xdoclet.sourceforge.net/xdoclet/index.html [2]Continuous Integration, Martin Fowler http://www.martinfowler.com/articles/continuousIntegration.html [3] Enhance J2EE component reuse with XDoclet,, IBM Developerworks http://www.arc-mind.com/downloads_protected/tutorials/xdoclet/ws-j2x-ltr.pdf [4] XDoclet Tutorial: A Short Tutorial on XDoclet Templates, Liu Zehua http://www.cais.ntu.edu.sg/~liuzh/xdoclet_tutorial/ [5] Use XDoclet to generate web service support files, IBM Developerworks http://www.arc-mind.com/downloads_protected/tutorials/xdoclet/xdoclet2.pdf


Download ppt "The Power of XDoclet Darren Landoll CIS 764 - Database System Design Kansas State University."

Similar presentations


Ads by Google