xml生成java代码_在Eclipse中从XML生成Java代码

本文详细介绍了如何在M2T项目中运用JET组件来创建和管理Java项目,包括创建.classpath和.project文件。通过示例展示了如何使用Jet模板生成类文件,并给出了一个包含ArticleCommand和GroupCommand的完整Java项目示例,强调了模板在处理输入模型、执行计算和存储结果作为模型注解的作用。
摘要由CSDN通过智能技术生成

这正是模型到文本(M2T)项目中的JET组件的用途.实际上,您甚至可以使用JET创建项目,.classpath和任何其他文件.

Jet模板如下.请注意,这些模板必须完全按照所示命名.

/templates/main.jet

Let c:iterate tags set the XPath context object.

For 100% compatibility with JET 0.9.x or earlier, remove this statement

--%>

--- traverse input model, performing calculations and storing

--- the results as model annotations via c:set tag

com.lacqui.commands

com.lacqui.commands

- Derive the class name from the name of the command

Command

false

--- traverse annotated model, performing text generation actions

--- such as ws:file, ws:folder and ws:project

/templates/classpath.jet

/templates/project.jet

org.eclipse.jdt.core.javabuilder

org.eclipse.jdt.core.javanature

/templates/class.jet

package ;

public class extends Command {

public ResponseCode execute() {

Server srv = getServer();

if (srv.hasCapability(Capabilities.) == false) {

Log.debug("Attempting non-available capability: ");

}

String = getArgument("");

if ( == null) {

throw new InvalidArgumentException("Require ");

}

String command = "GROUP";

if ( != null) command += " - " + ;

srv.send(command);

return srv.getResponse();

}

}

并使用此模型:

给出一个名为com.lacqui.commands的完整java项目,其中包含三个java文件:

package com.lacqui.commands;

public class ArticleCommand extends Command {

public ResponseCode execute() {

Server srv = getServer();

if (srv.hasCapability(Capabilities.READER) == false) {

Log.debug("Attempting non-available capability: READER");

}

String article-id = getArgument("article-id");

if (article-id == null) {

throw new InvalidArgumentException("Require article-id");

}

String message-id = getArgument("message-id");

String command = "GROUP";

if (article-id != null) command += " -article-id " + article-id;

if (message-id != null) command += " -message-id " + message-id;

srv.send(command);

return srv.getResponse();

}

}

还有这个:

package com.lacqui.commands;

public class GroupCommand extends Command {

public ResponseCode execute() {

Server srv = getServer();

if (srv.hasCapability(Capabilities.LOGGER) == false) {

Log.debug("Attempting non-available capability: LOGGER");

}

if (srv.hasCapability(Capabilities.AUTHENTICATOR) == false) {

Log.debug("Attempting non-available capability: AUTHENTICATOR");

}

String groupname = getArgument("groupname");

if (groupname == null) {

throw new InvalidArgumentException("Require groupname");

}

String command = "GROUP";

if (groupname != null) command += " -groupname " + groupname;

srv.send(command);

return srv.getResponse();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值