1 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 ; 23 24 28 public class ErrorHandlerTestDataGenerator 29 { 30 31 public static void generateTestData(String targetDir) throws IOException , 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 ("Some IO exception")); 42 BusinessException business = new BusinessException("Some business exception"); 43 44 ExceptionBean bean = new ExceptionBean(exception); 45 String xml = (String )trans.transform(bean); 46 FileUtils.stringToFile(targetDir + "MuleException.xml", xml); 47 48 bean = new ExceptionBean(fatal); 49 xml = (String )trans.transform(bean); 50 FileUtils.stringToFile(targetDir + "FatalException.xml", xml); 51 52 bean = new ExceptionBean(business); 53 xml = (String )trans.transform(bean); 54 FileUtils.stringToFile(targetDir + "BusinesException.xml", xml); 55 } 56 57 public static void main(String [] 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 path = args[0]; 66 try 67 { 68 generateTestData(path); 69 } 70 catch (Exception e) 71 { 72 e.printStackTrace(); 73 } 74 75 } 76 } 77 | Popular Tags |