001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.scheduler;
034:
035: import org.libresource.LibresourceException;
036:
037: import java.io.Serializable;
038:
039: import java.util.Enumeration;
040: import java.util.Hashtable;
041: import java.util.Iterator;
042: import java.util.Map;
043:
044: import javax.jms.JMSException;
045: import javax.jms.Message;
046:
047: /**
048: * LibreSource
049: *
050: * @author <a href="mailto:bort@loria.fr">Guillaume Bort </a>- <a
051: * href="http://www.inria.fr">INRIA Lorraine </a>
052: */
053: public class LibresourceJob implements Serializable {
054: public static final String TYPE_KEY = "__TYPE";
055: private String name;
056: private Map metaData;
057:
058: private LibresourceJob() {
059: }
060:
061: public LibresourceJob(String name, Map metaData)
062: throws LibresourceException {
063: this .name = name;
064: this .metaData = metaData;
065: }
066:
067: public void toMessage(Message message) throws JMSException {
068: message.setStringProperty("name", name);
069:
070: for (Iterator i = metaData.keySet().iterator(); i.hasNext();) {
071: String key = i.next().toString();
072: message.setStringProperty("metaData." + key, metaData.get(
073: key).toString());
074: }
075: }
076:
077: public static LibresourceJob toLibresourceJob(Message message)
078: throws Exception {
079: LibresourceJob job = new LibresourceJob();
080: job.name = message.getStringProperty("name");
081: job.metaData = new Hashtable();
082:
083: for (Enumeration e = message.getPropertyNames(); e
084: .hasMoreElements();) {
085: String property = e.nextElement().toString();
086:
087: if (property.startsWith("metaData.")) {
088: String key = property.substring(9);
089: String value = message.getStringProperty(property);
090: job.metaData.put(key, value);
091: }
092: }
093:
094: return job;
095: }
096:
097: public String getName() {
098: return name;
099: }
100:
101: public Map getMetaData() {
102: return metaData;
103: }
104: }
|