1 10 11 package org.mule.providers.jbi.components; 12 13 import org.mule.umo.transformer.TransformerException; 14 import org.mule.umo.transformer.UMOTransformer; 15 16 import javax.jbi.messaging.InOnly; 17 import javax.jbi.messaging.InOut; 18 import javax.jbi.messaging.MessageExchange; 19 import javax.jbi.messaging.MessagingException; 20 import javax.jbi.messaging.NormalizedMessage; 21 import javax.xml.transform.Source ; 22 23 29 public class TransformerComponent extends AbstractJbiComponent 30 { 31 32 protected UMOTransformer transformer = null; 33 34 public void onMessage(MessageExchange messageExchange, NormalizedMessage message) 35 throws MessagingException 36 { 37 if (messageExchange.getRole() == MessageExchange.Role.PROVIDER) 38 { 39 return; 40 } 41 NormalizedMessage in = messageExchange.getMessage("in"); 42 43 try 44 { 45 NormalizedMessage out = messageExchange.createMessage(); 46 transform(messageExchange, in, out); 47 48 if (messageExchange instanceof InOut) 49 { 50 messageExchange.setMessage(out, OUT); 51 } 52 else 53 { 54 InOnly outExchange = exchangeFactory.createInOnlyExchange(); 55 outExchange.setInMessage(out); 56 deliveryChannel.sendSync(outExchange); 57 } 58 done(messageExchange); 59 } 60 catch (Exception e) 61 { 62 error(messageExchange, e); 63 } 64 } 65 66 protected void transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) 67 throws TransformerException, MessagingException 68 { 69 Object result = transformer.transform(in.getContent()); 70 if (result instanceof Source ) 71 { 72 out.setContent((Source )result); 73 } 74 else 75 { 76 throw new UnsupportedOperationException ( 77 "Support for Source transformation is not yet implemented"); 78 } 79 } 80 } 81 | Popular Tags |