1 10 11 package org.mule.components.simple; 12 13 import org.mule.umo.UMOEventContext; 14 import org.mule.umo.lifecycle.Callable; 15 import org.mule.umo.lifecycle.Initialisable; 16 import org.mule.umo.lifecycle.InitialisationException; 17 import org.mule.util.IOUtils; 18 19 import java.io.IOException ; 20 21 29 public class StaticComponent implements Callable, Initialisable 30 { 31 32 private Object data; 33 private String dataFile; 34 private String prefix; 35 private String postfix; 36 37 public void initialise() throws InitialisationException 38 { 39 if (dataFile != null) 40 { 41 try 42 { 43 data = IOUtils.getResourceAsString(dataFile, getClass()); 44 } 45 catch (IOException e) 46 { 47 throw new InitialisationException(e, this); 48 } 49 } 50 } 51 52 public Object getData() 53 { 54 return data; 55 } 56 57 public void setData(Object data) 58 { 59 this.data = data; 60 } 61 62 public String getDataFile() 63 { 64 return dataFile; 65 } 66 67 public void setDataFile(String dataFile) 68 { 69 this.dataFile = dataFile; 70 } 71 72 public String getPrefix() 73 { 74 return prefix; 75 } 76 77 public void setPrefix(String prefix) 78 { 79 this.prefix = prefix; 80 } 81 82 public String getPostfix() 83 { 84 return postfix; 85 } 86 87 public void setPostfix(String postfix) 88 { 89 this.postfix = postfix; 90 } 91 92 public Object onCall(UMOEventContext eventContext) throws Exception 93 { 94 95 if (data != null) 96 { 97 return data; 98 } 99 100 String eventData = eventContext.getTransformedMessageAsString(); 101 102 if (prefix != null) 103 { 104 eventData = prefix + eventData; 105 } 106 107 if (postfix != null) 108 { 109 eventData += postfix; 110 } 111 return eventData; 112 } 113 } 114 | Popular Tags |