1 10 11 package org.mule.providers.xmpp.transformers; 12 13 import java.util.Iterator ; 14 15 import org.jivesoftware.smack.packet.Message; 16 import org.jivesoftware.smack.packet.XMPPError; 17 import org.mule.providers.xmpp.XmppConnector; 18 import org.mule.transformers.AbstractEventAwareTransformer; 19 import org.mule.umo.UMOEventContext; 20 import org.mule.umo.UMOException; 21 import org.mule.umo.UMOMessage; 22 import org.mule.umo.transformer.TransformerException; 23 24 30 public class ObjectToXmppPacket extends AbstractEventAwareTransformer 31 { 32 33 36 private static final long serialVersionUID = -815224066829254844L; 37 38 public ObjectToXmppPacket() 39 { 40 registerSourceType(String .class); 41 setReturnClass(Message.class); 42 } 43 44 public Object transform(Object src, String encoding, UMOEventContext context) throws TransformerException 45 { 46 Message result = null; 47 try 48 { 49 result = new Message(context.getMessageAsString(encoding)); 50 } 51 catch (UMOException e) 52 { 53 throw new TransformerException(this, e); 54 } 55 56 UMOMessage msg = context.getMessage(); 57 if (msg.getExceptionPayload() != null) 58 { 59 result.setError(new XMPPError(503, context.getMessage().getExceptionPayload().getMessage())); 60 } 61 62 for (Iterator iterator = msg.getPropertyNames().iterator(); iterator.hasNext();) 63 { 64 String name = (String )iterator.next(); 65 if (name.equals(XmppConnector.XMPP_THREAD)) 66 { 67 result.setThread((String )msg.getProperty(name)); 68 } 69 else if (name.equals(XmppConnector.XMPP_SUBJECT)) 70 { 71 result.setSubject((String )msg.getProperty(name)); 72 } 73 else if (name.equals(XmppConnector.XMPP_FROM)) 74 { 75 result.setFrom((String )msg.getProperty(name)); 76 } 77 else if (name.equals(XmppConnector.XMPP_TO)) 78 { 79 result.setTo((String )msg.getProperty(name)); 80 } 81 else 82 { 83 result.setProperty(name, msg.getProperty(name)); 84 } 85 } 86 return result; 87 } 88 89 } 90 | Popular Tags |