KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > test > samples > errorhandler > ErrorHandlerTestDataGenerator


1 /*
2  * $Id: ErrorHandlerTestDataGenerator.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.test.samples.errorhandler;
12
13 import org.mule.MuleException;
14 import org.mule.config.i18n.Message;
15 import org.mule.samples.errorhandler.ExceptionBean;
16 import org.mule.samples.errorhandler.exceptions.BusinessException;
17 import org.mule.transformers.xml.ObjectToXml;
18 import org.mule.umo.lifecycle.FatalException;
19 import org.mule.umo.transformer.TransformerException;
20 import org.mule.util.FileUtils;
21
22 import java.io.IOException JavaDoc;
23
24 /**
25  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
26  * @version $Revision: 3798 $
27  */

28 public class ErrorHandlerTestDataGenerator
29 {
30
31     public static void generateTestData(String JavaDoc targetDir) throws IOException JavaDoc, TransformerException
32     {
33         if (!(targetDir.endsWith("/") || targetDir.endsWith("\\")))
34         {
35             targetDir += "/";
36         }
37
38         ObjectToXml trans = new ObjectToXml();
39         MuleException exception = new MuleException(Message.createStaticMessage("Some default exception"));
40         FatalException fatal = new FatalException(Message.createStaticMessage("Some fatal exception"),
41             new IOException JavaDoc("Some IO exception"));
42         BusinessException business = new BusinessException("Some business exception");
43
44         ExceptionBean bean = new ExceptionBean(exception);
45         String JavaDoc xml = (String JavaDoc)trans.transform(bean);
46         FileUtils.stringToFile(targetDir + "MuleException.xml", xml);
47
48         bean = new ExceptionBean(fatal);
49         xml = (String JavaDoc)trans.transform(bean);
50         FileUtils.stringToFile(targetDir + "FatalException.xml", xml);
51
52         bean = new ExceptionBean(business);
53         xml = (String JavaDoc)trans.transform(bean);
54         FileUtils.stringToFile(targetDir + "BusinesException.xml", xml);
55     }
56
57     public static void main(String JavaDoc[] args)
58     {
59
60         if (args.length == 0)
61         {
62             System.out.println("You must specifiy a target directory for the output files");
63             System.exit(1);
64         }
65         String JavaDoc path = args[0];
66         try
67         {
68             generateTestData(path);
69         }
70         catch (Exception JavaDoc e)
71         {
72             e.printStackTrace();
73         }
74
75     }
76 }
77
Popular Tags