Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8390649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:03:15+00:00 2026-06-09T19:03:15+00:00

I am working on a project that will have several Java classes that are

  • 0

I am working on a project that will have several Java classes that are very similar to each other, and that I would like to generate from XML files. What I would like to be able to do is change the Eclipse build process to do something like this:

  • Compile the code generator
  • Run the code generator, converting the XML to Java
  • Compile the rest of the project

I could do this all manually but I would prefer to be able to have Eclipse do it all for me.

Example

I want to be able to take a source XML file that looks like this:

<command-list>
    <command name="DATE" />
    <command name="GROUP">
        <capability "READER" />
        <argument "groupname" />
    </command>
    <command name="ARTICLE">
        <capability "READER" />
        <argument "message-id" optional="true" />
    </command>
</command-list>

and have it give me something similar to the following (in separate files as appropriate):

public class Date extends Command {
    public ResponseCode execute() {
        Server srv = getServer();
        srv.send("DATE");
        return srv.getResponse();
    }
}

public class Group extends Command {
    public ResponseCode execute() {
        Server srv = getServer();
        if (srv.hasCapability(Capabilities.READER) == false) {
            Log.debug("Attempting non-available capability: READER");
        }
        String groupname = getArgument("groupname");
        if (groupname == null) {
             throw new InvalidArgumentException("Require groupname");
        }
        String command = "GROUP";
        if (groupname != null) command += " " + groupname;
        srv.send(command);
        return srv.getResponse();
    }
}

public class Article extends Command {
    public ResponseCode execute() {
        Server srv = getServer();
        if (srv.hasCapability(Capabilities.READER) == false) {
            Log.debug("Attempting non-available capability: READER");
        }
        String messageId = getArgument("messageId");
        String command = "ARTICLE";
        if (messageId != null) command += " " + messageId;
        srv.send(command);
        return srv.getResponse();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:03:16+00:00Added an answer on June 9, 2026 at 7:03 pm

    This is exactly what the JET component in the Model to Text (M2T) project was made for. In fact, you can even create the project, .classpath and any other files you need with JET.

    Jet templates are as follows. Note that these templates must be named exactly as shown.

    /templates/main.jet

    <%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags" %>
    <%-- Main entry point for com.lacqui.command.xform --%>
    
    <%-- 
      Let c:iterate tags set the XPath context object.
      For 100% compatibility with JET 0.9.x or earlier, remove this statement
     --%>
    <c:setVariable var="org.eclipse.jet.taglib.control.iterateSetsContext" select="true()"/>
    
        <c:setVariable select="/command-list" var="command-list" />
    
        --- traverse input model, performing calculations and storing 
        --- the results as model annotations via c:set tag 
    
        <c:set select="$command-list" name="project">com.lacqui.commands</c:set>
        <c:set select="$command-list" name="commandPkg">com.lacqui.commands</c:set>
        <c:set select="$command-list" name="commandDir"><c:get select="translate($command-list/@commandPkg,'.','/')" /></c:set>
    
        <c:iterate select="$command-list/command" var="command" >
    
                - Derive the class name from the name of the command
    
            <c:set select="$command" name="classname"><c:get select="camelCase($command/@name)" />Command</c:set>
    
            <c:iterate select="$command/argument" var="argument">
    
                <c:if test="not($argument/@optional)">
                    <c:set select="$argument" name="optional">false</c:set>
                </c:if>
    
            </c:iterate>
    
        </c:iterate>
    
       --- traverse annotated model, performing text generation actions 
       --- such as ws:file, ws:folder and ws:project 
    
       <ws:project name="{$command-list/@project}" />
       <ws:file template="templates/project.jet" path="{$command-list/@project}/.project"  />
       <ws:file template="templates/classpath.jet" path="{$command-list/@project}/.classpath"/>
    
        <c:iterate select="$command-list/command" var="command" >
    
            <ws:file template="templates/class.jet" path="{$command-list/@project}/src/{$command-list/@commandDir}/{$command/@classname}.java" replace="true"/>
    
        </c:iterate>
    

    /templates/classpath.jet

    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="output" path="bin"/>
    </classpath>
    

    /templates/project.jet

    <?xml version="1.0" encoding="UTF-8"?>
    <projectDescription>
        <name><c:get select="$command-list/@project" /></name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
            <buildCommand>
                <name>org.eclipse.jdt.core.javabuilder</name>
                <arguments>
                </arguments>
            </buildCommand>
        </buildSpec>
        <natures>
            <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>
    </projectDescription>
    

    /templates/class.jet

    package <c:get select="$command-list/@commandPkg" />;
    
    public class <c:get select="$command/@classname" /> extends Command {
        public ResponseCode execute() {
            Server srv = getServer();
    <c:iterate select="$command/capability" var="capability">
    
            if (srv.hasCapability(Capabilities.<c:get select="$capability/@name"/>) == false) {
                Log.debug("Attempting non-available capability: <c:get select="$capability/@name"/>");
            }
    </c:iterate>        
    <c:iterate select="$command/argument" var="argument">
    
            String <c:get select="$argument/@name"/> = getArgument("<c:get select="$argument/@name"/>");
    <c:if test="$argument/@optional = 'false'" >
            if (<c:get select="$argument/@name"/> == null) {
                 throw new InvalidArgumentException("Require <c:get select="$argument/@name"/>");
            }
    </c:if>
    </c:iterate>        
    
            String command = "GROUP";
    <c:iterate select="$command/argument" var="argument">
            if (<c:get select="$argument/@name"/> != null) command += " -<c:get select="$argument/@name"/> " + <c:get select="$argument/@name"/>;
    </c:iterate>       
    
            srv.send(command);
            return srv.getResponse();
        }
    }
    

    and using this model:

    <command-list>
        <command name="DATE" />
        <command name="GROUP">
            <capability name="LOGGER" />
            <capability name="AUTHENTICATOR" />
            <argument name="groupname" />
        </command>
        <command name="ARTICLE">
            <capability name="READER" />
            <argument name="article-id" optional="false" />
            <argument name="message-id" optional="true" />
        </command>
    </command-list>
    

    gives a complete java project named com.lacqui.commands containing three java files:

    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();
        }
    }
    

    and this:

    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();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a SaaS project that will have each customer having an instance
I'm working on a project that will have a single table holding lots and
I've started working on a little ruby project that will have sample implementations of
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
I have a small project that I will be working on shortly that collects
I'm working on a larger Web based Project, that probably will have to handle
I am currently working on a project where I have several string that may
I'm working on a project in C# 4.0. I have several presenter classes, which
I'm working on a web project that will (hopefully) be available in several languages
I am working on a project that i want to have a plugin-sandbox like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.