KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > quartz > DefaultQuartzMarshaler


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.components.quartz;
18
19 import java.util.Iterator JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import javax.jbi.messaging.MessagingException;
23 import javax.jbi.messaging.NormalizedMessage;
24 import javax.xml.parsers.ParserConfigurationException JavaDoc;
25 import javax.xml.transform.dom.DOMSource JavaDoc;
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 JavaDoc;
34 import org.w3c.dom.Element JavaDoc;
35
36 /**
37  * The default implementation of the Quartz marshaler
38  *
39  * @version $Revision: 426415 $
40  */

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 JavaDoc iter = dataMap.entrySet().iterator(); iter.hasNext(); ) {
47             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iter.next();
48             String JavaDoc key = (String JavaDoc) entry.getKey();
49             if (!key.equals(QuartzComponent.COMPONENT_KEY)) {
50                 Object JavaDoc value = entry.getValue();
51                 message.setProperty(key, value);
52             }
53         }
54
55         try {
56             Document JavaDoc document = getTransformer().createDocument();
57             Element JavaDoc 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 JavaDoc(document));
66         }
67         catch (ParserConfigurationException JavaDoc e) {
68             throw new MessagingException("Failed to create content: " + e, e);
69         }
70     }
71
72 }
73
Popular Tags