1
2
3
4
5
6
7
8
9
10
11 package org.mule.example.errorhandler;
12
13 import org.mule.api.DefaultMuleException;
14 import org.mule.api.lifecycle.FatalException;
15 import org.mule.api.transformer.TransformerException;
16 import org.mule.config.i18n.MessageFactory;
17 import org.mule.example.errorhandler.exceptions.BusinessException;
18 import org.mule.module.xml.transformer.ObjectToXml;
19 import org.mule.util.FileUtils;
20
21 import java.io.IOException;
22
23 public class ErrorHandlerTestDataGenerator
24 {
25
26 public static void generateTestData(String targetDir) throws IOException, TransformerException
27 {
28 if (!(targetDir.endsWith("/") || targetDir.endsWith("\\")))
29 {
30 targetDir += "/";
31 }
32
33 ObjectToXml trans = new ObjectToXml();
34 DefaultMuleException exception = new DefaultMuleException(MessageFactory.createStaticMessage("Some default exception"));
35 FatalException fatal = new FatalException(MessageFactory.createStaticMessage("Some fatal exception"),
36 new IOException("Some IO exception"));
37 BusinessException business = new BusinessException("Some business exception");
38
39 ExceptionBean bean = new ExceptionBean(exception);
40 String xml = (String)trans.transform(bean);
41 FileUtils.stringToFile(targetDir + "DefaultMuleException.xml", xml);
42
43 bean = new ExceptionBean(fatal);
44 xml = (String)trans.transform(bean);
45 FileUtils.stringToFile(targetDir + "FatalException.xml", xml);
46
47 bean = new ExceptionBean(business);
48 xml = (String)trans.transform(bean);
49 FileUtils.stringToFile(targetDir + "BusinesException.xml", xml);
50 }
51
52 public static void main(String[] args)
53 {
54
55 if (args.length == 0)
56 {
57 System.out.println("You must specifiy a target directory for the output files");
58 System.exit(1);
59 }
60 String path = args[0];
61 try
62 {
63 generateTestData(path);
64 }
65 catch (Exception e)
66 {
67 e.printStackTrace();
68 }
69
70 }
71 }