ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Using XML and Jar Utility API to Build a Rule-Based Java EE Auto-Deployer
Pages: 1, 2, 3, 4

And the generated XML document of the deployment rule (rule.xml) looks like this:

<?xml version="1.0"?> 
      <version>Release v1.0</version>
Design of the Deployment Tool

For this sample tool, a Factory design pattern is applied to build deployment module, POJOs, from a deployment rule, after that these POJOs are serialized to XML documents by a RuleGenerator using XStream utility library. The class design is shown in Figure 4.

Figure 4
Figure 4. Class diagram of deployment tool

As shown in Figure 5, the RuleGenerator reads a DeployPlan as a file or input stream and then parses the plan to generate a DeployRule Java object. The DeployRule Java object will be serialized to XML document using XStream utility library.

Figure 5
Figure 5. Sequence diagram of deployment rule generation

The sample code of RuleGenerator is shown below:

package onebuttondeploy.tool;

import java.io.FileWriter;
import java.util.ArrayList;

import onebuttondeploy.Constants;
import onebuttondeploy.rule.ApplicationModuleVO;
import onebuttondeploy.rule.DatasourceModuleVO;
import onebuttondeploy.rule.DeployModule;
import onebuttondeploy.rule.DeployRule;
import onebuttondeploy.rule.DeploymentModuleFactory;
import onebuttondeploy.rule.JmsModuleVO;
import onebuttondeploy.rule.LdapModuleVO;
import onebuttondeploy.rule.SqlModuleVO;

import com.thoughtworks.xstream.XStream;

* @author Colin (Chun) Lu
* @Email colinlucs@gmail.com

public class RuleGenerator {
     * Convert deploy plan to XML document
    public static String getXmlRule(String plan) throws Exception{
        return generateDeployRuleXml(plan2Rule(plan));
     * Instantiate DeployRule object from deploy plan
    private static DeployRule plan2Rule(String plan) throws Exception{
        if (plan == null)
            return null;
        DeployRule rule = new DeployRule();
        String[] deployModules = plan.split("\n");
        for (int i = 0; i < deployModules.length; i++) {
            DeployModule module = 
            if (module != null)
        return rule;
     * Serialize DeployRule object to XML document usign XStream
    private static String generateDeployRuleXml(DeployRule rule) throws Exception{
        if (rule == null)
            return null;
        String xml = "<?xml version=\"1.0\"?> \n";
        XStream xstream = new XStream();
        xstream.alias("rule", DeployRule.class);
        xstream.alias("modules", ArrayList.class);
        xstream.alias("datasource", DatasourceModuleVO.class);
        xstream.alias("jms", JmsModuleVO.class);
        xstream.alias("sql", SqlModuleVO.class);
        xstream.alias("ldap", LdapModuleVO.class);
        xstream.alias("application", ApplicationModuleVO.class);
        xml += xstream.toXML(rule);
        return xml;

Pages: 1, 2, 3, 4

Next Pagearrow