You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ag...@apache.org on 2005/07/22 21:21:52 UTC
svn commit: r224387 - in /incubator/roller/trunk: build.xml
metadata/xdoclet/pojo_wrapper.xdt
Author: agilliland
Date: Fri Jul 22 12:21:48 2005
New Revision: 224387
URL: http://svn.apache.org/viewcvs?rev=224387&view=rev
Log:
new xdoclet template for creating pojo wrapper classes and a new ant target for generating the wrappers.
Added:
incubator/roller/trunk/metadata/xdoclet/pojo_wrapper.xdt
Modified:
incubator/roller/trunk/build.xml
Modified: incubator/roller/trunk/build.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/build.xml?rev=224387&r1=224386&r2=224387&view=diff
==============================================================================
--- incubator/roller/trunk/build.xml (original)
+++ incubator/roller/trunk/build.xml Fri Jul 22 12:21:48 2005
@@ -57,7 +57,7 @@
<!-- XDoclet code generation -->
<!-- ********************************************************************* -->
-<target name="generate" depends="gen-forms,gen-hibernate,gen-web" >
+<target name="generate" depends="gen-forms,gen-hibernate,gen-web,gen-wrappers" >
</target>
<!-- ============================================== -->
@@ -195,6 +195,46 @@
</target>
+<!-- ============================================== -->
+<!-- Generate pojo wrappers -->
+<target name="gen-wrappers" description="XDoclet generate pojo wrappers">
+
+ <!-- Define the XDoclet task -->
+ <taskdef name="xdoclet" classname="xdoclet.DocletTask"
+ classpathref="xdoclet.path" />
+
+ <xdoclet destdir="${build.generated}/src.business">
+
+ <packageSubstitution packages="pojos" substituteWith="pojos.wrapper"/>
+
+ <fileset dir="./src">
+ <!--
+ it may be easier to glob using *Data.java at some point, but
+ for now that will generate a lot of unneeded classes.
+
+ maybe we can extend the process to only wrap classes that have
+ methods tagged with @roller.wrapPojoMethod ??
+ -->
+ <include name="org/roller/pojos/BookmarkData.java"/>
+ <include name="org/roller/pojos/CommentData.java"/>
+ <include name="org/roller/pojos/EntryAttributeData.java"/>
+ <include name="org/roller/pojos/FolderData.java"/>
+ <include name="org/roller/pojos/RefererData.java"/>
+ <include name="org/roller/pojos/Template.java"/>
+ <include name="org/roller/pojos/UserData.java"/>
+ <include name="org/roller/pojos/WeblogEntryData.java"/>
+ <include name="org/roller/pojos/WeblogCategoryData.java"/>
+ <include name="org/roller/pojos/WebsiteData.java"/>
+ </fileset>
+
+ <template
+ destinationFile="{0}Wrapper.java"
+ templateFile="metadata/xdoclet/pojo_wrapper.xdt"
+ subTaskName="Pojo Wrappers" />
+ </xdoclet>
+
+</target>
+
<!-- ********************************************************************* -->
<!-- Compile and jar Business Tier classes -->
<!-- ********************************************************************* -->
@@ -216,12 +256,14 @@
<javac debug="${build.debug}" destdir="${build.compile_beans}"
excludes="org/roller/presentation/**" >
<src path="${basedir}/src" />
+ <src path="${build.generated}/src.business"/>
&custom-src-beans;
<classpath>
<path refid="business.path"/>
&custom-jars;
</classpath>
</javac>
+
<!-- Copy class resources -->
<copy todir="${build.compile_beans}/org/roller/model">
<fileset dir="${build.generated}/src.business" includes="*.hbm.xml"/>
Added: incubator/roller/trunk/metadata/xdoclet/pojo_wrapper.xdt
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/metadata/xdoclet/pojo_wrapper.xdt?rev=224387&view=auto
==============================================================================
--- incubator/roller/trunk/metadata/xdoclet/pojo_wrapper.xdt (added)
+++ incubator/roller/trunk/metadata/xdoclet/pojo_wrapper.xdt Fri Jul 22 12:21:48 2005
@@ -0,0 +1,101 @@
+package <XDtPackage:packageName/>.wrapper;
+
+import <XDtClass:fullClassName/>;
+
+
+/**
+ * Generated wrapper for class: <XDtClass:fullClassName/>
+ */
+public class <XDtClass:className/>Wrapper {
+
+ // keep a reference to the wrapped pojo
+ private <XDtClass:className/> pojo = null;
+
+ // this is private so that we can force the use of the .wrap(pojo) method
+ private <XDtClass:className/>Wrapper(<XDtClass:className/> toWrap) {
+ this.pojo = toWrap;
+ }
+
+ // wrap the given pojo if it is not null
+ public static <XDtClass:className/>Wrapper wrap(<XDtClass:className/> toWrap) {
+ if(toWrap != null)
+ return new <XDtClass:className/>Wrapper(toWrap);
+
+ return null;
+ }
+
+<XDtMethod:forAllMethods superclasses="true">
+ <XDtMethod:ifHasMethodTag tagName="roller.wrapPojoMethod">
+ <XDtMethod:ifMethodTagValueEquals tagName="roller.wrapPojoMethod" paramName="type" value="pojo">
+
+ /**
+ * pojo method tagged with @roller.wrapPojoMethod type="pojo"
+ *
+ * This method returns another pojo so we need to wrap the returned pojo.
+ */
+ <XDtMethod:modifiers/> <XDtPackage:packageOf><XDtMethod:methodType/></XDtPackage:packageOf>.<XDtClass:classOf><XDtMethod:methodType/></XDtClass:classOf>Wrapper <XDtMethod:methodName/>(<XDtParameter:parameterList/>)
+ <XDtMethod:exceptionList/>
+ {
+ return <XDtPackage:packageOf><XDtMethod:methodType/></XDtPackage:packageOf>.<XDtClass:classOf><XDtMethod:methodType/></XDtClass:classOf>Wrapper.wrap(this.pojo.<XDtMethod:methodName/>(<XDtParameter:parameterList includeDefinition="false" />));
+ }
+
+ </XDtMethod:ifMethodTagValueEquals>
+
+ <XDtMethod:ifMethodTagValueEquals tagName="roller.wrapPojoMethod" paramName="type" value="pojo-collection">
+
+ /**
+ * pojo method tagged with @roller.wrapPojoMethod type="pojo-collection"
+ *
+ * This method returns a collection of pojos so we need to wrap
+ * each pojo that is part of the collection.
+ */
+ <XDtMethod:modifiers/> java.util.List <XDtMethod:methodName/>(<XDtParameter:parameterList/>)
+ <XDtMethod:exceptionList/>
+ {
+ <XDtMethod:methodType/> initialCollection = this.pojo.<XDtMethod:methodName/>(<XDtParameter:parameterList includeDefinition="false" />);
+
+ // iterate through and wrap
+ // we force the use of an ArrayList because it should be good enough to cover
+ // for any Collection type we encounter.
+ java.util.ArrayList wrappedCollection = new java.util.ArrayList(initialCollection.size());
+ java.util.Iterator it = initialCollection.iterator();
+ int i = 0;
+ while(it.hasNext()) {
+ wrappedCollection.add(i, <XDtPackage:packageOf><XDtMethod:methodTagValue tagName="roller.wrapPojoMethod" paramName="class"/></XDtPackage:packageOf>.<XDtClass:classOf><XDtMethod:methodTagValue tagName="roller.wrapPojoMethod" paramName="class"/></XDtClass:classOf>Wrapper.wrap((<XDtMethod:methodTagValue tagName="roller.wrapPojoMethod" paramName="class"/>) it.next()));
+ i++;
+ }
+
+ return wrappedCollection;
+ }
+
+ </XDtMethod:ifMethodTagValueEquals>
+
+ <XDtMethod:ifMethodTagValueEquals tagName="roller.wrapPojoMethod" paramName="type" value="simple">
+
+ /**
+ * pojo method tagged with @roller.wrapPojoMethod type="simple"
+ *
+ * Simply returns the same value that the pojo would have returned.
+ */
+ <XDtMethod:modifiers/> <XDtMethod:methodType/> <XDtMethod:methodName/>(<XDtParameter:parameterList/>)
+ <XDtMethod:exceptionList/>
+ {
+ return this.pojo.<XDtMethod:methodName/>(<XDtParameter:parameterList includeDefinition="false" />);
+ }
+ </XDtMethod:ifMethodTagValueEquals>
+
+ </XDtMethod:ifHasMethodTag>
+</XDtMethod:forAllMethods>
+
+
+ /**
+ * this is a special method to access the original pojo
+ * we don't really want to do this, but it's necessary
+ * because some parts of the rendering process still need the
+ * orginal pojo object
+ */
+ public <XDtClass:fullClassName/> getPojo() {
+ return this.pojo;
+ }
+
+}