1 17 package org.apache.servicemix.components.quartz; 18 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import javax.jbi.messaging.MessagingException; 23 import javax.jbi.messaging.NormalizedMessage; 24 import javax.xml.parsers.ParserConfigurationException ; 25 import javax.xml.transform.dom.DOMSource ; 26 27 import org.apache.servicemix.components.util.MarshalerSupport; 28 import org.apache.servicemix.jbi.util.DOMUtil; 29 import org.quartz.JobDataMap; 30 import org.quartz.JobDetail; 31 import org.quartz.JobExecutionContext; 32 import org.quartz.JobExecutionException; 33 import org.w3c.dom.Document ; 34 import org.w3c.dom.Element ; 35 36 41 public class DefaultQuartzMarshaler extends MarshalerSupport implements QuartzMarshaler { 42 43 public void populateNormalizedMessage(NormalizedMessage message, JobExecutionContext context) throws JobExecutionException, MessagingException { 44 JobDetail detail = context.getJobDetail(); 45 JobDataMap dataMap = detail.getJobDataMap(); 46 for (Iterator iter = dataMap.entrySet().iterator(); iter.hasNext(); ) { 47 Map.Entry entry = (Map.Entry ) iter.next(); 48 String key = (String ) entry.getKey(); 49 if (!key.equals(QuartzComponent.COMPONENT_KEY)) { 50 Object value = entry.getValue(); 51 message.setProperty(key, value); 52 } 53 } 54 55 try { 56 Document document = getTransformer().createDocument(); 57 Element root = document.createElement("timer"); 58 document.appendChild(root); 59 DOMUtil.addChildElement(root, "name", detail.getName()); 60 DOMUtil.addChildElement(root, "group", detail.getGroup()); 61 DOMUtil.addChildElement(root, "fullname", detail.getFullName()); 62 DOMUtil.addChildElement(root, "description", detail.getDescription()); 63 DOMUtil.addChildElement(root, "fireTime", context.getFireTime()); 64 65 message.setContent(new DOMSource (document)); 66 } 67 catch (ParserConfigurationException e) { 68 throw new MessagingException("Failed to create content: " + e, e); 69 } 70 } 71 72 } 73 | Popular Tags |