The Power of XDoclet http xdoclet sourceforge net

  • Slides: 20
Download presentation
The Power of XDoclet http: //xdoclet. sourceforge. net Darren Landoll CIS 764 - Database

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

Overview • • Introduction Benefits XDoclet and Ant EJB Generation Web Generation Extending XDoclet

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

Introduction - What is XDoclet? • Code generation tool • Metadata added to source

Introduction - What is XDoclet? • Code generation tool • Metadata added to source code (Java. Doc) • Parses source code like Java. Doc 12/05/04 Darren Landoll, CIS 764 3

Introduction - Concepts • Write one Java class for each major component • Save

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 12/05/04 Darren Landoll, CIS 764 4

Benefits • • • Reduce redundant work J 2 EE made easy Support for

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

XDoclet and Ant • Ant task invokes XDoclet • XDoclet tags in build. xml

XDoclet and Ant • Ant task invokes XDoclet • XDoclet tags in build. xml • http: //ant. apache. org … <target name="ejbdoclet" depends="prepare"> <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" > … 12/05/04 Darren Landoll, CIS 764 6

EJB Generation • • • ejbdoclet task Generates remote and/or local interfaces Generate value

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 12/05/04 Darren Landoll, CIS 764 7

Web Generation • • webdoclet task Servlet info Authentication info Page mappings 12/05/04 Darren

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

Web Example [3] The servlet mappings can also be defined with the XDoclet Java.

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

Extending XDoclet • Non-J 2 EE Example: Command line arguments • Create XDoclet template

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

Extending XDoclet, Cont. public class CLArguments {. . . /** * @clarguments. argname longname="inputurl"

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

DBills Example • • • Simple EJB for a bill management system Ant build.

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

DBills build. xml <target name="xdoclet-generate" depends="init"> <taskdef name="ejbdoclet" classname="xdoclet. modules. ejb. Ejb. Doclet. Task"

DBills build. xml <target name="xdoclet-generate" depends="init"> <taskdef name="ejbdoclet" classname="xdoclet. modules. ejb. Ejb. Doclet. Task" classpathref="base. path" /> <ejbdoclet destdir="${build. generate. dir}" excludedtags="@version, @author" ejbspec="${ejb. version}" mergedir="${src. resources. dir}/xdoclet" force="${xdoclet. force}" > <fileset dir="${src. ejb. dir}"> <include name="**/*Bean. java"/> </fileset> 12/05/04 Darren Landoll, CIS 764 13

DBills build. xml, cont. <package. Substitution packages="session, entity" substitute. With="interfaces"/> <valueobject/> <remoteinterface/> <localinterface/> <homeinterface/>

DBills build. xml, cont. <package. Substitution packages="session, entity" substitute. With="interfaces"/> <valueobject/> <remoteinterface/> <localinterface/> <homeinterface/> <localhomeinterface/> <entitybmp/> <entitycmp/> <session/> <deploymentdescriptor destdir="${build. dir}/META-INF"/> <jboss version="3. 0" xmlencoding="UTF-8" typemapping="my. SQL" datasource="java: /Big. DDS" destdir="${build. dir}/META-INF" validate. Xml="false" /> </ejbdoclet> </target> 12/05/04 Darren Landoll, CIS 764 14

DBills Directory/File Structure • build – classes (compiled Java classes) – generate (generated source

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) 12/05/04 Darren Landoll, CIS 764 15

DBills EJB Source Code Class header /** * Bill. Acct. Bean represents an account

DBills EJB Source Code Class header /** * Bill. Acct. Bean represents an account you have with a company * * @ejb. bean name="Bill. Acct" * local-jndi-name="ejb/Bill. Acct. Bean" * type="CMP" * view-type="local" * schema="bill. Acct. Schema" * cmp-version="2. x" * * @ejb. pk class="java. lang. Object" * @ejb. persistence * table-name="bill_acct" * * @ejb. finder * query="SELECT OBJECT(a) FROM bill. Acct. Schema as a" * signature="java. util. Collection find. All()" * * @ejb. value-object * name="Bill. Acct" * match="*" * extends="dbills. interfaces. Abstract. Value“ **/ public abstract class Bill. Acct. Bean implements Entity. Bean 12/05/04 Darren Landoll, CIS 764 16

DBills EJB Source Code Method headers for each field in the table /** *

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

DBills Generated Files • Bill. Acct. Bean – – Bill. Acct. CMP (complete CMP

DBills Generated Files • Bill. Acct. Bean – – Bill. Acct. CMP (complete CMP entity bean) Bill. Acct. Local. Home (interface) Bill. Acct. Local (interface) Bill. Acct. Value (value object) • Descriptor Files – ejb-jar. xml – jbosscmp-jdbc. xml – jboss. xml 12/05/04 Darren Landoll, CIS 764 18

Review • • • Benefits Integration with Ant EJB Generation Web Generation DBills Example

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

References [1] XDoclet home page http: //xdoclet. sourceforge. net/xdoclet/index. html [2]Continuous Integration, Martin Fowler

References [1] XDoclet home page http: //xdoclet. sourceforge. net/xdoclet/index. html [2]Continuous Integration, Martin Fowler http: //www. martinfowler. com/articles/continuous. Integration. html [3] Enhance J 2 EE component reuse with XDoclet, , IBM Developerworks http: //www. arc-mind. com/downloads_protected/tutorials/xdoclet/ws-j 2 x-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 2. pdf 12/05/04 Darren Landoll, CIS 764 20