`

read-AppFuse-16-XDoclet学习续

阅读更多
● xdoclet学习续
  Xdoclet是一个代码自动生成的工具
  XDoclet任务就是Ant的自定义任务,除此以外,没有其他运行XDoclet任务的方法。
  XDoclet它有两个重要的组件:
  进行特殊标记的 Java 源文件。
  预先定义的模板。[引用]
  
  
  Merge File用来处理无法在Source Code中加xdoclet tag的情况。
  
  Ø XDoclet中的核心任务:
  <ejbdoclet>:面向EJB领域,生成EJB、工具类和布署描述符。
  <webdoclet>:面向Web开发,生成serlvet、自定义标签库和web框架文件。
  <hibernatedoclet>:Hibernate持续,配置文件、Mbeans
  <jdodoclet>:JDO,元数据,vender configuration
  <jmxdoclet>:JMX,MBean接口,mlets,配置文件。
  <doclet>:使用用户自定义模板来生成代码。
  <documentdoclet>:生成项目文件(例如todo列报表)
  
  Ø webdoclet sub task
  XDoclet并没有和Ant一起发布,所以如果你想要使用XDoclet的话,就需要单独的下载和
  安装。在使用任何一个XDoclet的任务之前,你首先需要在使用Ant的<taskdef>任务来声
  明它。
  <deploymentdescriptor>:产生标准的web引用配置文件web.xml,destdir属性设定
  web.xml文件的存放位置。
  XDoclet通过合并点(merge points)支持定制,合并点是在模板文件定义里允许运行时插入定制代码的地方,使用mergedir属性设置。
   <target name="webdoclet" depends="compile-web"
   unless="webdoclet.unnecessary"
   description="Generate web and Struts descriptors">
   <taskdef name="webdoclet" classname="xdoclet.modules.web.WebDocletTask">
   <classpath>
   <path refid="xdoclet.classpath"/>
   <path refid="web.compile.classpath"/>
   </classpath>
   </taskdef>
   <!—mergedir完成模板文件合并的功能-->
   <webdoclet destdir="${webapp.target}/WEB-INF"
   force="${xdoclet.force}"
   mergedir="metadata/web"
   excludedtags="@version,@author"
   verbose="true">
   <!—找出目录src/web 和${build.dir}/web/gen文件中的webdoclet注
   释,生成web.xml,struts-config.xml等配置信息文件-->
   <fileset dir="src/web"/>
   <fileset dir="${build.dir}/web/gen"/>
   <!—生成的web.xml文件放在build/appName/WEB-INF/-->
   <deploymentdescriptor validateXML="true"
   servletspec="2.3" sessiontimeout="10"
   destdir="${webapp.target}/WEB-INF" distributable="false"
   displayname="${ant.project.name}">
   <configParam name="httpPort" value="${http.port}"/>
   <configParam name="httpsPort" value="${https.port}"/>
   <configParam name="daoType" value="${dao.type}"/>
   <configParam name="security" value="${security.mode}"/>
   </deploymentdescriptor>
   <jsptaglib validateXML="true"
   description="Custom tag library for this application"
   shortName="${webapp.name}" filename="${webapp.name}.tld"/>
   <strutsconfigxml validateXML="true" version="1.2"/>
   <strutsvalidationxml/>
   </webdoclet>
   </target>
  
  图表 1引用一张网友发表的非常直观的使用说明图
  Ø XDoclet 中的合并点
  在 XDoclet 的文档中,您会非常频繁地看到术语 合并点(merge point)和 合并文件(merge file)。合并文件是文本文件,您可以把它合并到 XDoclet 生成代码的指定位置——“合并点”上(由模板指定)。可以用合并文件来包含静态文本(例如代码片断和 XML 片断),这些文本可能很难或者不能用 XDoclet 的能力生成。例如,在示例代码的 metadata/web 目录下,您会找到这些文件。在代码生成期间,可以用到这些文件合并配置文件的一部分[引用]。
  
  ØXDoclet中的模板
  XDoclet使用代码模板来生成代码。模板(template)是你想生成文件的原型。模板里使
  用一些XML标签来指导模板引擎如何根据输入类以及它们的元数据来调整代码的生成。
  模板有点像JSP文件。它们都包含文件和XML标签,生成输出文件时XML标签会被解析,
  然后生成文本并显示在XML标签所处的位置上。除了以XDt为命名空间打头的XML标签
  会被XDoclet引擎解析以外,其余的XML标签XDoclet会忽略不管。
  Ø AppFuse中生成Action类的XDoclet模板
  public final class <XDtClass:className/>Action extends BaseAction {
  public ActionForward cancel(ActionMapping mapping, ActionForm form,HttpServletRequest request,
   HttpServletResponse response)
   throws Exception {
   return search(mapping, form, request, response);
   }
   public ActionForward delete(ActionMapping mapping, ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response)
   throws Exception {
   if (log.isDebugEnabled()) {
   log.debug("Entering 'delete' method");
   }
   ActionMessages messages = new ActionMessages();
   <XDtClass:className/>Form <XDtForm:classNameLower/>Form = (<XDtClass:className/>Form) form;
   // Exceptions are caught by ActionExceptionHandler
   Manager mgr = (Manager) getBean("manager");
   mgr.removeObject(<XDtClass:className/>.class, new Long(<XDtForm:classNameLower/>Form.getId()));
   messages.add(ActionMessages.GLOBAL_MESSAGE,
   new ActionMessage("<XDtForm:classNameLower/>.deleted"));
   // save messages in session, so they'll survive the redirect
   saveMessages(request.getSession(), messages);
   return search(mapping, form, request, response);
   }
  … …
  }
  Ø AppFuse中自动生成的对应Action类
  public final class PersonAction extends BaseAction {
   public ActionForward cancel(ActionMapping mapping, ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response)
   throws Exception {
   return search(mapping, form, request, response);
   }
  
   public ActionForward delete(ActionMapping mapping, ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response)
   throws Exception {
   if (log.isDebugEnabled()) {
   log.debug("Entering 'delete' method");
   }
   ActionMessages messages = new ActionMessages();
   PersonForm personForm = (PersonForm) form;
   // Exceptions are caught by ActionExceptionHandler
   Manager mgr = (Manager) getBean("manager");
   mgr.removeObject(Person.class, new Long(personForm.getId()));
   messages.add(ActionMessages.GLOBAL_MESSAGE,
   new ActionMessage("person.deleted"));
   // save messages in session, so they'll survive the redirect
   saveMessages(request.getSession(), messages);
   return search(mapping, form, request, response);
   }
  … …
  }
分享到:
评论

相关推荐

    SSH学习及开发框架-appfuse

    appfuse 有struts2+hibernate+spring的整合 springmvc+hibernate+spring的整合 多模块,但模块都有 学习开发参考使用非常方便 可以到官方下载最新版的,我只是把自己下载的打包整理一下 注意哈,都是基于maven的...

    Using Struts 2 - AppFuse 2 - Confluence(1).pdf

    Using Struts 2

    玩转appfuse--使用appfuse建设MVC网站

    使用appfuse进行网站开发,appfuse是关于Spring,Struts2,MVC3,Hibernate等技术的案例,可以加快建设网站。 1.文档说明。 2.可以执行的案例,亲测无误。

    xdoclet_appfuse打包

    appfuse,xdoclet上网收集的一些资料打包

    appfuse1.4-architecture

    06年时的appfuse,学习SSH架构的经典入门框架。相对比较老的资料,可以欣赏一下当时的架构,向牛人致敬

    Appfuse1.9至2.0.2

    主要是自己从网络上搜集的一些关于appfuse1.8.2-2.0.2的一些相关资料,间或有点自己试验的记录,还有点maven和quartz的东东,之前我主要是用1.8.2构建项目,感觉还不错,希望对想学习appfuse的人有些帮助.

    appfuse-documentation-2.1.0官方文档

    AppFuse是一个集成了众多当前最流行开源框架与工具(包括Hibernate、ibatis、Struts、Spring、DBUnit、Ant、Log4J、Struts Menu、Xdoclet、SiteMesh、OSCache、JUnit、JSTL)于一身的Web开发框架。AppFuse提供了Web...

    appfuse

    使用appfuse2.0,下载过来的实例源码,没有jar包

    appfuse-tutorial-struts-1.6.zip_appfuse

    关于企业人员管理的struts应用样例,包含人员添加、信息修改及注销等。

    建立项目原型骨架的步骤(最新版本appfuse)appfuse2.1.0-M2

    建立项目原型骨架的步骤(最新版本appfuse)appfuse2.1.0-M2 spring3.0 hibernte3.3 struts2.1.8

    appfuse学习笔记(一)安装部署

    NULL 博文链接:https://savagegarden.iteye.com/blog/427169

    appfuse 学习笔记

    Appfuse 一个开放源码的项目和应用程序,帮助我们快速而高效的地开发。

    appfuse-documentation-2.0

    AppFuse是目前最火热的开源项目,采用如SSH架构等,是优秀的系统开发框架。

    appfuse2学习日记

    自己学习appfuse2的相关日志,里面包含了一些在网上已经文档的综合.

    appfuse-light-webwork-spring-jdbc-1.8.2.zip_Java 8_appfuse_webwo

    appfuse对java web开发很有帮助,里边用了分层的思想进行开发的

    可直接使用的appfuse项目

    AppFuse是一个集成了众多当前最流行开源框架与工具(包括Hibernate、ibatis、Struts、Spring、DBUnit、Maven、Log4J、Struts Menu、Xdoclet、SiteMesh、OSCache、JUnit、JSTL等(现在还有lucene的,无敌了))于一身的...

    AppFuse

    本文以一个 J2EE 开发者的角度,借助一个简单的应用示例,在融合了个人经验的基础上介绍了如何用 AppFuse 一步步地构建 J2EE 项目。通过阅读本文,读者不仅能够学会用 AppFuse 进行开发,而且能够充分体会到 AppFuse...

    appfuse-demos

    appfuse-demos-2.0.2代码生成的基本代码框架。

    AppFuse入门文档(AppFuse与SpringMVC+mybatis整合)

    本文档详细描述了AppFuse与SpringMVC+mybatis整合的过程,只要你懂一些基本的eclipse操作和基本的maven命令,就可以在三分钟之内迅速的搭建出一个AppFuse的架构

Global site tag (gtag.js) - Google Analytics