KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > jpdl > xml > AbstractXmlTestCase


1 package org.jbpm.jpdl.xml;
2
3 import java.io.*;
4
5 import java.util.HashMap JavaDoc;
6
7 import junit.framework.*;
8
9 import org.dom4j.*;
10
11 import org.jbpm.graph.def.*;
12
13 public class AbstractXmlTestCase extends TestCase {
14     
15   // private static final String JPDL_NAMESPACE = "http://jbpm.org/3/jpdl";
16

17   static Element toXmlAndParse(ProcessDefinition processDefinition, String JavaDoc xpathExpression) throws Exception JavaDoc {
18     Element element = toXmlAndParse(processDefinition);
19     return (Element) element.selectSingleNode(xpathExpression);
20   }
21   
22   static Element toXmlAndParse(ProcessDefinition processDefinition, String JavaDoc xpathExpression, String JavaDoc namespace) throws Exception JavaDoc {
23         Element element = toXmlAndParseWithNamespace(processDefinition);
24         XPath xpath = DocumentHelper.createXPath(xpathExpression);
25         HashMap JavaDoc m = new HashMap JavaDoc();
26         m.put("", namespace);
27         
28         xpath.setNamespaceURIs( m );
29
30         return (Element) xpath.selectSingleNode( element );
31       }
32
33   static Element toXmlAndParse(ProcessDefinition processDefinition) throws Exception JavaDoc {
34     StringWriter stringWriter = new StringWriter();
35     JpdlXmlWriter jpdlWriter = new JpdlXmlWriter(stringWriter);
36     jpdlWriter.write( processDefinition );
37     String JavaDoc xml = stringWriter.toString();
38     return DocumentHelper.parseText( xml ).getRootElement();
39   }
40   
41   static Element toXmlAndParseWithNamespace(ProcessDefinition processDefinition) throws Exception JavaDoc {
42         StringWriter stringWriter = new StringWriter();
43         JpdlXmlWriter jpdlWriter = new JpdlXmlWriter(stringWriter);
44         jpdlWriter.setUseNamespace( true );
45         jpdlWriter.write( processDefinition );
46         String JavaDoc xml = stringWriter.toString();
47         return DocumentHelper.parseText( xml ).getRootElement();
48       }
49   
50   static void printXml(ProcessDefinition processDefinition) {
51     StringWriter stringWriter = new StringWriter();
52     JpdlXmlWriter jpdlWriter = new JpdlXmlWriter(stringWriter);
53     jpdlWriter.write( processDefinition );
54     System.out.println( stringWriter.toString() );
55   }
56 }
57
Popular Tags