[jbpm-commits] JBoss JBPM SVN: r6791 - in projects/migration_tool/trunk/src: main/java/org and 10 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Nov 2 18:46:43 EDT 2010


Author: MohReece
Date: 2010-11-02 18:46:42 -0400 (Tue, 02 Nov 2010)
New Revision: 6791

Added:
   projects/migration_tool/trunk/src/main/java/org/
   projects/migration_tool/trunk/src/main/java/org/jbpm/
   projects/migration_tool/trunk/src/main/java/org/jbpm/migration/
   projects/migration_tool/trunk/src/main/java/org/jbpm/migration/BpmnValidator.java
   projects/migration_tool/trunk/src/main/java/org/jbpm/migration/JpdlValidator.java
   projects/migration_tool/trunk/src/main/java/org/jbpm/migration/Migrator.java
   projects/migration_tool/trunk/src/main/java/org/jbpm/migration/ProcessTransformer.java
   projects/migration_tool/trunk/src/main/java/org/jbpm/migration/util/
   projects/migration_tool/trunk/src/main/java/org/jbpm/migration/util/XmlUtils.java
   projects/migration_tool/trunk/src/test/java/org/
   projects/migration_tool/trunk/src/test/java/org/jbpm/
   projects/migration_tool/trunk/src/test/java/org/jbpm/migration/
   projects/migration_tool/trunk/src/test/java/org/jbpm/migration/JpdlValidatorTest.java
   projects/migration_tool/trunk/src/test/java/org/jbpm/migration/ProcessTransformerTest.java
   projects/migration_tool/trunk/src/test/resources/jpdl3/.gpd.jpdl-3.2.xml
Modified:
   projects/migration_tool/trunk/src/main/resources/jpdl3-bpmn2.xsl
   projects/migration_tool/trunk/src/test/java/test/XSLTTest.java
Log:
Corrected the XSD validation.
Improved the transformation a little.
Added some first tests.

Added: projects/migration_tool/trunk/src/main/java/org/jbpm/migration/BpmnValidator.java
===================================================================
--- projects/migration_tool/trunk/src/main/java/org/jbpm/migration/BpmnValidator.java	                        (rev 0)
+++ projects/migration_tool/trunk/src/main/java/org/jbpm/migration/BpmnValidator.java	2010-11-02 22:46:42 UTC (rev 6791)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.migration;
+
+import java.io.File;
+import java.net.URISyntaxException;
+
+import org.apache.log4j.Logger;
+import org.jbpm.migration.util.XmlUtils;
+import org.w3c.dom.Document;
+
+/**
+ * This class validates a resulting jDPL definition against the applicable XML schema.
+ * 
+ * @author Eric D. Schabell
+ * @author Maurice de Chateau
+ */
+public final class BpmnValidator {
+    /* XML Schema file for BPMN version 2.0 on the classpath. */
+    private static final String BPMN_2_0_SCHEMA = "Schemas/BPMN/BPMN20.xsd";
+
+    /** Logging facility. */
+    private static final Logger LOGGER = Logger.getLogger(BpmnValidator.class);
+
+    /** Private constructor to enforce non-instantiability. */
+    private BpmnValidator() {
+    }
+
+    /**
+     * Validate a given BPMN process definition against the applicable schema.
+     * 
+     * @param bpmn
+     *            The process definition.
+     * @param gpd
+     *            The graphical positioning for the process definition.
+     * @return The concatenated document containing both process definition and positioning, or null if (one of) the validations was
+     *         not successful.
+     */
+    public static boolean validateDefinition(Document bpmn) {
+        // Validate against the jPDL schema.
+        File schema = null;
+        try {
+            schema = new File(BpmnValidator.class.getClassLoader().getResource(BPMN_2_0_SCHEMA).toURI());
+        } catch (URISyntaxException usEx) {
+            LOGGER.error("Cannot locate BPMN schema.", usEx);
+            return false;
+        }
+        return XmlUtils.validate(bpmn, schema);
+    }
+}


Property changes on: projects/migration_tool/trunk/src/main/java/org/jbpm/migration/BpmnValidator.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/migration_tool/trunk/src/main/java/org/jbpm/migration/JpdlValidator.java
===================================================================
--- projects/migration_tool/trunk/src/main/java/org/jbpm/migration/JpdlValidator.java	                        (rev 0)
+++ projects/migration_tool/trunk/src/main/java/org/jbpm/migration/JpdlValidator.java	2010-11-02 22:46:42 UTC (rev 6791)
@@ -0,0 +1,117 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.migration;
+
+import java.io.File;
+import java.net.URISyntaxException;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.jbpm.migration.util.XmlUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * This class validates an original jDPL definition against the applicable XML schema.
+ * <p>
+ * TODO: Make jPDL version flexible (now only 3.2 is supported).<br>
+ * TODO: Include validation for GPD.
+ * 
+ * @author Eric D. Schabell
+ * @author Maurice de Chateau
+ */
+public final class JpdlValidator {
+    /* XML Schema file for jPDL version 3.2 on the classpath. */
+    private static final String JPDL_3_2_SCHEMA = "Schemas/jPDL/jpdl-3.2.xsd";
+
+    /** Logging facility. */
+    private static final Logger LOGGER = Logger.getLogger(JpdlValidator.class);
+
+    /** Private constructor to enforce non-instantiability. */
+    private JpdlValidator() {
+    }
+
+    /**
+     * Parse and validate a given jDPL/GPD process definition against the applicable schema.
+     * <p>
+     * TODO: Correct the concatenation process, throws a DOMException like this.
+     * 
+     * @param jpdl
+     *            The process definition.
+     * @param gpd
+     *            The graphical positioning for the process definition.
+     * @return The concatenated document containing both process definition and positioning, or null if (one of) the validations was
+     *         not successful.
+     */
+    public static Document validateDefinition(File jpdl, File gpd) {
+        Document jpdlDoc = validateDefinition(jpdl);
+        Document gpdDoc = validatePositioning(gpd);
+
+        Document concatenated = null;
+        if (jpdlDoc != null && gpdDoc != null) {
+            try {
+                concatenated = XmlUtils.createEmptyDocument();
+                concatenated.appendChild(jpdlDoc);
+                concatenated.appendChild(gpdDoc);
+            } catch (Exception ex) {
+                LOGGER.error("Problem concatenating the jDPL and GPD definitions.", ex);
+            }
+        }
+        return concatenated;
+    }
+
+    private static Document validateDefinition(File jpdl) {
+        // Parse the jDPL definition into a DOM tree.
+        Document document = XmlUtils.parseFile(jpdl);
+        if (document == null) {
+            return null;
+        }
+
+        // Get the jPDL version from the process definition.
+        Node xmlnsNode = document.getFirstChild().getAttributes().getNamedItem("xmlns");
+        if (xmlnsNode != null && StringUtils.isNotBlank(xmlnsNode.getNodeValue())) {
+            String version = xmlnsNode.getNodeValue().substring(xmlnsNode.getNodeValue().length() - 3);
+            LOGGER.info("jPDL version == " + version);
+        }
+
+        // Validate against the jPDL schema.
+        File schema = null;
+        try {
+            schema = new File(JpdlValidator.class.getClassLoader().getResource(JPDL_3_2_SCHEMA).toURI());
+        } catch (URISyntaxException usEx) {
+            LOGGER.error("Cannot locate jPDL schema.", usEx);
+            return null;
+        }
+        return XmlUtils.validate(document, schema) ? document : null;
+    }
+
+    private static Document validatePositioning(File gpd) {
+        // Parse the GPD definition into a DOM tree.
+        Document document = XmlUtils.parseFile(gpd);
+        if (document == null) {
+            return null;
+        }
+
+        // TODO: Validate the document before returning it.
+        return document;
+    }
+}


Property changes on: projects/migration_tool/trunk/src/main/java/org/jbpm/migration/JpdlValidator.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/migration_tool/trunk/src/main/java/org/jbpm/migration/Migrator.java
===================================================================
--- projects/migration_tool/trunk/src/main/java/org/jbpm/migration/Migrator.java	                        (rev 0)
+++ projects/migration_tool/trunk/src/main/java/org/jbpm/migration/Migrator.java	2010-11-02 22:46:42 UTC (rev 6791)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.migration;
+
+import java.io.File;
+
+import org.apache.commons.lang.StringUtils;
+import org.jbpm.migration.util.XmlUtils;
+import org.w3c.dom.Document;
+
+/**
+ * This class migrate a jPDL process definition to an equivalent BPMN 2.0 process definition.
+ * 
+ * @author Eric D. Schabell
+ * @author Maurice de Chateau
+ */
+public class Migrator {
+    /**
+     * @param args
+     *            The input for this method:<br>
+     *            <ul>
+     *            <li>args[0]: The (full) path of the jPDL process definition that's to be migrated.</li>
+     *            <li>args[1]: The (full) path of the corresponding GPD positioning file.</li>
+     *            </ul>
+     *            Any further arguments are ignored.
+     */
+    public static void main(String[] args) {
+        // Check the input.
+        if (args.length != 2 || StringUtils.isBlank(args[0]) || StringUtils.isBlank(args[1])) {
+            throw new IllegalArgumentException("Insufficient arguments for the migrator (must be 2).");
+        }
+        File jpdl = new File(args[0]);
+        File gpd = new File(args[1]);
+        if (!jpdl.isFile() || !gpd.isFile()) {
+            throw new IllegalArgumentException("Both of the input arguments must be files.");
+        }
+
+        // Validate the jPDL and GPD files.
+        Document input = JpdlValidator.validateDefinition(jpdl, gpd);
+        System.out.println(XmlUtils.format(input));
+
+        // Transform the process.
+        Document output = ProcessTransformer.transform(input);
+        System.out.println(XmlUtils.format(output));
+
+        // TODO: Validate the BPMN file.
+    }
+}


Property changes on: projects/migration_tool/trunk/src/main/java/org/jbpm/migration/Migrator.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/migration_tool/trunk/src/main/java/org/jbpm/migration/ProcessTransformer.java
===================================================================
--- projects/migration_tool/trunk/src/main/java/org/jbpm/migration/ProcessTransformer.java	                        (rev 0)
+++ projects/migration_tool/trunk/src/main/java/org/jbpm/migration/ProcessTransformer.java	2010-11-02 22:46:42 UTC (rev 6791)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.migration;
+
+import java.io.File;
+import java.net.URISyntaxException;
+
+import org.apache.log4j.Logger;
+import org.jbpm.migration.util.XmlUtils;
+import org.w3c.dom.Document;
+
+/**
+ * Transforms a given jPDL/GPD definition to an equivalent BPMN 2.0 definition.
+ * 
+ * @author Eric D. Schabell
+ * @author Maurice de Chateau
+ */
+public final class ProcessTransformer {
+    /* XSL Transformation file for jPDL version 3.2 on the classpath. */
+    private static final String MIGRATION_STYLE_SHEET = "jpdl3-bpmn2.xsl";
+
+    /** Logging facility. */
+    private static final Logger LOGGER = Logger.getLogger(ProcessTransformer.class);
+
+    /** Private contractor to prevent instantiation. */
+    private ProcessTransformer() {
+    }
+
+    public static Document transform(Document jpdl) {
+        File styleSheet = null;
+        try {
+            styleSheet = new File(JpdlValidator.class.getClassLoader().getResource(MIGRATION_STYLE_SHEET).toURI());
+        } catch (URISyntaxException usEx) {
+            LOGGER.error("Cannot locate jPDL to BPMN style sheet.", usEx);
+            return null;
+        }
+        return XmlUtils.transform(jpdl, styleSheet);
+    }
+}


Property changes on: projects/migration_tool/trunk/src/main/java/org/jbpm/migration/ProcessTransformer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/migration_tool/trunk/src/main/java/org/jbpm/migration/util/XmlUtils.java
===================================================================
--- projects/migration_tool/trunk/src/main/java/org/jbpm/migration/util/XmlUtils.java	                        (rev 0)
+++ projects/migration_tool/trunk/src/main/java/org/jbpm/migration/util/XmlUtils.java	2010-11-02 22:46:42 UTC (rev 6791)
@@ -0,0 +1,210 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.migration.util;
+
+import java.io.File;
+import java.io.StringWriter;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Convenience class for working with XML documents.
+ * 
+ * @author Eric D. Schabell
+ * @author Maurice de Chateau
+ */
+public final class XmlUtils {
+    private static final Logger LOGGER = Logger.getLogger(XmlUtils.class);
+
+    private static final DocumentBuilderFactory FACTORY = DocumentBuilderFactory.newInstance();
+    static {
+        FACTORY.setNamespaceAware(true);
+    }
+
+    /** Private constructor to prevent instantiation. */
+    private XmlUtils() {
+    }
+
+    /**
+     * Create an empty XML structure.
+     * 
+     * @return An empty DOM tree.
+     */
+    public static Document createEmptyDocument() {
+        Document output = null;
+        try {
+            output = FACTORY.newDocumentBuilder().newDocument();
+        } catch (Exception ex) {
+            LOGGER.error("Problem creating empty XML document.", ex);
+        }
+
+        return output;
+    }
+
+    /**
+     * Parse a <code>File</code> containing an XML structure into a DOM tree.
+     * 
+     * @param input
+     *            The input XML file.
+     * @return The corresponding DOM tree, or <code>null</code> if the input could not be parsed successfully.
+     */
+    public static Document parseFile(File input) {
+        Document output = null;
+        try {
+            output = FACTORY.newDocumentBuilder().parse(input);
+        } catch (Exception ex) {
+            String msg = "Problem parsing the input XML file";
+            if (ex instanceof SAXParseException) {
+                msg += " at line #" + ((SAXParseException) ex).getLineNumber();
+            }
+            LOGGER.error(msg, ex);
+        }
+
+        return output;
+    }
+
+    /**
+     * Parse a <code>String</code> containing an XML structure into a DOM tree.
+     * 
+     * @param input
+     *            The input XML <code>String</code>.
+     * @return The corresponding DOM tree, or <code>null</code> if the input could not be parsed successfully.
+     */
+    public static Document parseString(String input) {
+        Document output = null;
+        try {
+            output = FACTORY.newDocumentBuilder().parse(input);
+        } catch (Exception ex) {
+            String msg = "Problem parsing the input XML file";
+            if (ex instanceof SAXParseException) {
+                msg += " at line #" + ((SAXParseException) ex).getLineNumber();
+            }
+            LOGGER.error(msg, ex);
+        }
+
+        return output;
+    }
+
+    /**
+     * Validate an XML document against an XML Schema definition.
+     * 
+     * @param input
+     *            The input XML document.
+     * @param schemaFile
+     *            The XML Schema against which the document must be validated.
+     * @return Whether the validation was successful.
+     */
+    public static boolean validate(Document input, File schemaFile) {
+        boolean isValid = true;
+        try {
+            SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+            Schema schema = factory.newSchema(new StreamSource(schemaFile));
+            // TODO: Experiment with ErrorHandler on Validator for more concise error messages.
+            schema.newValidator().validate(new DOMSource(input));
+        } catch (Exception ex) {
+            LOGGER.error("Problem validating the given process definition.", ex);
+            isValid = false;
+        }
+
+        return isValid;
+    }
+
+    /**
+     * Transform an XML document according to an XSL style sheet.
+     * 
+     * @param input
+     *            The input XML document.
+     * @param styleSheet
+     *            The XSL style sheet according to which the document must be transformed.
+     * @return The transformed document, or <code>null</code> if a problem occurred while transforming.
+     */
+    public static Document transform(Document input, File styleSheet) {
+        Document output = null;
+        try {
+            output = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+            Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(styleSheet));
+            transformer.transform(new DOMSource(input), new DOMResult(output));
+        } catch (Exception ex) {
+            LOGGER.error("Problem transforming XML file.", ex);
+        }
+
+        return output;
+    }
+
+    /**
+     * Format an XML document to a pretty-printable <code>String</code>.
+     * 
+     * @param input
+     *            The input XML document.
+     * @return The formatted <code>String</code>.
+     */
+    public static String format(Document input) {
+        StreamResult result = null;
+        try {
+            Transformer transformer = TransformerFactory.newInstance().newTransformer();
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+            result = new StreamResult(new StringWriter());
+            transformer.transform(new DOMSource(input), result);
+        } catch (Exception ex) {
+            LOGGER.error("Problem formatting DOM representation.", ex);
+            return null;
+        }
+
+        return result.getWriter().toString();
+    }
+
+    /**
+     * Format an XML <code>String</code> to a pretty-printable <code>String</code>.
+     * 
+     * @param input
+     *            The input XML <code>String</code>.
+     * @return The formatted <code>String</code>.
+     */
+    public static String format(String input) {
+        StreamResult result = null;
+        try {
+            Transformer transformer = TransformerFactory.newInstance().newTransformer();
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+            result = new StreamResult(new StringWriter());
+            transformer.transform(new StreamSource(input), result);
+        } catch (Exception ex) {
+            LOGGER.error("Problem formatting DOM representation.", ex);
+            return null;
+        }
+
+        return result.getWriter().toString();
+    }
+}


Property changes on: projects/migration_tool/trunk/src/main/java/org/jbpm/migration/util/XmlUtils.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: projects/migration_tool/trunk/src/main/resources/jpdl3-bpmn2.xsl
===================================================================
--- projects/migration_tool/trunk/src/main/resources/jpdl3-bpmn2.xsl	2010-11-02 22:45:50 UTC (rev 6790)
+++ projects/migration_tool/trunk/src/main/resources/jpdl3-bpmn2.xsl	2010-11-02 22:46:42 UTC (rev 6791)
@@ -3,21 +3,68 @@
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
     <xsl:template match="/process-definition">
-        <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
-            xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
-            xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
-            xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
-            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
+            xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             targetNamespace="http://www.jbpm.org/">
             <xsl:attribute name="name"> 
                 <xsl:value-of select="@name" />
             </xsl:attribute>
 
             <xsl:apply-templates />
+            <xsl:apply-templates select="//transition" />
 
         </definitions>
     </xsl:template>
 
+    <xsl:template match="//start-state">
+        <startEvent>
+            <xsl:attribute name="name">
+                <xsl:value-of select="@name" />
+            </xsl:attribute>
+            <xsl:attribute name="id">
+                <xsl:value-of select="@name" /><xsl:text>_id</xsl:text>
+            </xsl:attribute>
+        </startEvent>
+    </xsl:template>
+
+    <xsl:template match="//end-state">
+        <endEvent>
+            <xsl:attribute name="name">
+                <xsl:value-of select="@name" />
+            </xsl:attribute>
+            <xsl:attribute name="id">
+                <xsl:value-of select="@name" /><xsl:text>_id</xsl:text>
+            </xsl:attribute>
+        </endEvent>
+    </xsl:template>
+
+    <xsl:template match="//node">
+        <serviceTask>
+            <xsl:attribute name="name">
+                <xsl:value-of select="@name" />
+            </xsl:attribute>
+            <xsl:attribute name="id">
+                <xsl:value-of select="@name" /><xsl:text>_id</xsl:text>
+            </xsl:attribute>
+        </serviceTask>
+    </xsl:template>
+
+    <xsl:template match="//transition">
+        <sequenceFlow>
+            <xsl:attribute name="sourceRef">
+                <xsl:value-of select="../@name" /><xsl:text>_id</xsl:text>
+            </xsl:attribute>
+            <xsl:attribute name="targetRef">
+                <xsl:value-of select="@to" /><xsl:text>_id</xsl:text>
+            </xsl:attribute>
+        </sequenceFlow>
+    </xsl:template>
+
     <!-- TODO: Include templates for the missing jPDL elements. -->
 
+    <!-- Strip the white space from the result. -->
+    <xsl:template match="text()">
+        <xsl:value-of select="normalize-space()" />
+    </xsl:template>
+
 </xsl:stylesheet>

Added: projects/migration_tool/trunk/src/test/java/org/jbpm/migration/JpdlValidatorTest.java
===================================================================
--- projects/migration_tool/trunk/src/test/java/org/jbpm/migration/JpdlValidatorTest.java	                        (rev 0)
+++ projects/migration_tool/trunk/src/test/java/org/jbpm/migration/JpdlValidatorTest.java	2010-11-02 22:46:42 UTC (rev 6791)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.migration;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.w3c.dom.Document;
+
+/**
+ * Tests for the jDPL process definition validator.
+ * 
+ * @author Eric D. Schabell
+ * @author Maurice de Chateau
+ */
+public class JpdlValidatorTest {
+    @BeforeClass
+    public static void oneTimeSetUp() {
+        BasicConfigurator.configure();
+        Logger.getRootLogger().setLevel(Level.DEBUG);
+    }
+
+    @Test
+    public void validDefinition() throws Exception {
+        File jpdl = new File("src/test/resources/jpdl3/singleNode/processdefinition.xml");
+        File gpd = new File("src/test/resources/jpdl3/singleNode/gpd.xml");
+        Document document = JpdlValidator.validateDefinition(jpdl, gpd);
+        assertThat(document, is(notNullValue()));
+    }
+}


Property changes on: projects/migration_tool/trunk/src/test/java/org/jbpm/migration/JpdlValidatorTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: projects/migration_tool/trunk/src/test/java/org/jbpm/migration/ProcessTransformerTest.java
===================================================================
--- projects/migration_tool/trunk/src/test/java/org/jbpm/migration/ProcessTransformerTest.java	                        (rev 0)
+++ projects/migration_tool/trunk/src/test/java/org/jbpm/migration/ProcessTransformerTest.java	2010-11-02 22:46:42 UTC (rev 6791)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.migration;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jbpm.migration.util.XmlUtils;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.w3c.dom.Document;
+
+/**
+ * Tests for the jDPL process definition transformer.
+ * 
+ * @author Eric D. Schabell
+ * @author Maurice de Chateau
+ */
+public class ProcessTransformerTest {
+    @BeforeClass
+    public static void oneTimeSetUp() {
+        BasicConfigurator.configure();
+        Logger.getRootLogger().setLevel(Level.FATAL);
+    }
+
+    @Test
+    public void validDefinition() throws Exception {
+        File jpdlFile = new File("src/test/resources/jpdl3/singleNode/processdefinition.xml");
+        assertThat(jpdlFile.exists(), is(equalTo(true)));
+        Document jpdlDoc = XmlUtils.parseFile(jpdlFile);
+        assertThat(jpdlDoc, is(notNullValue()));
+        System.out.println("jPDL:\n" + XmlUtils.format(jpdlDoc));
+
+        Document bpmnDoc = ProcessTransformer.transform(jpdlDoc);
+        assertThat(bpmnDoc, is(notNullValue()));
+        System.out.println("BPMN:\n" + XmlUtils.format(bpmnDoc));
+        assertThat(BpmnValidator.validateDefinition(bpmnDoc), is(equalTo(true)));
+    }
+}


Property changes on: projects/migration_tool/trunk/src/test/java/org/jbpm/migration/ProcessTransformerTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: projects/migration_tool/trunk/src/test/java/test/XSLTTest.java
===================================================================
--- projects/migration_tool/trunk/src/test/java/test/XSLTTest.java	2010-11-02 22:45:50 UTC (rev 6790)
+++ projects/migration_tool/trunk/src/test/java/test/XSLTTest.java	2010-11-02 22:46:42 UTC (rev 6791)
@@ -23,7 +23,6 @@
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
-import org.apache.commons.lang.StringUtils;
 import org.junit.Before;
 import org.junit.Test;
 

Added: projects/migration_tool/trunk/src/test/resources/jpdl3/.gpd.jpdl-3.2.xml
===================================================================
--- projects/migration_tool/trunk/src/test/resources/jpdl3/.gpd.jpdl-3.2.xml	                        (rev 0)
+++ projects/migration_tool/trunk/src/test/resources/jpdl3/.gpd.jpdl-3.2.xml	2010-11-02 22:46:42 UTC (rev 6791)
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root-container name="Generated" width="856" height="396"/>


Property changes on: projects/migration_tool/trunk/src/test/resources/jpdl3/.gpd.jpdl-3.2.xml
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the jbpm-commits mailing list