[jboss-svn-commits] JBL Code SVN: r6227 - labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Sep 14 11:20:11 EDT 2006


Author: tfennelly
Date: 2006-09-14 11:20:03 -0400 (Thu, 14 Sep 2006)
New Revision: 6227

Modified:
   labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractFileAction.java
   labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractSqlRowAction.java
   labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessor.java
   labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummyAction.java
   labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummyFileAction.java
   labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummySqlRowAction.java
   labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/FileCopier.java
   labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/SmooksTransformActionHandler.java
Log:
ActionProcessor pipeline model changes

Modified: labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractFileAction.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractFileAction.java	2006-09-14 13:41:47 UTC (rev 6226)
+++ labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractFileAction.java	2006-09-14 15:20:03 UTC (rev 6227)
@@ -1,97 +1,103 @@
 /*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 
-
 package org.jboss.soa.esb.actions;
 
 import java.io.File;
+import java.io.IOException;
 
-import org.jboss.soa.esb.helpers.DomElement;
-import org.jboss.soa.esb.listeners.GpListener;
-
-public abstract class AbstractFileAction extends AbstractAction 
-{
 /**
- * Extend this class if you need to implement an action class intended to
- * process one file at a time
- * <br/>See FileCopier as an example
- * @param p_oP DomElement - Parameter tree passed by controlling listener
- * @param p_oCurr Object  - This is the object that's going to get processed
- * <br/>All classes that extend AbstractFileAction receive an instance of the internal 
- * <br/>class Params containing info needed to rename the file in different stages
- * <br/>of processing 
+ * <p/>
+ * Extend this class if you need to implement an action class intended to process one file at a time.
+ * <p/>
+ * See {@link org.jboss.soa.esb.actions.FileCopier} as an example.
+ * <p/>
+ * This class are stateful.
+ * @author Esteban.
  */
-	protected AbstractFileAction(DomElement p_oP, Object p_oCurr)
-	{	super(p_oP,p_oCurr);
-	} //________________________________
+public abstract class AbstractFileAction implements ActionProcessor {
+    
+    public static class Params {
+        public boolean bPostDelete;
 
-	public static class Params
-	{
-		public boolean	bPostDelete;
-		public File		oInpF	,oWrkF	,oErrF	,oDoneF;
-		public String toString() { return oInpF.toString(); }
-	} //________________________________
+        public File oInpF, oWrkF, oErrF, oDoneF;
 
-	public boolean isPostDelete() { return ((Params)m_oCurr).bPostDelete; }
-	public File getInputFile() { return ((Params)m_oCurr).oInpF; }
-	public File getWorkFile()  { return ((Params)m_oCurr).oWrkF; }
-	public File getErrorFile() { return ((Params)m_oCurr).oErrF; }
-	public File getDoneOkFile(){ return ((Params)m_oCurr).oDoneF; }
-	
-	public boolean renameToError() { return getWorkFile().renameTo(getErrorFile()); }
-	public boolean renameToDone () { return getWorkFile().renameTo(getDoneOkFile()); }
+        public String toString() {
+            return oInpF.toString();
+        }
+    } // ________________________________
 
-/**
- * Overrides run() in AbstractAction
- * <p/>Files processed by action classes need to be renamed during processing to
- * disable other listeners (or other threads launched by the same listener that
- * started this thread) to pick up the same file
- * <br/>Once processing ends a suffix will be added to the name of the original
- * file that has been processed.  The suffix will be different according to the
- * result of processing (OK or Exception).  Files could be moved to different
- * directories as well
- * <br/> Parameters for these options can be provided at run time in the
- * DomElement (arg 0 in constructor)
- */
-	public void run()
-	{
-		try 
-		{ 
-			processCurrentObject();
-			if (isPostDelete())
-				getWorkFile().delete();
-			else
-				renameToDone();
-			GpListener.notifyOK(m_oParms,getOkNotification());
-		} 
-		catch (Exception e) 
-		{
-			renameToError();
-			GpListener.notifyError(m_oParms,e,getErrorNotification());
-		}
-		finally 
-		{	setChanged();
-			notifyObservers(new Integer(-1)); 
-		}
-	} //________________________________
-	
-} //____________________________________________________________________________
+
+    public static boolean renameToError(Params fileParams) {
+        return fileParams.oWrkF.renameTo(fileParams.oErrF);
+    }
+
+    public static boolean renameToDone(Params fileParams) {
+        return fileParams.oWrkF.renameTo(fileParams.oDoneF);
+    }
+    
+    /**
+     * Files processed by action classes
+     * need to be renamed during processing to disable other listeners (or other
+     * threads launched by the same listener that started this thread) to pick
+     * up the same file <br/>Once processing ends a suffix will be added to the
+     * name of the original file that has been processed. The suffix will be
+     * different according to the result of processing (OK or Exception). Files
+     * could be moved to different directories as well <br/> Parameters for
+     * these options can be provided at run time in the DomElement (arg 0 in
+     * constructor)
+     * @param message The message payload to be processed.
+     * @return The processing result.
+     * @throws ActionProcessingException Exception during payload processing.
+     */
+    public final Object process(Object message) throws ActionProcessingException {
+        if(!(message instanceof Params)) {
+            throw new ActionProcessingException("Message object for processing by " + getClass().getName() 
+                    + " should have been preprocessed and 'normalised' to a " + Params.class.getName() + " instance.");
+        }
+        
+        Params fileParams = (Params)message;
+     
+        // Call the implementing class to process the file message...
+        try {
+            processFile(fileParams);
+        } catch (IOException e) {
+            throw new ActionProcessingException("Failed to process file message: " + fileParams, e);
+        }
+        
+        // Delete or rename the file...
+        if (fileParams.bPostDelete) {
+            fileParams.oWrkF.delete();
+        } else {
+            AbstractFileAction.renameToDone(fileParams);
+        }
+        
+        return message;
+    }
+
+    /**
+     * Process the file message object.
+     * @param fileParams Params re the file to be processed.
+     */
+    protected abstract void processFile(Params fileParams) throws IOException;
+
+} // ____________________________________________________________________________

Modified: labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractSqlRowAction.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractSqlRowAction.java	2006-09-14 13:41:47 UTC (rev 6226)
+++ labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/AbstractSqlRowAction.java	2006-09-14 15:20:03 UTC (rev 6227)
@@ -4,136 +4,161 @@
 
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 
 import javax.sql.DataSource;
 
-import org.jboss.soa.esb.helpers.DomElement;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.KeyValuePair;
 import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
 import org.jboss.soa.esb.helpers.persist.SimpleDataSource;
-import org.jboss.soa.esb.listeners.GpListener;
 import org.jboss.soa.esb.listeners.SqlTablePoller.ROW_STATE;
 
-public abstract class AbstractSqlRowAction  extends AbstractAction 
+public abstract class AbstractSqlRowAction implements ActionProcessor
 {
+
+    protected Logger logger;
 	protected JdbcCleanConn	m_oConn;
-	protected PreparedStatement m_PSsel4U	,m_PSupd;
 
-	protected AbstractSqlRowAction(DomElement p_oP, Object p_oCurr) throws Exception
+	protected AbstractSqlRowAction(String actionName, List<KeyValuePair>properties) throws Exception
 	{
-		super(p_oP,p_oCurr);
-		DataSource oDS	= new SimpleDataSource(m_oParms);
+        
+		DataSource oDS	= new SimpleDataSource(
+                KeyValuePair.getValue(SimpleDataSource.DRIVER, properties),
+                KeyValuePair.getValue(SimpleDataSource.URL, properties),
+                KeyValuePair.getValue(SimpleDataSource.USER, properties),
+                KeyValuePair.getValue(SimpleDataSource.PASSWORD, properties));
 		m_oConn			= new JdbcCleanConn(oDS);
-		m_PSsel4U		= m_oConn.prepareStatement(getSel4Upd());
-		m_PSupd			= m_oConn.prepareStatement(getUpdStmt());	
-
-		int iParm=1;
-  		for (String sColName : getKeys())
-  		{	
-  			Object oVal	= getColumnValue(sColName);
-  			m_PSsel4U.setObject	(iParm	,oVal);
-  			// parameters are +1 in update statement
-  			// autoincrement leaves things ready for next SQL parameter
-  			m_PSupd.setObject	(++iParm,oVal);
-  		}
-	} //________________________________
-	
-	public static class Params
-	{
-		public String	sUpdStates;
-		public String[]	saCols	,saKeys;
-		public String	sSel4Upd,sUpdate;
-		public Map<String,Object> omVals;
-		public String toString() { return omVals.toString(); }
-	} //________________________________
-
-	protected String getSel4Upd()
-	{	return ((Params)m_oCurr).sSel4Upd;
-	} //________________________________
-
-	protected String getUpdStmt()
-	{	return ((Params)m_oCurr).sUpdate;
-	} //________________________________
-
-	protected String getStatus(ROW_STATE p_oState)
-	{	int iPos = p_oState.ordinal();
-		return ((Params)m_oCurr).sUpdStates.substring(iPos,++iPos);
-	} //________________________________
-
-	protected Object getColumnValue(String p_sKey)
-	{	return ((Params)m_oCurr).omVals.get(p_sKey);
-	} //________________________________
-
-	protected String[] getKeys()
-	{	return ((Params)m_oCurr).saKeys;
-	} //________________________________
-
-	private boolean changeStatus (ROW_STATE pFrom, ROW_STATE pTo) throws Exception
-	{	ResultSet RS = m_oConn.execQueryWait(m_PSsel4U,5);
-		if (! RS.next())
-	  		return false;
-	  	if (null!=pFrom)
-	  	{	String sOldStatus = RS.getString(1).substring(0,1);
-	  		if (!sOldStatus.equalsIgnoreCase(getStatus(pFrom)))
-	  		{	m_oConn.rollback();
-	  			return false;
-	  		}
-	  	}
-	  	m_PSupd.setString(1,getStatus(pTo));
-	  	m_oConn.execUpdWait(m_PSupd,5);
-	  	m_oConn.commit();
-	  	
-		return true;
-	} //______________________________
-
-	public void run()
-	{
+        logger = Logger.getLogger(getClass());
+	}
+    
+    public Object process(Object message) throws ActionProcessingException {
+        if(!(message instanceof Params)) {
+            throw new ActionProcessingException("Message object for processing by " + getClass().getName() 
+                    + " should have been preprocessed and 'normalised' to a " + Params.class.getName() + " instance.");
+        }
+        
+        Params sqlParams = (Params)message;
+        PreparedStatement m_PSsel4U   ,m_PSupd;
+        
+        try {
+            m_PSsel4U       = m_oConn.prepareStatement(sqlParams.getSel4Upd());
+            m_PSupd         = m_oConn.prepareStatement(sqlParams.getUpdStmt());
+            int iParm=1;
+            for (String sColName : sqlParams.getKeys())
+            {   
+                Object oVal = sqlParams.getColumnValue(sColName);
+                m_PSsel4U.setObject (iParm  ,oVal);
+                // parameters are +1 in update statement
+                // autoincrement leaves things ready for next SQL parameter
+                m_PSupd.setObject   (++iParm,oVal);
+            }
+        } catch(Exception e) {
+            throw new ActionProcessingException("Exception processing SQL action.", e);
+        }
+        
   		// will only continue if it can change status to "Working"
 		try
 		{
-	  		if (! changeStatus(ROW_STATE.Pending,ROW_STATE.Working))
-	  		{	m_oLogger.warn("Unable to change status to Working");
+	  		if (! changeStatus(sqlParams, m_PSsel4U, m_PSupd, ROW_STATE.Pending,ROW_STATE.Working))
+	  		{	logger.warn("Unable to change status to Working");
 	  			m_oConn.rollback();
 	  			cleanup();
-	  			return;
+	  			return message;
 	  		}
 	 		m_oConn.commit();			
 		}
 		catch(Exception e)
-		{	m_oLogger.error("Unable to change status to Working",e);
+		{	logger.error("Unable to change status to Working",e);
 			cleanup();
-			return;
+			return message;
 		}
 
 		try 
 		{ 
-			processCurrentObject();
-			changeStatus(ROW_STATE.Working,ROW_STATE.Done);
+			processSQL(sqlParams, m_PSsel4U, m_PSupd);
+			changeStatus(sqlParams, m_PSsel4U, m_PSupd, ROW_STATE.Working,ROW_STATE.Done);
 			m_oConn.commit();
-			GpListener.notifyOK(m_oParms,getOkNotification());
 		} 
 		catch (Exception e) 
 		{
 			try 
-			{	changeStatus(ROW_STATE.Working,ROW_STATE.Error); 
+			{	changeStatus(sqlParams, m_PSsel4U, m_PSupd, ROW_STATE.Working,ROW_STATE.Error); 
 				m_oConn.commit();
 			}
 			catch (Exception eErr)
 			{
-				m_oLogger.error("Unable to change status to ERROR - Really weird - shouldn't happen");
+				logger.error("Unable to change status to ERROR - Really weird - shouldn't happen");
 			}
-			GpListener.notifyError(m_oParms,e,getErrorNotification());
 		}
 		finally { cleanup(); }
+        
+        return message;
 	} //________________________________
+    
+    /**
+     * Process the SQL message.
+     * @param sqlParams SQL Pararmeters.
+     * @param ssel4U Select for 
+     * @param supd
+     */
+    protected abstract void processSQL(Params sqlParams, PreparedStatement ssel4U, PreparedStatement supd) throws SQLException;
+
+    private boolean changeStatus (Params sqlParams, PreparedStatement ssel4U, PreparedStatement supd, ROW_STATE pFrom, ROW_STATE pTo) throws Exception
+    {   ResultSet RS = m_oConn.execQueryWait(ssel4U,5);
+        if (! RS.next())
+            return false;
+        if (null!=pFrom)
+        {   String sOldStatus = RS.getString(1).substring(0,1);
+            if (!sOldStatus.equalsIgnoreCase(sqlParams.getStatus(pFrom)))
+            {   m_oConn.rollback();
+                return false;
+            }
+        }
+        supd.setString(1, sqlParams.getStatus(pTo));
+        m_oConn.execUpdWait(supd,5);
+        m_oConn.commit();
+        
+        return true;
+    } //______________________________
 	
 	private void cleanup()
-	{	setChanged();
-		notifyObservers(new Integer(-1));
+	{	
 		if (null!=m_oConn)
 		{	try	{	m_oConn.rollback(); }
 			catch(Exception e)	{ /* OK just continue */ }
 			m_oConn.release();
 		}
 	} //________________________________
-	
+
+    public static class Params
+    {
+        public String   sUpdStates;
+        public String[] saCols  ,saKeys;
+        public String   sSel4Upd,sUpdate;
+        public Map<String,Object> omVals;
+        public String toString() { return omVals.toString(); }
+
+        protected String getSel4Upd()
+        {   return sSel4Upd;
+        } //________________________________
+
+        protected String getUpdStmt()
+        {   return sUpdate;
+        } //________________________________
+
+        protected String getStatus(ROW_STATE p_oState)
+        {   int iPos = p_oState.ordinal();
+            return sUpdStates.substring(iPos,++iPos);
+        } //________________________________
+
+        protected Object getColumnValue(String p_sKey)
+        {   return omVals.get(p_sKey);
+        } //________________________________
+
+        protected String[] getKeys()
+        {   return saKeys;
+        } //________________________________
+    } 
+
 } //____________________________________________________________________________

Modified: labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessor.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessor.java	2006-09-14 13:41:47 UTC (rev 6226)
+++ labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/ActionProcessor.java	2006-09-14 15:20:03 UTC (rev 6227)
@@ -22,6 +22,8 @@
 
 package org.jboss.soa.esb.actions;
 
+import java.io.Serializable;
+
 /**
  * Action Processor Interface Definition.
  * <p/>
@@ -45,4 +47,18 @@
      * @throws ActionProcessingException Exception during payload processing.
      */
     public Object process(Object message) throws ActionProcessingException;
+
+    /**
+     * Get the "OK" notification message for this processor.
+     * @param message The message Object.
+     * @return The OK message.
+     */
+    public abstract Serializable getOkNotification(Object message);
+
+    /**
+     * Get the "Error" notification message for this processor.
+     * @param message The message Object.
+     * @return The Error message.
+     */
+    public abstract Serializable getErrorNotification(Object message);
 }

Modified: labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummyAction.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummyAction.java	2006-09-14 13:41:47 UTC (rev 6226)
+++ labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummyAction.java	2006-09-14 15:20:03 UTC (rev 6227)
@@ -3,56 +3,43 @@
 import java.io.Serializable;
 import java.text.*;
 
-import org.jboss.soa.esb.helpers.DomElement;
-import org.jboss.soa.esb.listeners.GpListener;
+import org.apache.log4j.Logger;
+
+
 /**
- * Use this class to tune your XML configurations
- * <p/>Once your config works with this dummy class, you can
- * switch to your own action class
- * <p/>You will have to implement these three methods 
- * in your own action class
+ * Use this class to tune your XML configurations <p/>Once your config works
+ * with this dummy class, you can switch to your own action class <p/>You will
+ * have to implement these three methods in your own action class
  * 
  * @author Esteban
- *
+ * 
  */
-public class DummyAction extends AbstractAction 
-{
-/**
- * Constructor must always have the configuration tree and the object
- * that the run() method will process
- * @param p_oP
- * @param p_oCurr
- */
-	public DummyAction(DomElement p_oP, Object p_oCurr) throws Exception
-	{
-		super(p_oP,p_oCurr);
-	}
-	
-	@Override
-	public void processCurrentObject() throws Exception 
-	{
-		m_oLogger.info("processObject was called with <<"
-				+m_oCurr.toString()+">>");
-	} //________________________________
-	
-	private SimpleDateFormat s_oTS = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss.SSS");
-	private String getStamp() 
-		{ return s_oTS.format(new java.util.Date(System.currentTimeMillis())); }
+public class DummyAction implements ActionProcessor {
+    /**
+     * Class Logger.
+     */
+    private static Logger logger = Logger.getLogger(DummyAction.class);
 
-	@Override
-	public Serializable getOkNotification()
-	{
-		return getStamp()+" Notif OK - <"
-		+((null==m_oCurr)?"null":m_oCurr.toString())
-		+">";
-	} //________________________________
+    public Object process(Object message) {
+        logger.info("process was called with <<" + message.toString() + ">>");
+        return message;
+    } // ________________________________
 
-	@Override
-	public Serializable getErrorNotification()
-	{
-		return getStamp()+" Notif ERROR - <"
-		+((null==m_oCurr)?"null":m_oCurr.toString())
-		+">";
-	} //________________________________
-	
-} //____________________________________________________________________________
+    private SimpleDateFormat s_oTS = new SimpleDateFormat(
+            "yyyy/MM/dd hh:mm:ss.SSS");
+
+    private String getStamp() {
+        return s_oTS.format(new java.util.Date(System.currentTimeMillis()));
+    }
+
+    public Serializable getOkNotification(Object message) {
+        return getStamp() + " Notif OK - <"
+                + ((null == message) ? "null" : message.toString()) + ">";
+    } // ________________________________
+
+    public Serializable getErrorNotification(Object message) {
+        return getStamp() + " Notif ERROR - <"
+                + ((null == message) ? "null" : message.toString()) + ">";
+    } // ________________________________
+
+} // ____________________________________________________________________________

Modified: labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummyFileAction.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummyFileAction.java	2006-09-14 13:41:47 UTC (rev 6226)
+++ labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummyFileAction.java	2006-09-14 15:20:03 UTC (rev 6227)
@@ -3,7 +3,8 @@
 import java.io.Serializable;
 import java.text.*;
 
-import org.jboss.soa.esb.helpers.DomElement;
+import org.apache.log4j.Logger;
+
 /**
  * Use this class to tune your XML configurations
  * <p/>Once your config works with this dummy class, you can
@@ -16,41 +17,29 @@
  */
 public class DummyFileAction extends AbstractFileAction 
 {
-/**
- * Constructor must always have the configuration tree and the object
- * that the run() method will process
- * @param p_oP
- * @param p_oCurr
- */
-	public DummyFileAction(DomElement p_oP, Object p_oCurr) throws Exception
-	{
-		super(p_oP,p_oCurr);
-	}
+    private static Logger logger = Logger.getLogger(DummyFileAction.class);
 	
 	@Override
-	public void processCurrentObject() throws Exception 
+	public void processFile(Params fileParams) 
 	{
-		m_oLogger.info("processObject was called with <<"
-				+m_oCurr.toString()+">>");
+        logger.info("processObject was called with <<" + fileParams.toString() + ">>");
 	} //________________________________
 	
 	private SimpleDateFormat s_oTS = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss.SSS");
 	private String getStamp() 
 		{ return s_oTS.format(new java.util.Date(System.currentTimeMillis())); }
 
-	@Override
-	public Serializable getOkNotification()
+	public Serializable getOkNotification(Object message)
 	{
 		return getStamp()+" Notif OK - <"
-		+((null==m_oCurr)?"null":m_oCurr.toString())
+		+((null==message)?"null":message.toString())
 		+">";
 	} //________________________________
 
-	@Override
-	public Serializable getErrorNotification()
+	public Serializable getErrorNotification(Object message)
 	{
 		return getStamp()+" Notif ERROR - <"
-		+((null==m_oCurr)?"null":m_oCurr.toString())
+		+((null==message)?"null":message.toString())
 		+">";
 	} //________________________________
 	

Modified: labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummySqlRowAction.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummySqlRowAction.java	2006-09-14 13:41:47 UTC (rev 6226)
+++ labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/DummySqlRowAction.java	2006-09-14 15:20:03 UTC (rev 6227)
@@ -1,9 +1,13 @@
 package org.jboss.soa.esb.actions;
 
 import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
 import java.text.*;
+import java.util.List;
 
-import org.jboss.soa.esb.helpers.DomElement;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
 /**
  * Use this class to tune your XML configurations
  * <p/>Once your config works with this dummy class, you can
@@ -16,42 +20,35 @@
  */
 public class DummySqlRowAction extends AbstractSqlRowAction 
 {
-/**
- * Constructor must always have the configuration tree and the object
- * that the run() method will process
- * @param p_oP
- * @param p_oCurr
- */
-	public DummySqlRowAction(DomElement p_oP, Object p_oCurr) throws Exception
-	{
-		super(p_oP,p_oCurr);
-	}
+
+    protected DummySqlRowAction(String actionName, List<KeyValuePair> properties) throws Exception {
+        super(actionName, properties);
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.soa.esb.actions.AbstractSqlRowAction#processSQL(org.jboss.soa.esb.actions.AbstractSqlRowAction.Params, java.sql.PreparedStatement, java.sql.PreparedStatement)
+     */
+    @Override
+    protected void processSQL(Params sqlParams, PreparedStatement ssel4U, PreparedStatement supd) throws SQLException {
+        logger.info("processObject was called with <<"
+                + sqlParams.toString()+">>");
+    }
 	
-	@Override
-	public void processCurrentObject() throws Exception 
-	{
-		m_oLogger.info("processObject was called with <<"
-				+m_oCurr.toString()+">>");
-	} //________________________________
-	
 	private SimpleDateFormat s_oTS = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss.SSS");
 	private String getStamp() 
 		{ return s_oTS.format(new java.util.Date(System.currentTimeMillis())); }
 
-	@Override
-	public Serializable getOkNotification()
+	public Serializable getOkNotification(Object message)
 	{
 		return getStamp()+" Notif OK - <"
-		+((null==m_oCurr)?"null":m_oCurr.toString())
+		+((null==message)?"null":message.toString())
 		+">";
 	} //________________________________
 
-	@Override
-	public Serializable getErrorNotification()
+	public Serializable getErrorNotification(Object message)
 	{
 		return getStamp()+" Notif ERROR - <"
-		+((null==m_oCurr)?"null":m_oCurr.toString())
+		+((null==message)?"null":message.toString())
 		+">";
 	} //________________________________
-	
 } //____________________________________________________________________________

Modified: labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/FileCopier.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/FileCopier.java	2006-09-14 13:41:47 UTC (rev 6226)
+++ labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/FileCopier.java	2006-09-14 15:20:03 UTC (rev 6227)
@@ -1,107 +1,110 @@
 /*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 
 package org.jboss.soa.esb.actions;
 
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.Serializable;
 import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
 
 import org.jboss.soa.esb.helpers.*;
 
-public class FileCopier extends AbstractFileAction
-{
-  private static final String TMP_SUFFIX    = ".notReady";
-  private static final String PARMS_COPY_TO = "CopyTo";
-  private static final String PARMS_OUTDIR  = "copyToDirURI";
-  private static final String PARMS_OUTSFX  = "copyToSuffix";
+/**
+ * File copy action.
+ * <p/>
+ * Copy the file specified by the "fileParams" arg in {@link #processFile(Params)} to the location specified by the 
+ * action config properties.
+ * <p/>
+ * Sample Action Configuration:
+ * <pre>
+ * &lt;Action name="Copy-To-XXX" processor="FileCopier"&gt;
+ *     &lt;property name="copyToDirURI" value="file:///..." /&gt;
+ *     &lt;property name="copyToSuffix" value=".fileCopierOutput" /&gt;
+ * &lt;/Action&gt;
+ * </pre>
+ * 
+ * @author Esteban
+ */
+public class FileCopier extends AbstractFileAction {
+    
+    private static final String TMP_SUFFIX = ".notReady";
 
-  private File []     m_oaTmpFile;
-  private File []     m_oaOutFile;
+    private static final String PARMS_OUTDIR = "copyToDirURI";
 
-  public FileCopier(DomElement p_oP, Object p_oCurr) throws Exception
-  { super(p_oP,p_oCurr);
-    checkMyParms();
-  } //__________________________________
+    private static final String PARMS_OUTSFX = "copyToSuffix";
 
-  public void processCurrentObject() throws Exception
-  {
-      // Open & create temp files
-      FileInputStream oFI     = new FileInputStream(getWorkFile());
-      FileOutputStream []oaFO = new FileOutputStream[m_oaTmpFile.length];
-      for (int i1=0; i1<oaFO.length;i1++)
-        oaFO[i1]  = new FileOutputStream(m_oaTmpFile[i1]);
+    private File outputDir;
+    private String copyToSuffix;
 
-      //  Perform Copy
-      byte[] ba = new byte[50000];
-      while (true)
-      { int iQ = oFI.read(ba);
-        if (iQ < 0)     break;
-        for (int i1=0; i1<oaFO.length; i1++)
-          oaFO[i1].write(ba,0,iQ);
-      }
-      //  Close
-      oFI.close();
-      for (int i1=0; i1<oaFO.length; i1++)  oaFO[i1].close();
+    public FileCopier(String actionName, List<KeyValuePair> properties) throws URISyntaxException {
+        URI outputDirURI = new URI(KeyValuePair.getValue(PARMS_OUTDIR, properties));
+        
+        outputDir = new File(outputDirURI);
+        copyToSuffix = KeyValuePair.getValue(PARMS_OUTSFX, properties);
+    } // __________________________________
 
-      //  Rename
-      for (int i1=0; i1<m_oaTmpFile.length;i1++)
-      { m_oaOutFile[i1].delete();
-        m_oaTmpFile[i1].renameTo(m_oaOutFile[i1]);
-      }
-  } //__________________________________
+    public void processFile(Params fileParams) throws IOException {
+        
+        String inputFileName = fileParams.oInpF.getName();
+        File tempFile = File.createTempFile(inputFileName, TMP_SUFFIX, outputDir);
+        File outputFile = new File(outputDir, inputFileName + copyToSuffix);
+        FileInputStream inputFileStream = new FileInputStream(fileParams.oWrkF);
+        FileOutputStream outputFileStream;
+        
+        outputFileStream = new FileOutputStream(tempFile);
 
-  protected void checkMyParms() throws Exception
-  { DomElement[] oaPout = m_oParms.getElementChildren(PARMS_COPY_TO);
-    m_oaTmpFile  = new File[oaPout.length];
-    m_oaOutFile  = new File[oaPout.length];
+        // Perform Copy
+        byte[] ba = new byte[50000];
+        while (true) {
+            int iQ = inputFileStream.read(ba);
+            
+            if (iQ < 0) {
+                break;
+            }
 
-    if (oaPout.length<1)
-    { m_oLogger.warn("No output files specified for FileCopier");
-      return;
+            outputFileStream.write(ba, 0, iQ);
+        }
+        // Close
+        inputFileStream.close();
+        outputFileStream.close();
+
+        // Rename
+        outputFile.delete();
+        tempFile.renameTo(outputFile);
+    } // __________________________________
+
+    public Serializable getOkNotification(Object message) {
+        return "File " + ((Params)message).oInpF
+                + " successfully copied to all destinations";
     }
-    String sFile  = getInputFile().getName();
 
-    for (int i1=0; i1<m_oaTmpFile.length;i1++)
-    { File oDir  = new File(new URI(oaPout[i1].getAttr(PARMS_OUTDIR)));
-      m_oaTmpFile[i1] = File.createTempFile(sFile, TMP_SUFFIX, oDir);
-      String sCpySuffix = oaPout[i1].getAttr(PARMS_OUTSFX);
-      m_oaOutFile[i1] = new File(oDir,getInputFile().getName()+sCpySuffix);
+    public Serializable getErrorNotification(Object message) {
+        return "Problems copying " + ((Params)message).oInpF
+                + " to configured destinations";
     }
-    return;
-  } //__________________________________
 
-  @Override
-  public Serializable getOkNotification() 
-  {
-	  return "File "+getInputFile()+" successfully copied to all destinations";
-  } //__________________________________
-	
-  @Override
-  public Serializable getErrorNotification()
-  {
-	  return "Problems copying "+getInputFile()+" to configured destinations";
-  } //__________________________________
-
-} //____________________________________________________________________________
+} // ____________________________________________________________________________

Modified: labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/SmooksTransformActionHandler.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/SmooksTransformActionHandler.java	2006-09-14 13:41:47 UTC (rev 6226)
+++ labs/jbossesb/workspace/tfennelly/product/core/listeners/src/org/jboss/soa/esb/actions/SmooksTransformActionHandler.java	2006-09-14 15:20:03 UTC (rev 6227)
@@ -22,6 +22,7 @@
 
 package org.jboss.soa.esb.actions;
 
+import java.io.Serializable;
 import java.util.List;
 
 import org.jboss.soa.esb.helpers.KeyValuePair;
@@ -39,10 +40,24 @@
 	}
 
     /* (non-Javadoc)
-     * @see org.jboss.soa.esb.actions.ActionProcessor#processAction(java.lang.Object)
+     * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
      */
-    public Object process(Object payload) {
-        System.out.println("processAction: " + payload);
-        return payload;
+    public Object process(Object message) {
+        System.out.println("processAction: " + message);
+        return message;
     }
+
+    /* (non-Javadoc)
+     * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+     */
+    public Serializable getOkNotification(Object message) {
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+     */
+    public Serializable getErrorNotification(Object message) {
+        return null;
+    }
 }




More information about the jboss-svn-commits mailing list