Package org.servicemix.components.quartz

Source Code of org.servicemix.components.quartz.DefaultQuartzMarshaler

/**
*
* Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.servicemix.components.quartz;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobDetail;
import org.quartz.JobDataMap;
import org.servicemix.jbi.jaxp.StringSource;
import org.servicemix.jbi.util.DOMUtil;
import org.servicemix.components.util.MarshalerSupport;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import javax.jbi.messaging.NormalizedMessage;
import javax.jbi.messaging.MessagingException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.parsers.ParserConfigurationException;
import java.util.Iterator;
import java.util.Map;

/**
* The default implementation of the Quartz marshaler
*
* @version $Revision: 260 $
*/
public class DefaultQuartzMarshaler extends MarshalerSupport implements QuartzMarshaler {
    public static final String CONTEXT_KEY = "org.servicemix.quartz.context";
    public static final String DETAIL_KEY = "org.servicemix.quartz.detail";

    public void populateNormalizedMessage(NormalizedMessage message, JobExecutionContext context) throws JobExecutionException, MessagingException {
        message.setProperty(CONTEXT_KEY, context);
        JobDetail detail = context.getJobDetail();
        message.setProperty(DETAIL_KEY, detail);

        JobDataMap dataMap = detail.getJobDataMap();
        for (Iterator iter = dataMap.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry entry = (Map.Entry) iter.next();
            String key = (String) entry.getKey();
            Object value = entry.getValue();
            message.setProperty(key, value);
        }

        try {
            Document document = getTransformer().createDocument();
            Element root = document.createElement("timer");
            document.appendChild(root);
            DOMUtil.addChildElement(root, "name", detail.getName());
            DOMUtil.addChildElement(root, "group", detail.getGroup());
            DOMUtil.addChildElement(root, "fullname", detail.getFullName());
            DOMUtil.addChildElement(root, "description", detail.getDescription());
            DOMUtil.addChildElement(root, "fireTime", context.getFireTime());

            message.setContent(new DOMSource(document));
        }
        catch (ParserConfigurationException e) {
            throw new MessagingException("Failed to create content: " + e, e);
        }
    }

}
TOP

Related Classes of org.servicemix.components.quartz.DefaultQuartzMarshaler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.