1   /*
2    * $Id: ErrorHandlerTestDataGenerator.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.samples.errorhandler;
12  
13  import org.mule.MuleException;
14  import org.mule.config.i18n.MessageFactory;
15  import org.mule.samples.errorhandler.exceptions.BusinessException;
16  import org.mule.transformers.xml.ObjectToXml;
17  import org.mule.umo.lifecycle.FatalException;
18  import org.mule.umo.transformer.TransformerException;
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          MuleException exception = new MuleException(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 + "MuleException.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  }