[esb-java-dev] svn commit r23649 - in branches/synapse: . modules/core modules/core/src/main/java/org/apache/synapse modules/core/src/main/java/org/apache/synapse/config modules/core/src/main/java/org/apache/synapse/config/xml modules/core/src/main/java/org/apache/synapse/core modules/core/src/main/java/org/apache/synapse/core/axis2 modules/core/src/main/java/org/apache/synapse/mediators/transform modules/core/src/main/java/org/apache/synapse/startup/quartz modules/core/src/main/java/org/apache/synapse/util modules/tasks modules/tasks/src modules/tasks/src/main modules/tasks/src/main/java modules/tasks/src/main/java/org modules/tasks/src/main/java/org/apache modules/tasks/src/main/java/org/apache/synapse modules/tasks/src/main/java/org/apache/synapse/task modules/tasks/src/main/java/org/apache/synapse/task/service modules/tasks/src/main/test modules/transports modules/utils modules/utils/src modules/utils/src/main modules/utils/src/main/java modules/utils/src/main/java/org modules/utils/src/main/java/org/apache modules/utils/src/main/java/org/apache/synapse modules/utils/src/main/java/org/apache/synapse/util modules/utils/src/test modules/utils/src/test/java modules/utils/src/test/java/org modules/utils/src/test/java/org/apache modules/utils/src/test/java/org/apache/synapse modules/utils/src/test/java/org/apache/synapse/util

indika at wso2.com indika at wso2.com
Mon Nov 10 23:33:31 PST 2008


Author: indika
Date: Mon Nov 10 23:33:31 2008
New Revision: 23649
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=23649

Log:
add synapse tasks , utiles from synapse trunck 


Added:
   branches/synapse/modules/tasks/
   branches/synapse/modules/tasks/pom.xml
   branches/synapse/modules/tasks/src/
   branches/synapse/modules/tasks/src/main/
   branches/synapse/modules/tasks/src/main/java/
   branches/synapse/modules/tasks/src/main/java/org/
   branches/synapse/modules/tasks/src/main/java/org/apache/
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskJobDetailFactory.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskTriggerFactory.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskException.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/Task.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescription.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionFactory.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepository.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepositoryFactory.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionSerializer.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskJobDetailFactory.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskSchedulerFactory.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskTriggerFactory.java
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/service/
   branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/service/TaskManagementService.java
   branches/synapse/modules/tasks/src/main/test/
   branches/synapse/modules/utils/
   branches/synapse/modules/utils/pom.xml
   branches/synapse/modules/utils/src/
   branches/synapse/modules/utils/src/main/
   branches/synapse/modules/utils/src/main/java/
   branches/synapse/modules/utils/src/main/java/org/
   branches/synapse/modules/utils/src/main/java/org/apache/
   branches/synapse/modules/utils/src/main/java/org/apache/synapse/
   branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/
   branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/PropertyHelper.java
   branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/SynapseUtilException.java
   branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/TemporaryData.java
   branches/synapse/modules/utils/src/test/
   branches/synapse/modules/utils/src/test/java/
   branches/synapse/modules/utils/src/test/java/org/
   branches/synapse/modules/utils/src/test/java/org/apache/
   branches/synapse/modules/utils/src/test/java/org/apache/synapse/
   branches/synapse/modules/utils/src/test/java/org/apache/synapse/util/
   branches/synapse/modules/utils/src/test/java/org/apache/synapse/util/TemporaryDataTest.java
Removed:
   branches/synapse/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyHelper.java
   branches/synapse/modules/core/src/main/java/org/apache/synapse/util/TemporaryData.java
Modified:
   branches/synapse/modules/core/pom.xml
   branches/synapse/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
   branches/synapse/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
   branches/synapse/modules/core/src/main/java/org/apache/synapse/config/xml/ClassMediatorFactory.java
   branches/synapse/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java
   branches/synapse/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
   branches/synapse/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
   branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
   branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java
   branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzJob.java
   branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java
   branches/synapse/modules/transports/pom.xml
   branches/synapse/pom.xml

Modified: branches/synapse/modules/core/pom.xml
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/core/pom.xml?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/core/pom.xml	(original)
+++ branches/synapse/modules/core/pom.xml	Mon Nov 10 23:33:31 2008
@@ -209,5 +209,13 @@
             <groupId>org.apache.synapse</groupId>
             <artifactId>synapse-transports</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.synapse</groupId>
+            <artifactId>synapse-utils</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.synapse</groupId>
+            <artifactId>synapse-tasks</artifactId>
+        </dependency>          
     </dependencies>
 </project>

Modified: branches/synapse/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java	(original)
+++ branches/synapse/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java	Mon Nov 10 23:33:31 2008
@@ -307,6 +307,10 @@
 
     public static final String DOING_FAIL_OVER = "synapse.doing.failover";
 
+    public static String SYNAPSE_STARTUP_TASK_SCHEDULER = "synapse.startup.taskscheduler";
+
+    public static String SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY = "synapse.startup.taskdescriptions.repository";
+
     // Known transport error codes
     public static final int RCV_IO_ERROR_SENDING     = 101000;
     public static final int RCV_IO_ERROR_RECEIVING   = 101001;

Modified: branches/synapse/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java	(original)
+++ branches/synapse/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java	Mon Nov 10 23:33:31 2008
@@ -25,8 +25,9 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.*;
+import org.apache.synapse.task.TaskDescriptionRepository;
+import org.apache.synapse.task.TaskDescriptionRepositoryFactory;
 import org.apache.synapse.config.xml.MediatorFactoryFinder;
-import org.apache.synapse.config.xml.SwitchCase;
 import org.apache.synapse.config.xml.endpoints.XMLToEndpointMapper;
 import org.apache.synapse.core.SynapseEnvironment;
 import org.apache.synapse.core.axis2.ProxyService;
@@ -34,13 +35,6 @@
 import org.apache.synapse.mediators.base.SequenceMediator;
 import org.apache.synapse.mediators.ListMediator;
 import org.apache.synapse.mediators.AbstractMediator;
-import org.apache.synapse.mediators.eip.splitter.CloneMediator;
-import org.apache.synapse.mediators.eip.splitter.IterateMediator;
-import org.apache.synapse.mediators.eip.Target;
-import org.apache.synapse.mediators.eip.aggregator.AggregateMediator;
-import org.apache.synapse.mediators.filters.SwitchMediator;
-import org.apache.synapse.mediators.builtin.SendMediator;
-import org.apache.synapse.mediators.builtin.CacheMediator;
 import org.apache.synapse.registry.Registry;
 
 import javax.xml.namespace.QName;
@@ -100,8 +94,12 @@
 
     /** Hold reference to the Axis2 ConfigurationContext */
 	private AxisConfiguration axisConfiguration = null;
+    
+    private final TaskDescriptionRepository repository = 
+            TaskDescriptionRepositoryFactory.getTaskDescriptionRepository(
+                    SynapseConstants.SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY);
 
-	/**
+    /**
 	 * Save the path to the configuration file loaded, to save it later if
 	 * required
 	 */
@@ -836,6 +834,10 @@
                 if (p.getTargetInLineOutSequence() != null) {
                     p.getTargetInLineOutSequence().init(se);
                 }
+                
+                if (p.getTargetInLineFaultSequence() != null) {
+                    p.getTargetInLineFaultSequence().init(se);
+                }
         }
 
         // initialize managed mediators
@@ -897,4 +899,8 @@
 		log.error(msg);
 		throw new SynapseException(msg);
 	}
+
+    public TaskDescriptionRepository getTaskDescriptionRepository() {
+        return repository;
+    }
 }

Modified: branches/synapse/modules/core/src/main/java/org/apache/synapse/config/xml/ClassMediatorFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/core/src/main/java/org/apache/synapse/config/xml/ClassMediatorFactory.java?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/core/src/main/java/org/apache/synapse/config/xml/ClassMediatorFactory.java	(original)
+++ branches/synapse/modules/core/src/main/java/org/apache/synapse/config/xml/ClassMediatorFactory.java	Mon Nov 10 23:33:31 2008
@@ -22,10 +22,9 @@
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNode;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.Mediator;
 import org.apache.synapse.SynapseException;
+import org.apache.synapse.util.PropertyHelper;
 import org.apache.synapse.mediators.ext.ClassMediator;
 
 import javax.xml.namespace.QName;

Deleted: branches/synapse/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyHelper.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=23648

Modified: branches/synapse/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java	(original)
+++ branches/synapse/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java	Mon Nov 10 23:33:31 2008
@@ -20,9 +20,10 @@
 package org.apache.synapse.core;
 
 import org.apache.synapse.MessageContext;
+import org.apache.synapse.statistics.StatisticsCollector;
+import org.apache.synapse.config.SynapseConfiguration;
 import org.apache.synapse.endpoints.EndpointDefinition;
 import org.apache.synapse.mediators.base.SequenceMediator;
-import org.apache.synapse.statistics.StatisticsCollector;
 import org.apache.synapse.util.TemporaryData;
 
 import java.util.concurrent.ExecutorService;
@@ -102,13 +103,22 @@
 
     /**
      * Has the Synapse Environment properly initialized?
+     * 
      * @return true if the environment is ready for processing
      */
     public boolean isInitialized();
 
     /**
      * Set the environment as ready for message processing
+     * 
      * @param state true means ready for processing
      */
     public void setInitialized(boolean state);
+
+    /**
+     * Retrieves the {@link SynapseConfiguration} from the <code>environment</code>
+     * 
+     * @return configuration of the synapse
+     */
+    public SynapseConfiguration getSynapseConfiguration();
 }

Modified: branches/synapse/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java	(original)
+++ branches/synapse/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java	Mon Nov 10 23:33:31 2008
@@ -338,6 +338,15 @@
     }
 
     /**
+     * Retrieves the {@link SynapseConfiguration} from the <code>environment</code>
+     *
+     * @return synapseConfig associated with the environment
+     */
+    public SynapseConfiguration getSynapseConfiguration() {
+        return this.synapseConfig;
+    }
+    
+    /**
      * Mark this environment as ready for processing
      * @param state true means ready for processing
      */

Modified: branches/synapse/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java	(original)
+++ branches/synapse/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java	Mon Nov 10 23:33:31 2008
@@ -40,8 +40,8 @@
 import org.apache.synapse.mediators.MediatorProperty;
 import org.apache.synapse.util.xpath.SynapseXPath;
 import org.apache.synapse.util.AXIOMUtils;
-import org.apache.synapse.util.TemporaryData;
 import org.apache.synapse.util.TextFileDataSource;
+import org.apache.synapse.util.TemporaryData;
 import org.jaxen.JaxenException;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;

Modified: branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java	(original)
+++ branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java	Mon Nov 10 23:33:31 2008
@@ -21,29 +21,18 @@
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Random;
-import java.util.Set;
+import java.util.*;
 
 import javax.xml.namespace.QName;
 
-import org.apache.axiom.om.OMElement;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.core.SynapseEnvironment;
-import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.ServerManager;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.task.*;
 import org.apache.synapse.startup.AbstractStartup;
-import org.quartz.CronTrigger;
-import org.quartz.JobDataMap;
-import org.quartz.JobDetail;
-import org.quartz.Scheduler;
-import org.quartz.SchedulerException;
-import org.quartz.Trigger;
-import org.quartz.TriggerUtils;
-import org.quartz.impl.DirectSchedulerFactory;
 
 /*
  * This class is instantiated by SimpleQuartzFactory (or by hand)
@@ -55,117 +44,91 @@
 public class SimpleQuartz extends AbstractStartup {
 
     private static final Log log = LogFactory.getLog(SimpleQuartz.class);
-    private static final int THREADPOOLSIZE = 5;
 
-    static {
-      try {
-        DirectSchedulerFactory.getInstance().createVolatileScheduler(THREADPOOLSIZE);
-      } catch (SchedulerException e) {
-        throw new SynapseException("Error initializing scheduler factory", e);
-      }
-    }
-    
-    private String cron;
-    private int repeatCount = -1;
-    private long repeatInterval; // in milliseconds
-    private String className;
-    private List pinnedServers;
-    private Scheduler sch;
-    Set xmlProperties = new HashSet();
+    private TaskDescription taskDescription;
+
+    private TaskDescriptionRepository repository;
+  
 
     public QName getTagQName() {
         return SimpleQuartzFactory.TASK;
     }
 
     public void destroy() {
-        if (sch != null) {
-            try {
-                sch.shutdown();
-            } catch (SchedulerException e) {
-                log.warn("Error shutting down scheduler", e);
-                throw new SynapseException("Error shutting down scheduler", e);
-            }
+
+        TaskScheduler taskScheduler = TaskSchedulerFactory.getTaskScheduler(
+                SynapseConstants.SYNAPSE_STARTUP_TASK_SCHEDULER);
+        if (taskScheduler != null && taskScheduler.isInitialized()) {
+            taskScheduler.shutDown();
+        }
+       
+        if (repository != null && taskDescription != null) {
+            repository.removeTaskDescription(taskDescription.getName());
         }
     }
 
     public void init(SynapseEnvironment synapseEnvironment) {
 
+        if (taskDescription == null ) {
+            handleException("TaskDescription is null");
+        }
+
+        repository = synapseEnvironment.getSynapseConfiguration().getTaskDescriptionRepository();
+       
+        if (repository == null) {
+            handleException("Task Description Repository can not found");
+        }
+       
+        repository.addTaskDescription(taskDescription);
+       
         // this server name given by system property SynapseServerName
         // otherwise take host-name
         // else assume localhost
         String thisServerName = ServerManager.getInstance().getServerName();
-        if(thisServerName == null || thisServerName.equals("")) {
-          try {
-            InetAddress addr = InetAddress.getLocalHost();
-            thisServerName = addr.getHostName();
-  
-          } catch (UnknownHostException e) {
-            log.warn("Could not get local host name", e);
-          }
-          
-          if(thisServerName == null || thisServerName.equals("")) {
-            thisServerName = "localhost";
-          }
+        if (thisServerName == null || thisServerName.equals("")) {
+            try {
+                InetAddress addr = InetAddress.getLocalHost();
+                thisServerName = addr.getHostName();
+
+            } catch (UnknownHostException e) {
+                log.warn("Could not get local host name", e);
+            }
+
+            if (thisServerName == null || thisServerName.equals("")) {
+                thisServerName = "localhost";
+            }
         }
         log.debug("Synapse server name : " + thisServerName);
-        
+
         // start proxy service if either,
         // pinned server name list is empty
         // or pinned server list has this server name
-        List pinnedServers = getPinnedServers();
-        if(pinnedServers != null && !pinnedServers.isEmpty()) {
-          if(!pinnedServers.contains(thisServerName)) {
-            log.info("Server name not in pinned servers list. Not starting Task : " + getName());
-            return;
-          }
+        List pinnedServers = taskDescription.getPinnedServers();
+        if (pinnedServers != null && !pinnedServers.isEmpty()) {
+            if (!pinnedServers.contains(thisServerName)) {
+                log.info("Server name not in pinned servers list. Not starting Task : " + getName());
+                return;
+            }
         }
-      
-      
+
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put(SimpleQuartzJob.SYNAPSE_ENVIRONMENT, synapseEnvironment);
+
         try {
-            sch = DirectSchedulerFactory.getInstance().getScheduler();
-            if (sch == null) {
-              DirectSchedulerFactory.getInstance().createVolatileScheduler(THREADPOOLSIZE);
-              sch = DirectSchedulerFactory.getInstance().getScheduler();
-            }
-            
-            if(sch == null) {
-              throw new NullPointerException("Scheduler is null");
-            }
 
-            Trigger trigger = null;
-            if (cron == null) {
-                if (repeatCount >= 0) {
-                    trigger = TriggerUtils.makeImmediateTrigger(repeatCount - 1, repeatInterval);
-                } else {
-                    trigger = TriggerUtils.makeImmediateTrigger(-1, repeatInterval);
+            TaskScheduler taskScheduler = TaskSchedulerFactory.getTaskScheduler(SynapseConstants.SYNAPSE_STARTUP_TASK_SCHEDULER);
+            if (taskScheduler != null) {
+                if (!taskScheduler.isInitialized()) {
+                    taskScheduler.init(synapseEnvironment.getSynapseConfiguration().getProperties());
                 }
-
+                taskScheduler.scheduleTask(taskDescription, map, SimpleQuartzJob.class);
             } else {
-                CronTrigger cronTrig = new CronTrigger();
-                cronTrig.setCronExpression(cron);
-                trigger = cronTrig;
+                if (log.isDebugEnabled()) {
+                    log.debug("TaskScheduler cannot be found for :" + SynapseConstants.SYNAPSE_STARTUP_TASK_SCHEDULER + " , " +
+                            "therefore ignore scheduling of Task  " + taskDescription);
+                }
             }
 
-            // give the trigger a random name
-            trigger.setName("Trigger" + String.valueOf((new Random()).nextLong()));
-            trigger.setGroup("synapse.simple.quartz");
-            trigger.setVolatility(true);
-            JobDetail jobDetail = new JobDetail();
-
-            // Give the job a name
-            jobDetail.setName(name);
-            jobDetail.setGroup("synapse.simple.quartz");
-            jobDetail.setJobClass(SimpleQuartzJob.class);
-            JobDataMap jdm = new JobDataMap();
-            jdm.put(SimpleQuartzJob.SYNAPSE_ENVIRONMENT, synapseEnvironment);
-            jdm.put(SimpleQuartzJob.CLASSNAME, className);
-            jdm.put(SimpleQuartzJob.PROPERTIES, xmlProperties);
-            jobDetail.setJobDataMap(jdm);
-
-            sch.scheduleJob(jobDetail, trigger);
-            sch.start();
-            log.info("Scheduled job " + jobDetail.getFullName() + " for class " + className);
-
         } catch (Exception e) {
             log.fatal("Error starting up Scheduler", e);
             throw new SynapseException("Error starting up Scheduler", e);
@@ -173,55 +136,16 @@
 
     }
 
-    public String getJobClass() {
-        return className;
-    }
-
-    public void setJobClass(String attributeValue) {
-        className = attributeValue;
-
-    }
-
-    public void setInterval(long l) {
-        repeatInterval = l;
-
-    }
-
-    public long getInterval() {
-        return repeatInterval;
-    }
-
-    public void setCount(int i) {
-        repeatCount = i;
+    public TaskDescription getTaskDescription() {
+        return taskDescription;
     }
 
-    public int getCount() {
-        return repeatCount;
+    public void setTaskDescription(TaskDescription taskDescription) {
+        this.taskDescription = taskDescription;
     }
 
-    public void addProperty(OMElement prop) {
-        xmlProperties.add(prop);
+    private static void handleException(String message) {
+        log.error(message);
+        throw new SynapseException(message);
     }
-
-    public Set getProperties() {
-        return xmlProperties;
-    }
-
-    public void setCron(String attributeValue) {
-        cron = attributeValue;
-
-    }
-
-    public String getCron() {
-        return cron;
-    }
-
-    public List getPinnedServers() {
-      return pinnedServers;
-    }
-
-    public void setPinnedServers(List pinnedServers) {
-      this.pinnedServers = pinnedServers;
-    }
-
 }

Modified: branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java	(original)
+++ branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java	Mon Nov 10 23:33:31 2008
@@ -19,22 +19,20 @@
 
 package org.apache.synapse.startup.quartz;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-
 import javax.xml.namespace.QName;
 
-import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.config.xml.XMLConfigConstants;
-import org.apache.synapse.config.xml.PropertyHelper;
 import org.apache.synapse.config.xml.StartupFactory;
 import org.apache.synapse.Startup;
 import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.task.TaskDescription;
+import org.apache.synapse.task.TaskDescriptionFactory;
+import org.apache.synapse.task.TaskDescriptionRepositoryFactory;
+import org.apache.synapse.task.TaskDescriptionRepository;
 
 /**
  * &lt;task class="org.my.synapse.Task" name="string"&gt;
@@ -50,12 +48,6 @@
     public final static QName TASK
         = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "task");
 
-    private final static QName TRIGGER
-        = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "trigger");
-
-    private final static QName PROPERTY
-        = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "property");
-
     private final static Log log = LogFactory.getLog(SimpleQuartzFactory.class);
 
     public Startup createStartup(OMElement el) {
@@ -66,128 +58,28 @@
         
         if (el.getQName().equals(TASK)) {
             
-            SimpleQuartz q = new SimpleQuartz();
-
-            String name = el.getAttributeValue(
-                new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
-            if (name != null) {
-                q.setName(name);
-            } else {
-                handleException("Name for a task is required, missing name in the task");
-            }
-
-            // set the task class
-            OMAttribute classAttr = el.getAttribute(new QName("class"));
-            if (classAttr != null && classAttr.getAttributeValue() != null) {
-                String classname = classAttr.getAttributeValue();
-                try {
-                    Class.forName(classname).newInstance();
-                } catch (Exception e) {
-                    handleException("Failed to load task class " + classname, e);
-                }
-                q.setJobClass(classname);
-            } else {
-                handleException("Syntax error in the Task : no task class specified");
-            }
-            
-            // set pinned server list
-            OMAttribute pinnedServers = el.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "pinnedServers"));
-            if (pinnedServers != null) {
-                String pinnedServersValue = pinnedServers.getAttributeValue();
-                if (pinnedServersValue == null) {
-                    // default to all servers
-                } else {
-                    StringTokenizer st = new StringTokenizer(pinnedServersValue, " ,");
-                    List pinnedServersList = new ArrayList();
-                    while (st.hasMoreTokens()) {
-                        String token = st.nextToken();
-                        if (token.length() != 0) {
-                          pinnedServersList.add(token);
-                        }
-                    }
-                    q.setPinnedServers(pinnedServersList);
-                }
-            }
-
-            // next sort out the property children
-            Iterator it = el.getChildrenWithName(PROPERTY);
-            while (it.hasNext()) {
-                OMElement prop = (OMElement) it.next();
-                if (PropertyHelper.isStaticProperty(prop)) {
-                    q.addProperty(prop);
-                } else {
-                    handleException("Tasks does not support dynamic properties");
-                }
-            }
-
-            // setting the trigger to the task
-            OMElement trigger = el.getFirstChildWithName(TRIGGER);
-            if (trigger != null) {
-
-                OMAttribute count = trigger.getAttribute(new QName("count"));
-                if (count != null) {
-                    try {
-                        q.setCount(Integer.parseInt(count.getAttributeValue()));
-                    } catch (Exception e) {
-                        handleException("Failed to parse trigger count as an integer", e);
-                    }
-                }
-
-                OMAttribute once = trigger.getAttribute(new QName("once"));
-                if (once != null && Boolean.TRUE.toString().equals(once.getAttributeValue())) {
-                    q.setCount(1);
-                    q.setInterval(1);
-                }
-
-                OMAttribute repeatInterval = trigger.getAttribute(new QName("interval"));
-                if (repeatInterval == null && q.getCount() > 1) {
-                    handleException("Trigger seems to be " +
-                        "a simple trigger, but no interval specified");
-                } else if (repeatInterval != null && repeatInterval.getAttributeValue() != null) {
-                    try {
-                        long repeatIntervalInSeconds = Long.parseLong(repeatInterval.getAttributeValue());
-                        long repeatIntervalInMillis = repeatIntervalInSeconds * 1000;
-                        q.setInterval(repeatIntervalInMillis);
-                    } catch (Exception e) {
-                        handleException("Failed to parse trigger interval as a long value", e);
-                    }
-                }
-
-                OMAttribute expr = trigger.getAttribute(new QName("cron"));
-                if (expr == null && q.getInterval() == 0) {
-                    q.setCount(1);
-                    q.setInterval(1);
-                } else if (expr != null && q.getInterval() > 0) {
-                    handleException("Trigger syntax error : " +
-                        "both cron and simple trigger attributes are present");
-                } else if (expr != null && expr.getAttributeValue() != null) {
-                    q.setCron(expr.getAttributeValue());
-                }
-
-            } else {
-                q.setCount(1);
-                q.setInterval(1);
-            }
-
-            return q;
+            SimpleQuartz simpleQuartz = new SimpleQuartz();
+            TaskDescription taskDescription =
+                    TaskDescriptionFactory.createTaskDescription(el, SynapseConstants.SYNAPSE_OMNAMESPACE);
+            if(taskDescription == null){
+                handleException("Invalid task - Task description can not be created  form :"+el);
+            }          
+            simpleQuartz.setName(taskDescription.getName());
+            simpleQuartz.setTaskDescription(taskDescription);
+            return simpleQuartz;
         } else {
             handleException("Syntax error in the task : wrong QName for the task");
             return null;
         }
     }
 
-    public Class getSerializerClass() {
+    public Class<SimpleQuartzSerializer> getSerializerClass() {
         return SimpleQuartzSerializer.class;
     }
 
     public QName getTagQName() {
         return TASK;
-    }
-
-    private void handleException(String message, Exception e) {
-        log.error(message);
-        throw new SynapseException(message, e);
-    }
+    }  
 
     private void handleException(String message) {
         log.error(message);

Modified: branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzJob.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzJob.java?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzJob.java	(original)
+++ branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzJob.java	Mon Nov 10 23:33:31 2008
@@ -1,30 +1,34 @@
 package org.apache.synapse.startup.quartz;
 
-import java.util.Iterator;
-import java.util.Set;
-
 import org.apache.axiom.om.OMElement;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.ManagedLifecycle;
-import org.apache.synapse.startup.Task;
-import org.apache.synapse.config.xml.PropertyHelper;
+import org.apache.synapse.util.PropertyHelper;
+import org.apache.synapse.task.Task;
+
 import org.apache.synapse.core.SynapseEnvironment;
 import org.quartz.Job;
 import org.quartz.JobDataMap;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 
+import java.util.Set;
+
 public class SimpleQuartzJob implements Job {
-    public static final String
-        SYNAPSE_ENVIRONMENT = "SynapseEnvironment",
-        CLASSNAME = "ClassName",
-        PROPERTIES = "Properties";
+    
+    public static final String SYNAPSE_ENVIRONMENT = "SynapseEnvironment";
+    public static final String CLASSNAME = "ClassName";
+    public static final String PROPERTIES = "Properties";
+
     private static final Log log = LogFactory.getLog(SimpleQuartzJob.class);
 
     public void execute(JobExecutionContext ctx) throws JobExecutionException {
 
-        log.debug("Executing task : " + ctx.getJobDetail().getFullName());
+        String jobName = ctx.getJobDetail().getFullName();
+        if (log.isDebugEnabled()) {
+            log.debug("Executing task : " + jobName);
+        }
         JobDataMap jdm = ctx.getMergedJobDataMap();
         String jobClassName = (String) jdm.get(CLASSNAME);
         if (jobClassName == null) {
@@ -39,23 +43,27 @@
         }
 
         Set properties = (Set) jdm.get(PROPERTIES);
-        Iterator it = properties.iterator();
-        while (it.hasNext()) {
-            OMElement prop = (OMElement) it.next();
+        for (Object property : properties) {
+            OMElement prop = (OMElement) property;
             log.debug("Found Property : " + prop.toString());
             PropertyHelper.setStaticProperty(prop, task);
         }
 
+        // 1. Initialize
         SynapseEnvironment se = (SynapseEnvironment) jdm.get("SynapseEnvironment");
-        if (task instanceof ManagedLifecycle) {
-            if (se != null) {
-                ((ManagedLifecycle) task).init(se);
-            }
+        if (task instanceof ManagedLifecycle && se != null) {
+            ((ManagedLifecycle) task).init(se);
         }
 
-        if (se.isInitialized()) {
+        // 2. Execute
+        if (se != null && task != null && se.isInitialized()) {
             task.execute();
         }
+
+        // 3. Destroy
+        if (task instanceof ManagedLifecycle && se != null) {
+            ((ManagedLifecycle) task).destroy();
+        }
     }
 
     private void handleException(String msg) throws JobExecutionException {

Modified: branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java	(original)
+++ branches/synapse/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java	Mon Nov 10 23:33:31 2008
@@ -19,29 +19,18 @@
 
 package org.apache.synapse.startup.quartz;
 
-import java.util.List;
-
-import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
 import org.apache.synapse.Startup;
 import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.task.TaskDescription;
+import org.apache.synapse.task.TaskDescriptionSerializer;
+import org.apache.synapse.task.TaskDescriptionRepository;
+import org.apache.synapse.task.TaskDescriptionRepositoryFactory;
 import org.apache.synapse.config.xml.StartupSerializer;
-import org.apache.synapse.config.xml.XMLConfigConstants;
-
-import javax.xml.namespace.QName;
 
 public class SimpleQuartzSerializer implements StartupSerializer {
 
-    protected static final OMFactory fac = OMAbstractFactory.getOMFactory();
-    protected static final OMNamespace synNS
-        = fac.createOMNamespace(XMLConfigConstants.SYNAPSE_NAMESPACE, "syn");
-    protected static final OMNamespace nullNS
-        = fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
-    protected static final QName PROP_Q
-        = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "property", "syn");
-
     public OMElement serializeStartup(OMElement parent, Startup s) {
 
         if (!(s instanceof SimpleQuartz)) {
@@ -50,42 +39,22 @@
         }
 
         SimpleQuartz sq = (SimpleQuartz) s;
-
-        OMElement task = fac.createOMElement("task", synNS, parent);
-        task.addAttribute("name", sq.getName(), nullNS);
-        task.addAttribute("class", sq.getJobClass(), nullNS);
-
-        List pinnedServers = sq.getPinnedServers();
-        if (pinnedServers != null && !pinnedServers.isEmpty()) {
-          String pinnedServersStr = "" + pinnedServers.get(0);
-          for (int i = 1; i < pinnedServers.size(); i++) {
-            pinnedServersStr = pinnedServersStr + " " + pinnedServers.get(i);
-          }
-          task.addAttribute(fac.createOMAttribute("pinnedServers", nullNS, pinnedServersStr));
-        }
         
-        OMElement el = fac.createOMElement("trigger", synNS, task);
-        if (sq.getInterval() == 1 && sq.getCount() == 1) {
-            el.addAttribute("once", "true", nullNS);
-        } else if (sq.getCron() != null) {
-            el.addAttribute("cron", sq.getCron(), nullNS);
-        } else {
-            if (sq.getCount() != -1) {
-                el.addAttribute("count", Integer.toString(sq.getCount()), nullNS);
-            }
+        TaskDescription taskDescription = sq.getTaskDescription();
 
-            if (sq.getInterval() != 0) {
-                long interval = sq.getInterval() / 1000;
-                el.addAttribute("interval", Long.toString(interval), nullNS);
+        if (taskDescription != null) {
+            OMElement task = TaskDescriptionSerializer.serializeTaskDescription(
+                    SynapseConstants.SYNAPSE_OMNAMESPACE, taskDescription);
+            if (task == null) {
+                throw new SynapseException("Task Element can not be null.");
             }
+            if (parent != null) {
+                parent.addChild(task);
+            }
+            return task;
+        } else {
+            throw new SynapseException("Task Description is null");
         }
-        
-        for (Object o : sq.getProperties()) {
-            OMElement prop = (OMElement) o;
-            task.addChild(prop.cloneOMElement());
-        }
-
-        return task;
     }
 
 }

Deleted: branches/synapse/modules/core/src/main/java/org/apache/synapse/util/TemporaryData.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=23648

Added: branches/synapse/modules/tasks/pom.xml
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/pom.xml?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/pom.xml	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~  Licensed to the Apache Software Foundation (ASF) under one
+  ~  or more contributor license agreements.  See the NOTICE file
+  ~  distributed with this work for additional information
+  ~  regarding copyright ownership.  The ASF licenses this file
+  ~  to you 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.
+  -->
+
+<project
+        xmlns="http://maven.apache.org/POM/4.0.0"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.synapse</groupId>
+        <artifactId>Apache-Synapse</artifactId>
+        <version>1.2.wso2v1</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.synapse</groupId>
+    <artifactId>synapse-tasks</artifactId>
+
+    <name>Apache Synapse - Tasks classes</name>
+    <description>Apache Synapse - Tasks classes</description>
+    <packaging>bundle</packaging>
+
+    <build>
+        <plugins>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.2</version>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>1.4.0</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Version>1.3.0</Bundle-Version>
+                        <Bundle-Name>org.apache.synapse.task</Bundle-Name>
+                        <Bundle-Vendor>Apache Software Foundation</Bundle-Vendor>
+                        <Bundle-Description>${pom.description}</Bundle-Description>
+                        <Bundle-SymbolicName>org.apache.synapse.tasks</Bundle-SymbolicName>
+                        <Export-Package>
+                            org.apache.synapse.task.*;-split-package:=merge-last,
+                        </Export-Package>
+                        <Import-Package>
+                            !javax.xml.namespace,                                                      
+                            org.apache.axiom.*,  
+                            org.apache.commons.logging,
+                            org.apache.log4j,
+                            javax.xml.namespace; version=0.0.0,      
+                            org.apache.synapse.utils.*,
+                            org.apache.commons.io.*,
+                            org.quartz.*,
+                            javax.transaction.*,
+                            org.apache.axiom.*,
+                            org.apache.commons.collections.*,
+                            *;resolution:=optional,
+                        </Import-Package>
+                        <DynamicImport-Package>*</DynamicImport-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.synapse</groupId>
+            <artifactId>synapse-utils</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.opensymphony</groupId>
+            <artifactId>quartz</artifactId>
+            <version>${quartz.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jta_1.1_spec</artifactId>
+            <version>${geronimo-spec.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-collections</groupId>
+            <artifactId>commons-collections</artifactId>
+            <version>${commons-collections.version}</version>
+        </dependency>
+    </dependencies>
+    <properties>
+        <!-- startup, quartz -->
+        <commons-collections.version>3.1</commons-collections.version>
+        <quartz.version>1.6.0</quartz.version>
+        <geronimo-spec.version>1.1</geronimo-spec.version>
+    </properties>
+</project>

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskJobDetailFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskJobDetailFactory.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskJobDetailFactory.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,87 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.Job;
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Default JobDetailFactory ships with synapse utils
+ */
+public class DefaultTaskJobDetailFactory implements TaskJobDetailFactory {
+
+    private static final Log log = LogFactory.getLog(DefaultTaskJobDetailFactory.class);
+
+    /**
+     * @see TaskJobDetailFactory
+     */
+    public JobDetail createJobDetail(TaskDescription taskDescription, Map<String, Object> resources, Class<Job> jobClass) {
+
+        if (taskDescription == null) {
+            throw new SynapseTaskException("Task Description cannot be found.", log);
+        }
+
+        if (jobClass == null) {
+            throw new SynapseTaskException("Job Class cannot be found.", log);
+        }
+
+        if (resources == null) {
+            resources = new HashMap<String, Object>();
+        }
+
+        JobDetail jobDetail = new JobDetail();
+        jobDetail.setJobClass(jobClass);
+
+        String name = taskDescription.getName();
+        if (name == null || "".equals(name)) {
+            throw new SynapseTaskException("Name cannot be found.", log);
+        }
+        jobDetail.setName(name);
+
+
+        String group = taskDescription.getGroup();
+        if (group != null && !"".equals(group)) {
+            jobDetail.setGroup(group);
+        } else {
+            jobDetail.setGroup(TaskDescription.DEFAULT_GROUP);
+        }
+
+        JobDataMap jobDataMap = new JobDataMap(resources);
+
+        String className = taskDescription.getTaskClass();
+        if (className != null && !"".equals(className)) {
+            jobDataMap.put(TaskDescription.CLASSNAME, className);
+        }
+
+        Set xmlProperties = taskDescription.getProperties();
+        if (xmlProperties != null) {
+            jobDataMap.put(TaskDescription.PROPERTIES, xmlProperties);
+        }
+        jobDetail.setJobDataMap(jobDataMap);
+
+        return jobDetail;
+    }
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskTriggerFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskTriggerFactory.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/DefaultTaskTriggerFactory.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,93 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.CronTrigger;
+import org.quartz.SimpleTrigger;
+import org.quartz.Trigger;
+import org.quartz.TriggerUtils;
+
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Random;
+
+/**
+ * Default TriggerFactory ship with synapse utils
+ */
+public class DefaultTaskTriggerFactory implements TaskTriggerFactory {
+    private static final Log log = LogFactory.getLog(DefaultTaskTriggerFactory.class);
+
+    /**
+     * @see TaskTriggerFactory
+     */
+    public Trigger createTrigger(TaskDescription taskDescription) {
+
+        String name = taskDescription.getName();
+        if (name == null || "".equals(name)) {
+            throw new SynapseTaskException("Name of the Task cannot be null", log);
+        }
+
+        String cron = taskDescription.getCron();
+        int repeatCount = taskDescription.getCount();
+        long repeatInterval = taskDescription.getInterval();
+        Date startTime = taskDescription.getStartTime();
+        Date endTime = taskDescription.getEndTime();
+
+        Trigger trigger;
+        if (cron == null || "".equals(cron)) {
+            if (repeatCount >= 0) {
+                trigger = TriggerUtils.makeImmediateTrigger(repeatCount - 1, repeatInterval);
+            } else {
+                trigger = TriggerUtils.makeImmediateTrigger(SimpleTrigger.REPEAT_INDEFINITELY, repeatInterval);
+            }
+
+        } else {
+            CronTrigger cronTrigger = new CronTrigger();
+            try {
+                cronTrigger.setCronExpression(cron);
+                trigger = cronTrigger;
+            } catch (ParseException e) {
+                throw new SynapseTaskException("Error setting cron expression : " + cron, log);
+            }
+        }
+
+        if (trigger == null) {
+            throw new SynapseTaskException("Trigger is null for the Task description : " + taskDescription, log);
+        }
+
+        if (startTime != null) {
+            trigger.setStartTime(startTime);
+        }
+        if (endTime != null) {
+            trigger.setEndTime(endTime);
+        }
+        // give the trigger a random name
+        trigger.setName(name + "-trigger-" + String.valueOf((new Random()).nextLong()));
+        String group = taskDescription.getGroup();
+        if (group != null && !"".equals(group)) {
+            trigger.setGroup(group);
+        } else {
+            trigger.setGroup(TaskDescription.DEFAULT_GROUP);
+        }
+        trigger.setVolatility(taskDescription.isVolatility());
+        return trigger;
+    }
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskException.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskException.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/SynapseTaskException.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,52 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+import org.apache.commons.logging.Log;
+
+/**
+ *
+ */
+public class SynapseTaskException extends RuntimeException {
+
+    private static final long serialVersionUID = -7967803433723984038L;
+
+    public SynapseTaskException(String string) {
+        super(string);
+    }
+
+    public SynapseTaskException(String msg, Throwable e) {
+        super(msg, e);
+    }
+
+    public SynapseTaskException(Throwable t) {
+        super(t);
+    }
+
+    public SynapseTaskException(String msg, Log log) {
+        super(msg);
+        log.error(msg);
+    }
+
+
+    public SynapseTaskException(String msg, Throwable cause, Log log) {
+        super(msg, cause);
+        log.error(msg, cause);
+    }
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/Task.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/Task.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/Task.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,29 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+/**
+ * Represents a executable Task
+ */
+public interface Task {
+    /**
+     * Execute method will be invoked by the QuartzJOb.
+     */
+    public void execute();
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescription.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescription.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescription.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,149 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+
+import org.apache.axiom.om.OMElement;
+import org.quartz.SimpleTrigger;
+
+import java.util.*;
+
+/**
+ * Encapsulates details about a task
+ * Properties are self descriptive and related with quartz
+ */
+public class TaskDescription {
+
+    public static final String CLASSNAME = "ClassName";
+    public static final String PROPERTIES = "Properties";
+    public static final String DEFAULT_GROUP = "synapse.simple.quartz";
+    private String cron;
+    private int repeatCount = SimpleTrigger.REPEAT_INDEFINITELY;
+    private long repeatInterval; // in milliseconds
+    private String className;
+    private final List<String> pinnedServers = new ArrayList<String>();
+    private final Set<OMElement> xmlProperties = new HashSet<OMElement>();
+    private String name;
+    private String group;
+    private Date startTime;
+    private Date endTime;
+    private boolean volatility = true;
+
+
+    public String getTaskClass() {
+        return className;
+    }
+
+    public void setTaskClass(String attributeValue) {
+        className = attributeValue;
+
+    }
+
+    public void setInterval(long l) {
+        repeatInterval = l;
+
+    }
+
+    public long getInterval() {
+        return repeatInterval;
+    }
+
+    public void setCount(int i) {
+        repeatCount = i;
+    }
+
+    public int getCount() {
+        return repeatCount;
+    }
+
+    public void addProperty(OMElement prop) {
+        xmlProperties.add(prop);
+    }
+
+    public Set<OMElement> getProperties() {
+        return xmlProperties;
+    }
+
+    public void setCron(String attributeValue) {
+        cron = attributeValue;
+
+    }
+
+    public String getCron() {
+        return cron;
+    }
+
+    public List<String> getPinnedServers() {
+        return pinnedServers;
+    }
+
+    public void setPinnedServers(List<String> pinnedServers) {
+        if (pinnedServers != null) {
+            this.pinnedServers.addAll(pinnedServers);
+        }
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getGroup() {
+        return group;
+    }
+
+    public void setGroup(String group) {
+        this.group = group;
+    }
+
+    public Date getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(Date endTime) {
+        this.endTime = endTime;
+    }
+
+    public Date getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(Date startTime) {
+        this.startTime = startTime;
+    }
+
+    public boolean isVolatility() {
+        return volatility;
+    }
+
+    public void setVolatility(boolean volatility) {
+        this.volatility = volatility;
+    }
+
+    @Override
+    public String toString() {
+        StringBuffer stringBuffer = new StringBuffer();
+        stringBuffer.append("[Task Description [ Name : ").append(name).
+                append(" ][ClassName : ").append(className).append(" ] ]");
+        return stringBuffer.toString();
+    }
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionFactory.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionFactory.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,179 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.util.PropertyHelper;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ * Create TaskDescription based on OMElement
+ */
+public class TaskDescriptionFactory {
+
+    private static final Log log = LogFactory.getLog(TaskDescriptionFactory.class);
+    private static final String NULL_NAMESPACE = "";
+    private final static String TASK = "task";
+    private final static String TRIGGER = "trigger";
+    private final static String PROPERTY = "property";
+
+    public static TaskDescription createTaskDescription(OMElement el, OMNamespace tagetNamespace) {
+
+        if (log.isDebugEnabled()) {
+            log.debug("Creating SimpleQuartz Task");
+        }
+        QName task = createQName(TASK, tagetNamespace);
+        if (task.equals(el.getQName())) {
+
+            TaskDescription taskDescription = new TaskDescription();
+
+            String name = el.getAttributeValue(
+                    new QName(NULL_NAMESPACE, "name"));
+            if (name != null) {
+                taskDescription.setName(name);
+            } else {
+                handleException("Name for a task is required, missing name in the task");
+            }
+
+            // set the task class
+            OMAttribute classAttr = el.getAttribute(new QName("class"));
+            if (classAttr != null && classAttr.getAttributeValue() != null) {
+                String classname = classAttr.getAttributeValue();
+                try {
+                    Class.forName(classname).newInstance();
+                } catch (Exception e) {
+                    handleException("Failed to load task class " + classname, e);
+                }
+                taskDescription.setTaskClass(classname);
+            } else {
+                log.warn("TaskClass cannot be found." +
+                        "Task implementation may need a task class if there is no default one");
+            }
+
+            // set pinned server list
+            OMAttribute pinnedServers = el.getAttribute(new QName(NULL_NAMESPACE, "pinnedServers"));
+            if (pinnedServers != null) {
+                String pinnedServersValue = pinnedServers.getAttributeValue();
+                if (pinnedServersValue == null) {
+                    // default to all servers
+                } else {
+                    StringTokenizer st = new StringTokenizer(pinnedServersValue, " ,");
+                    List<String> pinnedServersList = new ArrayList<String>();
+                    while (st.hasMoreTokens()) {
+                        String token = st.nextToken();
+                        if (token.length() != 0) {
+                            pinnedServersList.add(token);
+                        }
+                    }
+                    taskDescription.setPinnedServers(pinnedServersList);
+                }
+            }
+
+            // next sort out the property children
+
+            Iterator it = el.getChildrenWithName(createQName(PROPERTY, tagetNamespace));
+            while (it.hasNext()) {
+                OMElement prop = (OMElement) it.next();
+                if (PropertyHelper.isStaticProperty(prop)) {
+                    taskDescription.addProperty(prop);
+                } else {
+                    handleException("Tasks does not support dynamic properties");
+                }
+            }
+
+            // setting the trigger to the task
+            OMElement trigger = el.getFirstChildWithName(createQName(TRIGGER, tagetNamespace));
+            if (trigger != null) {
+
+                OMAttribute count = trigger.getAttribute(new QName("count"));
+                if (count != null) {
+                    try {
+                        taskDescription.setCount(Integer.parseInt(count.getAttributeValue()));
+                    } catch (Exception e) {
+                        handleException("Failed to parse trigger count as an integer", e);
+                    }
+                }
+
+                OMAttribute once = trigger.getAttribute(new QName("once"));
+                if (once != null && Boolean.TRUE.toString().equals(once.getAttributeValue())) {
+                    taskDescription.setCount(1);
+                    taskDescription.setInterval(1);
+                }
+
+                OMAttribute repeatInterval = trigger.getAttribute(new QName("interval"));
+                if (repeatInterval == null && taskDescription.getCount() > 1) {
+                    handleException("Trigger seems to be " +
+                            "a simple trigger, but no interval specified");
+                } else if (repeatInterval != null && repeatInterval.getAttributeValue() != null) {
+                    try {
+                        long repeatIntervalInSeconds = Long.parseLong(repeatInterval.getAttributeValue());
+                        long repeatIntervalInMillis = repeatIntervalInSeconds * 1000;
+                        taskDescription.setInterval(repeatIntervalInMillis);
+                    } catch (Exception e) {
+                        handleException("Failed to parse trigger interval as a long value", e);
+                    }
+                }
+
+                OMAttribute expr = trigger.getAttribute(new QName("cron"));
+                if (expr == null && taskDescription.getInterval() == 0) {
+                    taskDescription.setCount(1);
+                    taskDescription.setInterval(1);
+                } else if (expr != null && taskDescription.getInterval() > 0) {
+                    handleException("Trigger syntax error : " +
+                            "both cron and simple trigger attributes are present");
+                } else if (expr != null && expr.getAttributeValue() != null) {
+                    taskDescription.setCron(expr.getAttributeValue());
+                }
+
+            } else {
+                taskDescription.setCount(1);
+                taskDescription.setInterval(1);
+            }
+
+            return taskDescription;
+        } else {
+            handleException("Syntax error in the task : wrong QName for the task");
+            return null;
+        }
+    }
+
+    private static QName createQName(String localName, OMNamespace omNamespace) {
+        return new QName(omNamespace.getNamespaceURI(), localName, omNamespace.getPrefix());
+    }
+
+    private static void handleException(String message, Exception e) {
+        log.error(message);
+        throw new SynapseTaskException(message, e);
+    }
+
+    private static void handleException(String message) {
+        log.error(message);
+        throw new SynapseTaskException(message);
+    }
+
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepository.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepository.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepository.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,142 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Local repository for holds Task descriptions
+ */
+public class TaskDescriptionRepository {
+
+    private static final Log log = LogFactory.getLog(TaskDescriptionRepository.class);
+    private final Map<String, TaskDescription> taskDescriptionMap = new HashMap<String, TaskDescription>();
+
+    /**
+     * Stores a given TaskDescription
+     *
+     * @param taskDescription TaskDescription instance
+     */
+    public void addTaskDescription(TaskDescription taskDescription) {
+
+        validateTaskDescription(taskDescription);
+
+        String name = taskDescription.getName();
+        validateName(name);
+        validateUniqueness(name);
+
+        if (log.isDebugEnabled()) {
+            log.debug("Storing a TaskDescription : " + taskDescription);
+        }
+        taskDescriptionMap.put(name, taskDescription);
+
+    }
+
+    /**
+     * Gets a TaskDescription
+     *
+     * @param name Name of the TaskDescription to be looked up
+     * @return TaskDescription instance
+     */
+    public TaskDescription getTaskDescription(String name) {
+        validateName(name);
+        TaskDescription taskDescription = taskDescriptionMap.get(name);
+        if (taskDescription == null) {
+            if (log.isDebugEnabled()) {
+                log.debug("TaskDescription cannot be found for name :" + name + " , returning null");
+            }
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("Returning TaskDescription : " + taskDescription);
+            }
+        }
+        return taskDescription;
+    }
+
+    /**
+     * Removing a TaskDescription
+     *
+     * @param name Name of the TaskDescription to be removed
+     * @return Removed TaskDescription instance
+     */
+    public TaskDescription removeTaskDescription(String name) {
+        validateName(name);
+        if (log.isDebugEnabled()) {
+            log.debug("Removing a TaskDescription with name : " + name);
+        }
+        TaskDescription taskDescription = taskDescriptionMap.remove(name);
+        if (taskDescription == null) {
+            if (log.isDebugEnabled()) {
+                log.debug("There is no TaskDescription to be removed with name : " + name);
+            }
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("Removed TaskDescription : " + taskDescription);
+            }
+        }
+        return taskDescription;
+
+    }
+
+    /**
+     * Return all TaskDescritions
+     *
+     * @return Iterator for access taskDescritions
+     */
+    public Iterator<TaskDescription> getAllTaskDescriptions() {
+        return taskDescriptionMap.values().iterator();
+    }
+
+    /**
+     * Explicit check for determine whether there is a task description with a name in interest
+     *
+     * @param name Name of the TaskDescription
+     * @return Returns true , if there is no TaskDescription associated with given name , otherwise , false
+     */
+    public boolean isUnique(String name) {
+        validateName(name);
+        return taskDescriptionMap.isEmpty() || !taskDescriptionMap.containsKey(name);
+    }
+
+
+    private void validateName(String name) {
+        if (name == null || "".equals(name)) {
+            throw new SynapseTaskException("Task name is null or empty", log);
+        }
+
+    }
+
+    private void validateUniqueness(String name) {
+        if (taskDescriptionMap.containsKey(name)) {
+            throw new SynapseTaskException("Name with ' " + name + " ' is already there", log);
+        }
+    }
+
+    private void validateTaskDescription(TaskDescription taskDescription) {
+        if (taskDescription == null) {
+            throw new SynapseTaskException("TaskDescription is null", log);
+        }
+
+    }
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepositoryFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepositoryFactory.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionRepositoryFactory.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TaskDescriptionRepositoryFactory {
+
+    private static final Log log = LogFactory.getLog(TaskDescriptionRepositoryFactory.class);
+    private final static Map<String, TaskDescriptionRepository> repositoryMap = new HashMap<String, TaskDescriptionRepository>();
+
+    private TaskDescriptionRepositoryFactory() {
+    }
+
+    /**
+     * Returns a TaskDescriptionRepository instance
+     * There is an only one instance of TaskDescriptionRepository for a given id as Factory caches TaskDescriptionRepositorys
+     *
+     * @param id Identifier for TaskDescriptionRepository
+     * @return TaskDescriptionRepository instance
+     */
+    public static TaskDescriptionRepository getTaskDescriptionRepository(String id) {
+
+        if (id == null || "".equals(id)) {
+            throw new SynapseTaskException("Name cannot be found.", log);
+        }
+
+        TaskDescriptionRepository repository = repositoryMap.get(id);
+        if (repository == null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Creating a TaskDescriptionRepository with id : " + id);
+            }
+            repository = new TaskDescriptionRepository();
+            repositoryMap.put(id, repository);
+        }
+        return repository;
+    }
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionSerializer.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionSerializer.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskDescriptionSerializer.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,91 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.List;
+
+/**
+ * Serialize a TaskDescription into a OMElement
+ */
+public class TaskDescriptionSerializer {
+
+    private static final Log log = LogFactory.getLog(TaskDescriptionSerializer.class);
+    private static final OMFactory omFactory = OMAbstractFactory.getOMFactory();
+
+    private static final String NULL_NAMESPACE = "";
+    private static final OMNamespace NULL_OMNS = omFactory.createOMNamespace(NULL_NAMESPACE, "");
+
+    public static OMElement serializeTaskDescription(OMNamespace targetNamespace, TaskDescription taskDescription) {
+
+        if (taskDescription == null) {
+            throw new SynapseTaskException("TaskDescription can not be null", log);
+        }
+
+        OMElement task = omFactory.createOMElement("task", targetNamespace);
+        task.addAttribute("name", taskDescription.getName(), NULL_OMNS);
+
+        String taskClass = taskDescription.getTaskClass();
+        if (taskClass != null && !"".equals(taskClass)) {
+            task.addAttribute("class", taskDescription.getTaskClass(), NULL_OMNS);
+        }
+
+        List pinnedServers = taskDescription.getPinnedServers();
+        if (pinnedServers != null && !pinnedServers.isEmpty()) {
+            String pinnedServersStr = "" + pinnedServers.get(0);
+            for (int i = 1; i < pinnedServers.size(); i++) {
+                pinnedServersStr = pinnedServersStr + " " + pinnedServers.get(i);
+            }
+            task.addAttribute(omFactory.createOMAttribute("pinnedServers", NULL_OMNS, pinnedServersStr));
+        }
+
+        OMElement el = omFactory.createOMElement("trigger", targetNamespace, task);
+        if (taskDescription.getInterval() == 1 && taskDescription.getCount() == 1) {
+            el.addAttribute("once", "true", NULL_OMNS);
+        } else if (taskDescription.getCron() != null) {
+            el.addAttribute("cron", taskDescription.getCron(), NULL_OMNS);
+        } else {
+            if (taskDescription.getCount() != -1) {
+                el.addAttribute("count", Integer.toString(taskDescription.getCount()), NULL_OMNS);
+            }
+
+            if (taskDescription.getInterval() != 0) {
+                long interval = taskDescription.getInterval() / 1000;
+                el.addAttribute("interval", Long.toString(interval), NULL_OMNS);
+            }
+        }
+
+        for (Object o : taskDescription.getProperties()) {
+            OMElement prop = (OMElement) o;
+            if (prop != null) {
+                prop.setNamespace(targetNamespace);
+                task.addChild(prop.cloneOMElement());
+            }
+        }
+
+        return task;
+    }
+
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskJobDetailFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskJobDetailFactory.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskJobDetailFactory.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,42 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+import org.quartz.Job;
+import org.quartz.JobDetail;
+
+import java.util.Map;
+
+/**
+ * Creates a JobDetail based on give Task Description , additional resources and job class
+ */
+public interface TaskJobDetailFactory {
+
+    /**
+     * Factory method for creating a JobDetail based on give Task Description , additional resources and job class
+     *
+     * @param taskDescription TaskDescription instance
+     * @param resources       Additional resources .
+     *                        This can be used to provide context specific resources
+     *                        Example : Synapse Environment
+     * @param jobClass        Job class
+     * @return JobDetail instance , if there are enough information to create a instance , otherwise , return null
+     */
+    JobDetail createJobDetail(TaskDescription taskDescription, Map<String, Object> resources, Class<Job> jobClass);
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskScheduler.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,290 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.*;
+import org.quartz.impl.StdSchedulerFactory;
+
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Abstraction for scheduling a Task
+ */
+public class TaskScheduler {
+
+    private static Log log = LogFactory.getLog(TaskScheduler.class);
+
+    /**
+     * scheduler instance
+     */
+    private Scheduler scheduler;
+    /* determine whether scheduler has been initialized or not - Ready to schedule a Task or not */
+    private boolean initialized = false;
+
+    /**
+     * Default trigger factory
+     */
+    private TaskTriggerFactory triggerFactory = new DefaultTaskTriggerFactory();
+    /**
+     * Default job detail factory
+     */
+    private TaskJobDetailFactory jobDetailFactory = new DefaultTaskJobDetailFactory();
+
+    /**
+     * Property look up key for get a quartz configuration
+     */
+    public static String QUARTZ_CONF = "quartz.conf";
+
+    /**
+     * Name of the scheduler
+     */
+    private String name;
+
+    public TaskScheduler(String name) {
+        this.name = name;
+    }
+
+    /**
+     * Initialize the scheduler based on provided properties
+     * Looking for  'quartz.conf' and if found , use it for initiating quartz scheduler
+     *
+     * @param properties Properties
+     */
+    public void init(Properties properties) {
+
+        StdSchedulerFactory sf = new StdSchedulerFactory();
+
+        if (properties != null) {
+            String quartzConf = properties.getProperty(QUARTZ_CONF);
+            try {
+                if (quartzConf != null && !"".equals(quartzConf)) {
+
+                    if (log.isDebugEnabled()) {
+                        log.debug("Initiating a Scheduler with configuration : " + quartzConf);
+                    }
+
+                    sf.initialize(quartzConf);
+                }
+            } catch (SchedulerException e) {
+                throw new SynapseTaskException("Error initiating scheduler factory "
+                        + sf + "with configuration loaded from " + quartzConf, e, log);
+            }
+        }
+
+        try {
+
+            if (name != null) {
+                scheduler = sf.getScheduler(name);
+            }
+            if (scheduler == null) {
+                scheduler = sf.getScheduler();
+            }
+
+        } catch (SchedulerException e) {
+            throw new SynapseTaskException("Error getting a  scheduler instance form scheduler factory " + sf, e, log);
+        }
+        initialized = true;
+        start();
+    }
+
+    /**
+     * Explicitly start up call for scheduler, return if already it has been started
+     */
+    public void start() {
+
+        validateInit();
+        try {
+            if (!scheduler.isStarted()) {
+
+                if (log.isDebugEnabled()) {
+                    log.debug("Starting a Scheduler : [ " + scheduler.getMetaData() + " ]");
+                }
+                scheduler.start();
+            }
+        } catch (SchedulerException e) {
+            throw new SynapseTaskException("Error starting scheduler ", e, log);
+        }
+    }
+
+    /**
+     * Schedule a Task
+     *
+     * @param taskDescription TaskDescription , an information about Task
+     * @param resources       Any initial resources for task
+     * @param jobClass        Quartz job class
+     */
+    public void scheduleTask(TaskDescription taskDescription, Map<String, Object> resources, Class jobClass) {
+
+        validateInit();
+        validateStart();
+
+        if (taskDescription == null) {
+            throw new SynapseTaskException("Task Description can not be found", log);
+        }
+
+        if (jobClass == null) {
+            throw new SynapseTaskException("Job Class can not be found", log);
+        }
+
+        if (!Job.class.isAssignableFrom(jobClass)) {
+            throw new SynapseTaskException("Invalid Job Class : [ Expected " + Job.class.getName() + "]" +
+                    " [ Found " + jobClass.getName() + " ]", log);
+        }
+
+        if (triggerFactory == null) {
+            throw new SynapseTaskException("TriggerFactory can not be found", log);
+        }
+
+        if (jobDetailFactory == null) {
+            throw new SynapseTaskException("JobDetailFactory can not be found", log);
+        }
+
+        Trigger trigger = triggerFactory.createTrigger(taskDescription);
+        if (trigger == null) {
+            throw new SynapseTaskException("Trigger can not be created from : " + taskDescription, log);
+        }
+
+        JobDetail jobDetail = jobDetailFactory.createJobDetail(taskDescription, resources, jobClass);
+        if (jobDetail == null) {
+            throw new SynapseTaskException("JobDetailcan not be created from : " + taskDescription +
+                    " and job class " + jobClass.getName(), log);
+        }
+
+        try {
+            if (log.isDebugEnabled()) {
+                log.debug("scheduling job : " + jobDetail + " with trigger " + trigger);
+            }
+            scheduler.scheduleJob(jobDetail, trigger);
+        } catch (SchedulerException e) {
+            throw new SynapseTaskException("Error scheduling job : " + jobDetail + " with trigger " + trigger);
+        }
+
+    }
+
+    /**
+     * ShutDown the underlying quartz scheduler
+     */
+    public void shutDown() {
+
+        validateInit();
+        validateStart();
+
+        try {
+            if (log.isDebugEnabled()) {
+                log.debug("ShutingDown Scheduler : " + scheduler.getMetaData());
+            }
+            scheduler.shutdown();
+            initialized = false;
+        } catch (SchedulerException e) {
+            throw new SynapseTaskException("Error shutingDown scheduler ", e, log);
+        }
+    }
+
+    /**
+     * @return Returns true if the scheduler is ready for schedule a task
+     */
+    public boolean isInitialized() {
+        return initialized;
+    }
+
+    /**
+     * Deletes a Task
+     *
+     * @param name  Name of the Task
+     * @param group Group name of the task
+     *              Default value @see org.apache.synapse.util.task.TaskDescription.DEFAULT_GROUP
+     */
+    public void deleteTask(String name, String group) {
+
+        validateInit();
+        validateStart();
+
+        if (name == null || "".equals(name)) {
+            throw new SynapseTaskException("Task Name can not be null", log);
+        }
+
+        if (group == null || "".equals(group)) {
+            group = TaskDescription.DEFAULT_GROUP;
+            if (log.isDebugEnabled()) {
+                log.debug("Task group is null or empty , using default group :" + TaskDescription.DEFAULT_GROUP);
+            }
+        }
+
+        try {
+            if (log.isDebugEnabled()) {
+                log.debug("Deleting a Job with [ Name :" + name + " ]" +
+                        " [ Group :" + group + " ]");
+            }
+            scheduler.deleteJob(name, group);
+        } catch (SchedulerException e) {
+            throw new SynapseTaskException("Error deleting a job with  [ Name :" + name + " ]" +
+                    " [ Group :" + group + " ]");
+        }
+    }
+
+    /**
+     * Sets a Trigger Factory , if it needs to void using default factory
+     *
+     * @param triggerFactory TaskTriggerFactory instance
+     */
+    public void setTriggerFactory(TaskTriggerFactory triggerFactory) {
+        this.triggerFactory = triggerFactory;
+    }
+
+    /**
+     * Sets a JobDetail Factory, if it needs to void using default factory
+     *
+     * @param jobDetailFactory TaskJobDetailFactory instance
+     */
+    public void setJobDetailFactory(TaskJobDetailFactory jobDetailFactory) {
+        this.jobDetailFactory = jobDetailFactory;
+    }
+
+    @Override
+    public String toString() {
+        StringBuffer schedulerMetaData = new StringBuffer();
+        if (scheduler != null) {
+            schedulerMetaData = schedulerMetaData.append("[ Scheduler : ").append(scheduler).append(" ]");
+        }
+        return new StringBuffer().append("[ TaskScheduler[ Name :").
+                append(name).append("]").append(schedulerMetaData).append(" ]").toString();
+    }
+
+    private void validateInit() {
+
+        if (!initialized) {
+            throw new SynapseTaskException("Scheduler has not been initialled yet", log);
+        }
+    }
+
+    private void validateStart() {
+
+        try {
+            if (!scheduler.isStarted()) {
+                throw new SynapseTaskException("Scheduler has not been started yet", log);
+            }
+        } catch (SchedulerException e) {
+            throw new SynapseTaskException("Error determine start state of the cheduler ", e, log);
+        }
+    }
+
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskSchedulerFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskSchedulerFactory.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskSchedulerFactory.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Factory method for retrieve / create a TaskScheduler
+ */
+public class TaskSchedulerFactory {
+
+    private final static Map<String, TaskScheduler> MAP = new HashMap<String, TaskScheduler>();
+
+    private TaskSchedulerFactory() {
+    }
+
+    /**
+     * Returns a TaskScheduler whose name is match with given name.
+     * There is an only one instance of TaskScheduler for a given name as Factory caches
+     *
+     * @param name Name of the TaskScheduler
+     * @return TaskScheduler instance
+     */
+    public static TaskScheduler getTaskScheduler(String name) {
+
+        if (name == null || "".equals(name)) {
+            throw new SynapseTaskException("Name cannot be found.");
+        }
+
+        TaskScheduler taskScheduler = MAP.get(name);
+        if (taskScheduler == null) {
+            taskScheduler = new TaskScheduler(name);
+            MAP.put(name, taskScheduler);
+        }
+
+        return taskScheduler;
+    }
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskTriggerFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskTriggerFactory.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/TaskTriggerFactory.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,36 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task;
+
+import org.quartz.Trigger;
+
+/**
+ * Creates a trigger instance based on given Task Description
+ */
+public interface TaskTriggerFactory {
+
+    /**
+     * Factory method to create a trigger instance based on given Task Description
+     *
+     * @param taskDescription Task Description encapsulates details need to create a trigger
+     * @return Trigger instance , if there are enough information , otherwise null
+     */
+    public Trigger createTrigger(TaskDescription taskDescription);
+
+}

Added: branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/service/TaskManagementService.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/service/TaskManagementService.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/tasks/src/main/java/org/apache/synapse/task/service/TaskManagementService.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,84 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.task.service;
+
+import org.apache.synapse.task.TaskDescription;
+import org.apache.axiom.om.OMElement;
+
+import java.util.List;
+
+/**
+ * A service for management of task
+ * Implementation can be a web service , OSGI service , etc
+ */
+public interface TaskManagementService {
+
+    /**
+     * Adding a  TaskDescription instance
+     *
+     * @param taskDescription TaskDescription instance
+     */
+    void addTaskDescription(TaskDescription taskDescription);
+
+    /**
+     * Deletes a TaskDescription instance with given name
+     *
+     * @param name Name of the TaskDescription  to be deleted
+     */
+    void deleteTaskDescription(String name);
+
+    /**
+     * Edit a TaskDescription
+     * Remove existing one with new one
+     *
+     * @param taskDescription New TaskDescription instance
+     */
+    void editTaskDescription(TaskDescription taskDescription);
+
+    /**
+     * Lists of all TaskDescription instances
+     *
+     * @return A List of TaskDescription
+     */
+    List<TaskDescription> getAllTaskDescriptions();
+
+    /**
+     * Get a TaskDescription instance with given name
+     *
+     * @param name Name of the TaskDescription instance to be returned
+     * @return TaskDescription instance
+     */
+    TaskDescription getTaskDescription(String name);
+
+    /**
+     * Explicit check for availability of a particular TaskDescription instance
+     *
+     * @param name Name of the TaskDescription instance
+     * @return Returns true if there is a TaskDescription instance with given name , otherwise , false
+     */
+    boolean isContains(String name);
+
+    /**
+     * Returns list of names of assignable instance properties of the task implementation
+     *
+     * @param taskClass A name of the task implementation
+     * @return List of assignable property's names
+     */
+    List<String> getPropertyNames(String taskClass);
+}

Modified: branches/synapse/modules/transports/pom.xml
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/transports/pom.xml?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/modules/transports/pom.xml	(original)
+++ branches/synapse/modules/transports/pom.xml	Mon Nov 10 23:33:31 2008
@@ -125,7 +125,10 @@
     </profiles>
 
     <dependencies>
-
+        <dependency>
+            <groupId>org.apache.synapse</groupId>
+            <artifactId>synapse-utils</artifactId>
+        </dependency>
     </dependencies>
 
     <properties>

Added: branches/synapse/modules/utils/pom.xml
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/utils/pom.xml?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/utils/pom.xml	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~  Licensed to the Apache Software Foundation (ASF) under one
+  ~  or more contributor license agreements.  See the NOTICE file
+  ~  distributed with this work for additional information
+  ~  regarding copyright ownership.  The ASF licenses this file
+  ~  to you 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.
+  -->
+
+<project
+    xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.synapse</groupId>
+        <artifactId>Apache-Synapse</artifactId>
+        <version>1.2.wso2v1</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.synapse</groupId>
+    <artifactId>synapse-utils</artifactId>
+    
+    <name>Apache Synapse - Utility classes</name>
+    <description>Apache Synapse - Utility classes</description>
+    <packaging>bundle</packaging>
+
+    <build>
+        <plugins>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.2</version>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>1.4.0</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Version>1.3.0</Bundle-Version>
+                        <Bundle-Name>org.apache.synapse.util</Bundle-Name>
+                        <Bundle-Vendor>Apache Software Foundation</Bundle-Vendor>
+                        <Bundle-Description>${pom.description}</Bundle-Description>
+                        <Bundle-SymbolicName>org.apache.synapse.utils</Bundle-SymbolicName>
+                        <Export-Package>
+                            org.apache.synapse.util.*;-split-package:=merge-last,
+                        </Export-Package>
+                        <Import-Package>
+                            !javax.xml.namespace,
+                            !org.apache.commons.io,
+                            javax.xml.namespace; version=0.0.0,                             
+                            org.apache.axiom.*,  
+                            org.apache.commons.logging,
+                            org.apache.log4j,
+                            org.apache.commons.io.*,                     
+                            *;resolution:=optional,
+                        </Import-Package>
+                        <DynamicImport-Package>*</DynamicImport-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+
+        </plugins>
+    </build>
+
+    <dependencies>
+        
+    </dependencies>
+</project>

Added: branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/PropertyHelper.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/PropertyHelper.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/PropertyHelper.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,175 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.util;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.lang.reflect.Method;
+
+/**
+ * This class will be used as a Helper class to get the properties loaded while building the
+ * Synapse Configuration from the XML
+ */
+public class PropertyHelper {
+
+    /**
+     * Log variable for the logging purposes
+     */
+    private static final Log log = LogFactory.getLog(PropertyHelper.class);
+
+    /**
+     * Find and invoke the setter method with the name of form setXXX passing in the value given
+     * on the POJO object
+     * @param name name of the setter field
+     * @param val value to be set
+     * @param obj POJO instance
+     */
+    public static void setInstanceProperty(String name, Object val, Object obj) {
+
+        String mName = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
+        Method method;
+
+        try {
+            Method[] methods = obj.getClass().getMethods();
+            boolean invoked = false;
+
+            for (Method method1 : methods) {
+                if (mName.equals(method1.getName())) {
+                    Class[] params = method1.getParameterTypes();
+                    if (params.length != 1) {
+                        handleException("Did not find a setter method named : " + mName +
+                                "() that takes a single String, int, long, float, double ,OMElement " +
+                                "or boolean parameter");
+                    } else if (val instanceof String) {
+                        String value = (String) val;
+                        if (String.class.equals(params[0])) {
+                            method = obj.getClass().getMethod(mName, String.class);
+                            method.invoke(obj, new String[]{value});
+                        } else if (int.class.equals(params[0])) {
+                            method = obj.getClass().getMethod(mName, int.class);
+                            method.invoke(obj, new Integer[]{new Integer(value)});
+                        } else if (long.class.equals(params[0])) {
+                            method = obj.getClass().getMethod(mName, long.class);
+                            method.invoke(obj, new Long[]{new Long(value)});
+                        } else if (float.class.equals(params[0])) {
+                            method = obj.getClass().getMethod(mName, float.class);
+                            method.invoke(obj, new Float[]{new Float(value)});
+                        } else if (double.class.equals(params[0])) {
+                            method = obj.getClass().getMethod(mName, double.class);
+                            method.invoke(obj, new Double[]{new Double(value)});
+                        } else if (boolean.class.equals(params[0])) {
+                            method = obj.getClass().getMethod(mName, boolean.class);
+                            method.invoke(obj, new Boolean[]{Boolean.valueOf(value)});
+                        } else {
+                            continue;
+                        }
+                    } else if (val instanceof OMElement && OMElement.class.equals(params[0])) {
+                        method = obj.getClass().getMethod(mName, OMElement.class);
+                        method.invoke(obj, new OMElement[]{(OMElement) val});
+                    } else {
+                        continue;
+                    }
+                    invoked = true;
+                    break;
+                }
+            }
+
+            if (!invoked) {
+                handleException("Did not find a setter method named : " + mName +
+                        "() that takes a single String, int, long, float, double " +
+                        "or boolean parameter");
+            }
+
+        } catch (Exception e) {
+            handleException("Error invoking setter method named : " + mName +
+                    "() that takes a single String, int, long, float, double " +
+                    "or boolean parameter", e);
+        }
+    }
+
+    /**
+     * This method will set the static property discribed in the OMElement to the specified object.
+     * This Object should have the setter method for the specified property name
+     * 
+     * @param property - OMElement specifying the property to be built in to the object
+     * @param o - Object to which the specified property will be set.
+     */
+    public static void setStaticProperty(OMElement property, Object o) {
+
+        if (property.getLocalName().toLowerCase().equals("property")) {
+
+            String propertyName = property.getAttributeValue(new QName("name"));
+            String mName = "set"
+                    + Character.toUpperCase(propertyName.charAt(0))
+                    + propertyName.substring(1);
+
+            // try to set String value first
+            if (property.getAttributeValue(new QName("value")) != null) {
+                String value = property.getAttributeValue(new QName("value"));
+                setInstanceProperty(propertyName, value, o);
+            } else {
+                // now try XML child
+                OMElement value = property.getFirstElement();
+                if (value != null) {
+
+                    try {
+                        Method method = o.getClass().getMethod(mName, OMElement.class);
+                        if (log.isDebugEnabled()) {
+                            log.debug("Setting property :: invoking method "
+                                    + mName + "(" + value + ")");
+                        }
+                        method.invoke(o, value);
+
+                    } catch (Exception e) {
+                        handleException("Error setting property : " + propertyName
+                                + " as an OMElement property into class mediator : "
+                                + o.getClass() + " : " + e.getMessage(), e);
+                    }
+
+                }
+
+            }
+        }
+    }
+
+    /**
+     * This method will check the given OMElement represent either a static property or not
+     * 
+     * @param property - OMElement to be checked for the static property
+     * @return boolean true if the elemet represents a static property element false otherwise
+     */
+    public static boolean isStaticProperty(OMElement property) {
+        return "property".equals(property.getLocalName().toLowerCase())
+            && (property.getAttributeValue(new QName("expression")) == null);
+    }
+
+    private static void handleException(String message, Throwable e) {
+        log.error(message + e.getMessage());
+        throw new SynapseUtilException(message, e);
+    }
+
+    private static void handleException(String message) {
+        log.error(message);
+        throw new SynapseUtilException(message);
+    }    
+}

Added: branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/SynapseUtilException.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/SynapseUtilException.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/SynapseUtilException.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,51 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.util;
+
+import org.apache.commons.logging.Log;
+
+/**
+ *
+ */
+public class SynapseUtilException extends RuntimeException {
+
+    private static final long serialVersionUID = -7361599095528938810L;
+
+    public SynapseUtilException(String string) {
+        super(string);
+    }
+
+    public SynapseUtilException(String msg, Throwable e) {
+        super(msg, e);
+    }
+
+    public SynapseUtilException(Throwable t) {
+        super(t);
+    }
+
+    public SynapseUtilException(String msg, Log synLog) {
+        super(msg);
+        synLog.error(msg);
+    }
+
+    public SynapseUtilException(String msg, Throwable cause, Log synLog) {
+        super(msg, cause);
+        synLog.error(msg, cause);
+    }
+}
\ No newline at end of file

Added: branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/TemporaryData.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/TemporaryData.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/utils/src/main/java/org/apache/synapse/util/TemporaryData.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,363 @@
+package org.apache.synapse.util;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.*;
+
+/**
+ * Class representing some temporary data in the form of a byte stream.
+ * <p>
+ * Data is stored by writing to the output stream obtained using
+ * {@link #getOutputStream()}. It can then be read back using
+ * the input stream obtained from {@link #getInputStream()}.
+ * The data is first stored into a fixed size buffer. Once this
+ * buffer overflows, it is transferred to a temporary file. The buffer
+ * is divided into a given number of fixed size chunks that are allocated
+ * on demand. Since a temporary file may be created it is mandatory to
+ * call {@link #release()} to discard the temporary data.
+ */
+public class TemporaryData {
+    
+    private static final Log log = LogFactory.getLog(TemporaryData.class);
+    
+    class OutputStreamImpl extends OutputStream {
+        
+        private FileOutputStream fileOutputStream;
+        
+        public void write(byte[] b, int off, int len) throws IOException {
+
+            if (fileOutputStream != null) {
+                fileOutputStream.write(b, off, len);
+            } else if (len > (chunks.length-chunkIndex)*chunkSize - chunkOffset) {
+
+                // The buffer will overflow. Switch to a temporary file.
+                fileOutputStream = switchToTempFile();
+                
+                // Write the new data to the temporary file.
+                fileOutputStream.write(b, off, len);
+
+            } else {
+
+                // The data will fit into the buffer.
+                while (len > 0) {
+
+                    byte[] chunk = getCurrentChunk();
+
+                    // Determine number of bytes that can be copied to the current chunk.
+                    int c = Math.min(len, chunkSize-chunkOffset);
+                    // Copy data to the chunk.
+                    System.arraycopy(b, off, chunk, chunkOffset, c);
+
+                    // Update variables.
+                    len -= c;
+                    off += c;
+                    chunkOffset += c;
+                    if (chunkOffset == chunkSize) {
+                        chunkIndex++;
+                        chunkOffset = 0;
+                    }
+                }
+            }
+        }
+
+        public void write(byte[] b) throws IOException {
+            write(b, 0, b.length);
+        }
+
+        public void write(int b) throws IOException {
+            write(new byte[] { (byte)b }, 0, 1);
+        }
+
+        public void flush() throws IOException {
+            if (fileOutputStream != null) {
+                fileOutputStream.flush();
+            }
+        }
+
+        public void close() throws IOException {
+            if (fileOutputStream != null) {
+                fileOutputStream.close();
+            }
+        }
+    }
+    
+    class InputStreamImpl extends InputStream {
+
+        private int currentChunkIndex;
+        private int currentChunkOffset;
+        private int markChunkIndex;
+        private int markChunkOffset;
+        
+        public int available() throws IOException {
+            return (chunkIndex-currentChunkIndex)*chunkSize + chunkOffset - currentChunkOffset;
+        }
+
+        public int read(byte[] b, int off, int len) throws IOException {
+
+            if (len == 0) {
+                return 0;
+            }
+
+            int read = 0;
+            while (len > 0 && !(currentChunkIndex == chunkIndex
+                    && currentChunkOffset == chunkOffset)) {
+
+                int c;
+                if (currentChunkIndex == chunkIndex) {
+                    // The current chunk is the last one => take into account the offset
+                    c = Math.min(len, chunkOffset-currentChunkOffset);
+                } else {
+                    c = Math.min(len, chunkSize-currentChunkOffset);
+                }
+
+                // Copy the data.
+                System.arraycopy(chunks[currentChunkIndex], currentChunkOffset, b, off, c);
+
+                // Update variables
+                len -= c;
+                off += c;
+                currentChunkOffset += c;
+                read += c;
+                if (currentChunkOffset == chunkSize) {
+                    currentChunkIndex++;
+                    currentChunkOffset = 0;
+                }
+            }
+
+            if (read == 0) {
+                // We didn't read anything (and the len argument was not 0) => we reached the end of the buffer.
+                return -1;
+            } else {
+                return read;
+            }
+        }
+
+        public int read(byte[] b) throws IOException {
+            return read(b, 0, b.length);
+        }
+
+        public int read() throws IOException {
+            byte[] b = new byte[1];
+            return read(b) == -1 ? -1 : (int)b[0] & 0xFF;
+        }
+
+        public boolean markSupported() {
+            return true;
+        }
+
+        public void mark(int readlimit) {
+            markChunkIndex = currentChunkIndex;
+            markChunkOffset = currentChunkOffset;
+        }
+
+        public void reset() throws IOException {
+            currentChunkIndex = markChunkIndex;
+            currentChunkOffset = markChunkOffset;
+        }
+
+        public long skip(long n) throws IOException {
+
+            int available = available();
+            int c = n < available ? (int)n : available;
+            int newOffset = currentChunkOffset + c;
+            int chunkDelta = newOffset/chunkSize;
+            currentChunkIndex += chunkDelta;
+            currentChunkOffset = newOffset - (chunkDelta*chunkSize);
+            return c;
+        }
+        
+        public void close() throws IOException {
+        }
+    }
+    
+    /**
+     * Size of the chunks that will be allocated in the buffer.
+     */
+    final int chunkSize;
+    
+    /**
+     * The prefix to be used in generating the name of the temporary file.
+     */
+    final String tempPrefix;
+    
+    /**
+     * The suffix to be used in generating the name of the temporary file.
+     */
+    final String tempSuffix;
+    
+    /**
+     * Array of <code>byte[]</code> representing the chunks of the buffer.
+     * A chunk is only allocated when the first byte is written to it.
+     * This attribute is set to <code>null</code> when the buffer overflows and
+     * is written out to a temporary file.
+     */
+    byte[][] chunks;
+    
+    /**
+     * Index of the chunk the next byte will be written to.
+     */
+    int chunkIndex;
+    
+    /**
+     * Offset into the chunk where the next byte will be written.
+     */
+    int chunkOffset;
+    
+    /**
+     * The handle of the temporary file. This is only set when the memory buffer
+     * overflows and is written out to a temporary file.
+     */
+    File temporaryFile;
+    
+    public TemporaryData(int numberOfChunks, int chunkSize, String tempPrefix, String tempSuffix) {
+        this.chunkSize = chunkSize;
+        this.tempPrefix = tempPrefix;
+        this.tempSuffix = tempSuffix;
+        chunks = new byte[numberOfChunks][];
+    }
+    
+    /**
+     * Get the current chunk to write to, allocating it if necessary.
+     * 
+     * @return the current chunk to write to (never null)
+     */
+    byte[] getCurrentChunk() {
+        if (chunkOffset == 0) {
+            // We will write the first byte to the current chunk. Allocate it.
+            byte[] chunk = new byte[chunkSize];
+            chunks[chunkIndex] = chunk;
+            return chunk;
+        } else {
+            // The chunk has already been allocated.
+            return chunks[chunkIndex];
+        }
+    }
+    
+    /**
+     * Create a temporary file and write the existing in memory data to it.
+     * 
+     * @return an open FileOutputStream to the temporary file
+     * @throws IOException
+     */
+    FileOutputStream switchToTempFile() throws IOException {
+        temporaryFile = File.createTempFile(tempPrefix, tempSuffix);
+        if (log.isDebugEnabled()) {
+            log.debug("Using temporary file " + temporaryFile);
+        }
+        temporaryFile.deleteOnExit();
+
+        FileOutputStream fileOutputStream = new FileOutputStream(temporaryFile);
+        // Write the buffer to the temporary file.
+        for (int i=0; i<chunkIndex; i++) {
+            fileOutputStream.write(chunks[i]);
+        }
+
+        if (chunkOffset > 0) {
+            fileOutputStream.write(chunks[chunkIndex], 0, chunkOffset);
+        }
+
+        // Release references to the buffer so that it can be garbage collected.
+        chunks = null;
+        
+        return fileOutputStream;
+    }
+    
+    public OutputStream getOutputStream() {
+        return new OutputStreamImpl();
+    }
+    
+    /**
+     * Fill this object with data read from a given InputStream.
+     * <p>
+     * A call <code>tmp.readFrom(in)</code> has the same effect as the
+     * following code:
+     * <pre>
+     * OutputStream out = tmp.getOutputStream();
+     * IOUtils.copy(in, out);
+     * out.close();
+     * </pre>
+     * However it does so in a more efficient way.
+     * 
+     * @param in An InputStream to read data from. This method will not
+     *           close the stream.
+     * @throws IOException
+     */
+    public void readFrom(InputStream in) throws IOException {
+        while (true) {
+            int c = in.read(getCurrentChunk(), chunkOffset, chunkSize-chunkOffset);
+            if (c == -1) {
+                break;
+            }
+            chunkOffset += c;
+            if (chunkOffset == chunkSize) {
+                chunkIndex++;
+                chunkOffset = 0;
+                if (chunkIndex == chunks.length) {
+                    FileOutputStream fileOutputStream = switchToTempFile();
+                    IOUtils.copy(in, fileOutputStream);
+                    fileOutputStream.close();
+                    break;
+                }
+            }
+        }
+    }
+    
+    public InputStream getInputStream() throws IOException {
+        if (temporaryFile != null) {
+            return new FileInputStream(temporaryFile);
+        } else {
+            return new InputStreamImpl();
+        }
+    }
+    
+    /**
+     * Write the data to a given output stream.
+     * 
+     * @param out The output stream to write the data to. This method will
+     *            not close the stream.
+     * @throws IOException
+     */
+    public void writeTo(OutputStream out) throws IOException {
+        if (temporaryFile != null) {
+            FileInputStream in = new FileInputStream(temporaryFile);
+            try {
+                IOUtils.copy(in, out);
+            } finally {
+                in.close();
+            }
+        } else {
+            for (int i=0; i<chunkIndex; i++) {
+                out.write(chunks[i]);
+            }
+            if (chunkOffset > 0) {
+                out.write(chunks[chunkIndex], 0, chunkOffset);
+            }
+        }
+    }
+    
+    public long getLength() {
+        if (temporaryFile != null) {
+            return temporaryFile.length();
+        } else {
+            return chunkIndex*chunkSize + chunkOffset;
+        }
+    }
+    
+    public void release() {
+        if (temporaryFile != null) {
+            if (log.isDebugEnabled()) {
+                log.debug("Deleting temporary file " + temporaryFile);
+            }
+            temporaryFile.delete();
+        }
+    }
+
+    protected void finalize() throws Throwable {
+        if (temporaryFile != null) {
+            log.warn("Cleaning up unreleased temporary file " + temporaryFile);
+            temporaryFile.delete();
+        }
+    }
+}

Added: branches/synapse/modules/utils/src/test/java/org/apache/synapse/util/TemporaryDataTest.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/modules/utils/src/test/java/org/apache/synapse/util/TemporaryDataTest.java?pathrev=23649
==============================================================================
--- (empty file)
+++ branches/synapse/modules/utils/src/test/java/org/apache/synapse/util/TemporaryDataTest.java	Mon Nov 10 23:33:31 2008
@@ -0,0 +1,134 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.synapse.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Random;
+
+import org.apache.commons.io.IOUtils;
+
+import junit.framework.TestCase;
+
+public class TemporaryDataTest extends TestCase {
+    private final static Random random = new Random();
+    
+    private void doTestRandomReadWrite(int size) throws IOException {
+        byte[] data = new byte[size];
+        random.nextBytes(data);
+        TemporaryData tmp = new TemporaryData(16, 1024, "test", ".dat");
+        try {
+            OutputStream out = tmp.getOutputStream();
+            // Write the test data in chunks with random size
+            int offset = 0;
+            while (offset < data.length) {
+                int c = Math.min(512 + random.nextInt(1024), data.length - offset);
+                out.write(data, offset, c);
+                offset += c;
+            }
+            out.close();
+            assertEquals(size, tmp.getLength());
+            // Reread the test data, again in chunks with random size
+            InputStream in = tmp.getInputStream();
+            offset = 0;
+            byte[] data2 = new byte[data.length];
+            byte[] buffer = new byte[2048];
+            while (true) {
+                int bufferOffset = random.nextInt(512);
+                int c = 512 + random.nextInt(1024);
+                int read = in.read(buffer, bufferOffset, c);
+                if (read == -1) {
+                    break;
+                }
+                int newOffset = offset + read;
+                assertTrue(newOffset <= data2.length);
+                System.arraycopy(buffer, bufferOffset, data2, offset, read);
+                offset = newOffset;
+            }
+            assertEquals(data2.length, offset);
+            in.close();
+            assertTrue(Arrays.equals(data, data2));
+        }
+        finally {
+            tmp.release();
+        }
+    }
+    
+    public void testRandomReadWriteInMemory() throws IOException {
+        doTestRandomReadWrite(10000);
+    }
+    
+    public void testRandomReadWriteWithTemporaryFile() throws IOException {
+        doTestRandomReadWrite(100000);
+    }
+    
+    public void testMarkReset() throws IOException {
+        byte[] sourceData1 = new byte[2000];
+        byte[] sourceData2 = new byte[2000];
+        random.nextBytes(sourceData1);
+        random.nextBytes(sourceData2);
+        TemporaryData tmp = new TemporaryData(16, 512, "test", ".dat");
+        OutputStream out = tmp.getOutputStream();
+        out.write(sourceData1);
+        out.write(sourceData2);
+        out.close();
+        DataInputStream in = new DataInputStream(tmp.getInputStream());
+        byte[] data1 = new byte[sourceData1.length];
+        byte[] data2 = new byte[sourceData2.length];
+        in.readFully(data1);
+        in.mark(sourceData2.length);
+        in.readFully(data2);
+        in.reset();
+        in.readFully(data2);
+        assertTrue(Arrays.equals(sourceData1, data1));
+        assertTrue(Arrays.equals(sourceData2, data2));
+    }
+    
+    private void testReadFrom(int size) throws IOException {
+        byte[] data = new byte[size];
+        random.nextBytes(data);
+        TemporaryData tmp = new TemporaryData(16, 1024, "test", ".dat");
+        try {
+            tmp.readFrom(new ByteArrayInputStream(data));
+            InputStream in = tmp.getInputStream();
+            try {
+                assertTrue(Arrays.equals(data, IOUtils.toByteArray(in)));
+            }
+            finally {
+                in.close();
+            }
+        }
+        finally {
+            tmp.release();
+        }
+    }
+    
+    public void testReadFromInMemory() throws IOException {
+        testReadFrom(10000);
+    }
+    
+    public void testReadFromWithTemporaryFile() throws IOException {
+        testReadFrom(100000);
+    }
+}

Modified: branches/synapse/pom.xml
URL: http://wso2.org/svn/browse/wso2/branches/synapse/pom.xml?rev=23649&r1=23648&r2=23649&view=diff
==============================================================================
--- branches/synapse/pom.xml	(original)
+++ branches/synapse/pom.xml	Mon Nov 10 23:33:31 2008
@@ -203,6 +203,16 @@
             <!-- Synapse -->
             <dependency>
                 <groupId>org.apache.synapse</groupId>
+                <artifactId>synapse-utils</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.synapse</groupId>
+                <artifactId>synapse-tasks</artifactId>
+                <version>${project.version}</version>
+            </dependency>             
+            <dependency>
+                <groupId>org.apache.synapse</groupId>
                 <artifactId>synapse-core</artifactId>
                 <version>${project.version}</version>
             </dependency>
@@ -1009,7 +1019,11 @@
             <artifactId>quartz</artifactId>
             <version>${quartz.version}</version>
         </dependency>
-
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-jta_1.1_spec</artifactId>
+            <version>${geronimo-spec.version}</version>
+        </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
@@ -1110,6 +1124,8 @@
     </repositories>
 
     <modules>
+        <module>modules/utils</module>
+        <module>modules/tasks</module>
         <module>modules/transports</module>
         <module>modules/mar</module>
         <module>modules/core</module>
@@ -1163,6 +1179,7 @@
         <!-- startup, quartz -->
         <commons-collections.version>3.1</commons-collections.version>
         <quartz.version>1.6.0</quartz.version>
+        <geronimo-spec.version>1.1</geronimo-spec.version>
 
         <!-- xalan xsltc  -->
         <bcel.version>5.2</bcel.version>



More information about the Esb-java-dev mailing list