XDoclet learning notes (template)

xiaoxiao2021-03-05  20

XDoclet provides its own template engine. This template engine is conceptually similar to JavaServer Pages (JSP) technology. It essentially contains two types of tags: block tags and content tags. Block tag controls streams such as the IF and FOR statements in the Java programming language. Content tag prints the clip of the current parsing tree, such as class name, method name, and parameters, and so on.

I can talk about XDoclet all day, but if you are like me, then you will want me to "give code." There is no need to say, there is a simple template, it looks for all entity beans, then print out their class name and the names of all its CMP fields:

ClassName =

CMP Field =

This simple template also demonstrates block tags and content tags. FORALLCLASSES is a block tag example that traverses all classes passing to the template engine, which is passed by calling the FileSet in the ANT build file in the xdoclet. FORALLCLASSES Filters the classes that do not belong to type Javax.ejb.EntityBean (Type = "javax.ejb.entitybean).

ClassName is an example of a content tag that prints the name of the current class.

FORALLPROPERITESWITHTAG is another block tag example. It traverses all the features of all the XDoclet tag @ Ejb.Persistence in the class (these features are related to the BEAN's CMP field). Finally, PropertyName is another example of the content tag because it displays the current feature name during the traversal process.

Since all other examples are built over these simple concepts, let us take these concepts. The picture below shows the block mark with the black bold font, and the content tag is displayed with red bold font. In addition, these blocks also use a circular rectangle to demonstrate its range.

The output of this code template is as follows:

ClassName = Employeebean

CMP Field = ID

CMP Field = firstname

CMP Field = lastname

CMP Field = Phone

ClassName = de PEPTBEAN

CMP Field = ID

CMP Field = Name

To run this template, you will need the following code in your Ant build file:

Name = "templatedoclet"

ClassName = "xdoclet.doclettask"

ClasspathRef = "xdocpath"

/>

TemplateFile = "template / template.xdt"

DestinationFile = "Test.txt" />

Templatedoclet tasks are used to perform templates. The FileSet sub-elements are used to specify: You only want the file that ends with "bean.java" in the SRC directory. Template sub-tasks are used to specify the template files and target files used. The above example executes the template defined earlier (Template / Template.xdt) and outputs the result to text.txt. Please refer to the figure below for more details. To truly understand how to effectively develop custom XDoclet templates, you should understand the XDoclet architecture - so please allow me to explain the architecture first, and then discuss it.

转载请注明原文地址:https://www.9cbs.com/read-38859.html

New Post(0)