[jboss-svn-commits] JBL Code SVN: r8273 - in labs/jbossesb/trunk/product/core/rosetta/src/org/jboss: internal/soa/esb/util soa/esb/util

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Dec 12 18:24:41 EST 2006


Author: b_georges
Date: 2006-12-12 18:24:36 -0500 (Tue, 12 Dec 2006)
New Revision: 8273

Added:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/FtpUtils.java
Modified:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystem.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java
Log:
Added Support for EPR to the RemoteFileSystemFactory, started the implementation in the sub classes.
Removed the getInstance method of the Factory. It is not needed while preserving the factory pattern.
note that the current method which takes ConfigTree as argument will be replaced by the new one which takes the FTPEpr

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java	2006-12-12 21:56:14 UTC (rev 8272)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/EdtFtpImpl.java	2006-12-12 23:24:36 UTC (rev 8273)
@@ -25,8 +25,10 @@
 import java.net.UnknownHostException;
 import java.util.List;
 
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.util.FtpClientUtil;
 import org.jboss.soa.esb.util.RemoteFileSystem;
 
 import com.enterprisedt.net.ftp.FTPClient;
@@ -46,12 +48,10 @@
  * </p>
  */
 
-public class EdtFtpImpl implements RemoteFileSystem
-{
+public class EdtFtpImpl implements RemoteFileSystem {
 	private static final String TMP_SUFFIX = ".rosettaPart";
 
-	public enum XFER_TYPE
-	{
+	public enum XFER_TYPE {
 		ascii, binary
 	};
 
@@ -70,8 +70,7 @@
 	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#getRemoteDir()
 	 */
-	public String getRemoteDir()
-	{
+	public String getRemoteDir() {
 		return m_sRemoteDir;
 	}
 
@@ -97,32 +96,29 @@
 	 *             in remote computer </li>
 	 */
 
-	public EdtFtpImpl(ConfigTree p_oP, boolean p_bConnect) throws Exception
-	{
+	public EdtFtpImpl(ConfigTree p_oP, boolean p_bConnect) throws Exception {
 		m_oParms = p_oP;
 		initialize(p_bConnect);
 	}
 
+	public EdtFtpImpl(FTPEpr p_oP, boolean p_bConnect) throws Exception {
+		// TODO initialize
+	}
+
 	public EdtFtpImpl(List<KeyValuePair> attribs, boolean connect)
-			throws Exception
-	{
+			throws Exception {
 		m_oParms = new ConfigTree("fromProps");
 		for (KeyValuePair oCurr : attribs)
 			m_oParms.setAttribute(oCurr.getKey(), oCurr.getValue());
 		initialize(connect);
 	}
 
-	private void initialize(boolean bConnect) throws Exception
-	{
+	private void initialize(boolean bConnect) throws Exception {
 		checkParms();
-		if (bConnect)
-		{
-			try
-			{
+		if (bConnect) {
+			try {
 				m_oConn.setRemoteHost(m_sFtpServer);
-			}
-			catch (UnknownHostException ex)
-			{
+			} catch (UnknownHostException ex) {
 				ex.printStackTrace();
 
 				throw ex;
@@ -131,7 +127,7 @@
 			m_oConn.connect();
 			for (int i1 = 0; i1 < 10 && !m_oConn.connected(); i1++)
 				Thread.sleep(200); // TODO arbitrary MAGIC number!
-									// Configurable?
+			// Configurable?
 			if (!m_oConn.connected())
 				throw new Exception("Can't connect to FTP server");
 			m_oConn.user(m_sUser);
@@ -146,16 +142,12 @@
 	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#quit()
 	 */
-	public void quit()
-	{
+	public void quit() {
 		if (null != m_oConn)
-			try
-			{
+			try {
 				m_oConn.quit();
+			} catch (Exception e) {
 			}
-			catch (Exception e)
-			{
-			}
 	}
 
 	/*
@@ -163,10 +155,9 @@
 	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#deleteRemoteFile(java.lang.String)
 	 */
-	public void deleteRemoteFile(String p_sFile) throws Exception
-	{
+	public void deleteRemoteFile(String p_sFile) throws Exception {
 		// TODO improve error handling.
-		
+
 		m_oConn.delete(getRemoteDir() + "/" + new File(p_sFile).getName());
 	}
 
@@ -175,9 +166,8 @@
 	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#remoteDelete(java.io.File)
 	 */
-	public void remoteDelete(File p_oFile) throws Exception
-	{
-		m_oConn.delete(fileToFtpString(p_oFile));
+	public void remoteDelete(File p_oFile) throws Exception {
+		m_oConn.delete(FtpUtils.fileToFtpString(p_oFile));
 	}
 
 	/*
@@ -185,8 +175,7 @@
 	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#getFileListFromRemoteDir(java.lang.String)
 	 */
-	public String[] getFileListFromRemoteDir(String p_sSuffix) throws Exception
-	{
+	public String[] getFileListFromRemoteDir(String p_sSuffix) throws Exception {
 		String sSuffix = (null == p_sSuffix) ? "*" : "*" + p_sSuffix;
 		return m_oConn.dir(sSuffix);
 	}
@@ -196,10 +185,9 @@
 	 * 
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#setRemoteDir(java.lang.String)
 	 */
-	public void setRemoteDir(String p_sDir) throws Exception
-	{
+	public void setRemoteDir(String p_sDir) throws Exception {
 		// TODO deal with null string
-		
+
 		m_oConn.chdir(p_sDir);
 	}
 
@@ -210,18 +198,14 @@
 	 *      java.lang.String)
 	 */
 	public void renameInRemoteDir(String p_sFrom, String p_sTo)
-			throws Exception
-	{
+			throws Exception {
 		String sRmtFrom = new File(p_sFrom).getName();
 		String sRmtTo = new File(p_sTo).getName();
 
-		try
-		{
+		try {
 			m_oConn.rename(getRemoteDir() + "/" + sRmtFrom, getRemoteDir()
 					+ "/" + sRmtTo);
-		}
-		catch (Exception e)
-		{
+		} catch (Exception e) {
 			String sMess = this.getClass().getSimpleName()
 					+ " can't rename in remote directory <" + e.getMessage()
 					+ ">";
@@ -235,14 +219,11 @@
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#remoteRename(java.io.File,
 	 *      java.io.File)
 	 */
-	public void remoteRename(File p_oFrom, File p_oTo) throws Exception
-	{
-		try
-		{
-			m_oConn.rename(fileToFtpString(p_oFrom), fileToFtpString(p_oTo));
-		}
-		catch (Exception e)
-		{
+	public void remoteRename(File p_oFrom, File p_oTo) throws Exception {
+		try {
+			m_oConn.rename(FtpClientUtil.fileToFtpString(p_oFrom), FtpUtils
+					.fileToFtpString(p_oTo));
+		} catch (Exception e) {
 			String sMess = this.getClass().getSimpleName()
 					+ " can't rename in remote directory <" + e.getMessage()
 					+ ">";
@@ -256,12 +237,11 @@
 	 * @see org.jboss.soa.esb.util.RemoteFileSystem#uploadFile(java.io.File,
 	 *      java.lang.String)
 	 */
-	public void uploadFile(File p_oFile, String p_sRemoteName) throws Exception
-	{
+	public void uploadFile(File p_oFile, String p_sRemoteName) throws Exception {
 		String sRemoteOK = getRemoteDir() + "/" + p_sRemoteName;
 		String sRemoteTmp = sRemoteOK + TMP_SUFFIX;
 		m_oConn.setType(m_oXferType);
-		m_oConn.put(fileToFtpString(p_oFile), sRemoteTmp);
+		m_oConn.put(FtpUtils.fileToFtpString(p_oFile), sRemoteTmp);
 		m_oConn.rename(sRemoteTmp, sRemoteOK);
 	}
 
@@ -272,20 +252,16 @@
 	 *      java.lang.String)
 	 */
 	public void downloadFile(String p_sFile, String p_sFinalName)
-			throws Exception
-	{
+			throws Exception {
 		File oLocalDir = new File(m_sLocalDir);
 		File oLclFile = File.createTempFile("Rosetta_", TMP_SUFFIX, oLocalDir);
 
-		try
-		{
+		try {
 			oLclFile.delete();
+		} catch (Exception e) {
 		}
-		catch (Exception e)
-		{
-		}
 		m_oConn.setType(m_oXferType);
-		m_oConn.get(fileToFtpString(oLclFile), p_sFile);
+		m_oConn.get(FtpUtils.fileToFtpString(oLclFile), p_sFile);
 
 		File oNew = new File(oLocalDir, p_sFinalName);
 		if (oNew.exists())
@@ -297,14 +273,12 @@
 	// It appears that there's some kind of bug in the edtftpj.jar library
 	// The !XFER_TYPE.ascii.equals(p_oMode) should NOT be negated
 	// But it works when negated (newlines from Unix to DOS)
-	private void setXferType(XFER_TYPE p_oMode)
-	{
+	private void setXferType(XFER_TYPE p_oMode) {
 		m_oXferType = !XFER_TYPE.ascii.equals(p_oMode) ? FTPTransferType.ASCII
 				: FTPTransferType.BINARY;
 	}
 
-	private void checkParms() throws Exception
-	{
+	private void checkParms() throws Exception {
 		m_sFtpServer = m_oParms.getAttribute(PARMS_FTP_SERVER);
 		if (null == m_sFtpServer)
 			throw new Exception("No FTP server specified");
@@ -341,9 +315,4 @@
 		return;
 	}
 
-	public static String fileToFtpString(File p_oF)
-	{
-		return (null == p_oF) ? null : p_oF.toString().replace("\\", "/");
-	}
-
 }
\ No newline at end of file

Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/FtpUtils.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/FtpUtils.java	2006-12-12 21:56:14 UTC (rev 8272)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/FtpUtils.java	2006-12-12 23:24:36 UTC (rev 8273)
@@ -0,0 +1,42 @@
+/*
+ * 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.internal.soa.esb.util;
+
+import java.io.File;
+
+/**
+ * Ftp handling utilities.
+ * @author b_georges
+ */
+public class FtpUtils {
+
+	/**
+	 * Transforms File path to FTP path
+	 * @param p_oF The file to transform
+	 * @return The modified path
+	 */
+	public static String fileToFtpString(File p_oF)
+	{
+		return (null == p_oF) ? null : p_oF.toString().replace("\\", "/");
+	}
+	
+}

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java	2006-12-12 21:56:14 UTC (rev 8272)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/util/SecureFtpImpl.java	2006-12-12 23:24:36 UTC (rev 8273)
@@ -30,6 +30,7 @@
 import java.util.List;
 import java.util.Vector;
 
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.helpers.KeyValuePair;
 import org.jboss.soa.esb.util.RemoteFileSystem;
@@ -106,6 +107,20 @@
 	/*
 	 * Constructor
 	 * 
+	 * @param p_oP Is an EPR used to initialize the object
+	 * 
+	 * @param connect If true create a new sftp session
+	 * 
+	 */
+	public SecureFtpImpl(FTPEpr p_oP, boolean p_bConnect) throws Exception
+	{
+		
+		// TODO initialize
+	}
+
+	/*
+	 * Constructor
+	 * 
 	 * @param attribs The key/value pairs used to initialize the object
 	 * 
 	 * @param connect If true create a new sftp session using attribs
@@ -207,7 +222,7 @@
 	 */
 	public void remoteDelete(File p_oFile) throws Exception
 	{
-		m_oSftpChannel.rm(fileToFtpString(p_oFile));
+		m_oSftpChannel.rm(FtpUtils.fileToFtpString(p_oFile));
 	}
 
 	/*
@@ -296,8 +311,8 @@
 	{
 		try
 		{
-			m_oSftpChannel.rename(fileToFtpString(p_oFrom),
-					fileToFtpString(p_oTo));
+			m_oSftpChannel.rename(FtpUtils.fileToFtpString(p_oFrom),
+					FtpUtils.fileToFtpString(p_oTo));
 		} catch (Exception e)
 		{
 			String sMess = this.getClass().getSimpleName()
@@ -322,7 +337,7 @@
 		String sRemoteOK = getRemoteDir() + "/" + p_sRemoteName;
 		String sRemoteTmp = sRemoteOK + TMP_SUFFIX;
 		// m_oSftpChannel.setType(m_oXferType);
-		m_oSftpChannel.put(fileToFtpString(p_oFile), sRemoteTmp);
+		m_oSftpChannel.put(FtpUtils.fileToFtpString(p_oFile), sRemoteTmp);
 		m_oSftpChannel.rename(sRemoteTmp, sRemoteOK);
 	}
 
@@ -350,7 +365,7 @@
 		}
 		// TODO check if we have to set the Transfer Type with JSch impl =>
 		// m_oXferType
-		m_oSftpChannel.get(fileToFtpString(oLclFile), p_sFile);
+		m_oSftpChannel.get(FtpUtils.fileToFtpString(oLclFile), p_sFile);
 
 		File oNew = new File(oLocalDir, p_sFinalName);
 		if (oNew.exists())
@@ -378,9 +393,6 @@
 		m_oSftpChannel.quit();
 	}
 
-	public static String fileToFtpString(File p_oF)
-	{
-		return (null == p_oF) ? null : p_oF.toString().replace("\\", "/");
-	}
+	
 
 }

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystem.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystem.java	2006-12-12 21:56:14 UTC (rev 8272)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystem.java	2006-12-12 23:24:36 UTC (rev 8273)
@@ -1,24 +1,24 @@
 /*
-* 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.util;
 
@@ -26,6 +26,12 @@
 
 public interface RemoteFileSystem {
 
+	public static final String FTP_PROTOCOL = "ftp";
+
+	public static final String SFTP_PROTOCOL = "sftp";
+
+	public static final String FTPS_PROTOCOL = "ftps";
+
 	public static final String PARMS_FTP_SERVER = "ftpServer";
 
 	public static final String PARMS_USER = "ftpUser";
@@ -48,73 +54,98 @@
 	 * Terminates ftp session and frees resources
 	 * <li>Well behaved programs should make sure to call this method </li>
 	 */
-	public void quit(); //_________________________________
+	public void quit(); // _________________________________
 
 	/**
 	 * Deletes specified file in remote directory
-	 * @param p_sFile String : filename to delete.  Method will attempt to delete
-	 * file with rightmost node of argument within remote directory specified in 'remoteDirURI'
-	 * @throws Exception : if ftp connection cannot be established, or file
-	 * cannot be deleted in remote directory
+	 * 
+	 * @param p_sFile
+	 *            String : filename to delete. Method will attempt to delete
+	 *            file with rightmost node of argument within remote directory
+	 *            specified in 'remoteDirURI'
+	 * @throws Exception :
+	 *             if ftp connection cannot be established, or file cannot be
+	 *             deleted in remote directory
 	 */
-	public void deleteRemoteFile(String p_sFile) throws Exception; //_________________________________
+	public void deleteRemoteFile(String p_sFile) throws Exception; // _________________________________
 
-	public void remoteDelete(File p_oFile) throws Exception; //_________________________________
+	public void remoteDelete(File p_oFile) throws Exception; // _________________________________
 
 	/**
 	 * Gets the list of files in the remote directory that end with arg0
-	 * @param p_sSuffix String : retrieve only files that end with that suffix - all files if null
-	 * @throws Exception : if ftp connection cannot be established, or problems encountered
+	 * 
+	 * @param p_sSuffix
+	 *            String : retrieve only files that end with that suffix - all
+	 *            files if null
+	 * @throws Exception :
+	 *             if ftp connection cannot be established, or problems
+	 *             encountered
 	 */
-	public String[] getFileListFromRemoteDir(String p_sSuffix) throws Exception; //_________________________________
+	public String[] getFileListFromRemoteDir(String p_sSuffix) throws Exception; // _________________________________
 
 	/**
 	 * Change remote directory
-	 * @param p_sDir String : directory to set
-	 * @throws Exception : if ftp connection cannot be established, or problems encountered
+	 * 
+	 * @param p_sDir
+	 *            String : directory to set
+	 * @throws Exception :
+	 *             if ftp connection cannot be established, or problems
+	 *             encountered
 	 */
-	public void setRemoteDir(String p_sDir) throws Exception; //_________________________________
+	public void setRemoteDir(String p_sDir) throws Exception; // _________________________________
 
 	/**
 	 * Renames specified file in remote directory to specified new name
-	 * @param p_sFrom String : filename to rename
-	 * @param p_sTo String : new filename
-	 * @throws Exception : if ftp connection cannot be established, or file
-	 * cannot be renamed to new name in remote directory
-	 * <li>Method will attempt to rename file with rightmost node of argument
-	 * within remote directory specified in 'remoteDirURI', to new name inside
-	 * the SAME remote directory
+	 * 
+	 * @param p_sFrom
+	 *            String : filename to rename
+	 * @param p_sTo
+	 *            String : new filename
+	 * @throws Exception :
+	 *             if ftp connection cannot be established, or file cannot be
+	 *             renamed to new name in remote directory
+	 *             <li>Method will attempt to rename file with rightmost node
+	 *             of argument within remote directory specified in
+	 *             'remoteDirURI', to new name inside the SAME remote directory
 	 */
 	public void renameInRemoteDir(String p_sFrom, String p_sTo)
-			throws Exception; //_________________________________
+			throws Exception; // _________________________________
 
-	public void remoteRename(File p_oFrom, File p_oTo) throws Exception; //_________________________________
+	public void remoteRename(File p_oFrom, File p_oTo) throws Exception; // _________________________________
 
 	/**
 	 * Uploads specified file from local directory (localDirURI) to remote
 	 * directory (remoteDirURI)
-	 * @param p_sFile String : filename to upload
-	 * @throws Exception : if ftp connection cannot be established, or file
-	 * cannot be uploaded
-	 * <li> local file will be renamed during transfer ('.xferNotReady' appended
-	 * to name)</li>
-	 * <li> upon successful completion. the suffix '.xferDone' will be appended
-	 * to the original filename </li>
+	 * 
+	 * @param p_sFile
+	 *            String : filename to upload
+	 * @throws Exception :
+	 *             if ftp connection cannot be established, or file cannot be
+	 *             uploaded
+	 *             <li> local file will be renamed during transfer
+	 *             ('.xferNotReady' appended to name)</li>
+	 *             <li> upon successful completion. the suffix '.xferDone' will
+	 *             be appended to the original filename </li>
 	 */
-	public void uploadFile(File p_oFile, String p_sRemoteName) throws Exception; //_________________________________
+	public void uploadFile(File p_oFile, String p_sRemoteName) throws Exception; // _________________________________
 
 	/**
 	 * Downloads specified file from remote directory (remoteDirURI) to local
 	 * directory (localDirURI)
-	 * @param p_sFile String : filename to download
-	 * @throws Exception : if ftp connection cannot be established, or file
-	 * cannot be downloaded
-	 * <li> local file is assigned a temporary name during transfer  </li>
-	 * <li> upon successful completion, local temporary file will be renamed to
-	 * name specified in argument, and suffix '.xferDone' will be appended
-	 * to the original filename in the remote directory </li>
+	 * 
+	 * @param p_sFile
+	 *            String : filename to download
+	 * @throws Exception :
+	 *             if ftp connection cannot be established, or file cannot be
+	 *             downloaded
+	 *             <li> local file is assigned a temporary name during transfer
+	 *             </li>
+	 *             <li> upon successful completion, local temporary file will be
+	 *             renamed to name specified in argument, and suffix '.xferDone'
+	 *             will be appended to the original filename in the remote
+	 *             directory </li>
 	 */
 	public void downloadFile(String p_sFile, String p_sFinalName)
-			throws Exception; //_________________________________
+			throws Exception; // _________________________________
 
 }
\ No newline at end of file

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java	2006-12-12 21:56:14 UTC (rev 8272)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/util/RemoteFileSystemFactory.java	2006-12-12 23:24:36 UTC (rev 8273)
@@ -24,44 +24,57 @@
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URISyntaxException;
+import java.net.URL;
 import java.net.UnknownHostException;
 
 import org.jboss.internal.soa.esb.util.EdtFtpImpl;
+import org.jboss.internal.soa.esb.util.SecureFtpImpl;
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.xml.sax.SAXException;
 
-public class RemoteFileSystemFactory 
-{
-	
-	//
-	private static final RemoteFileSystemFactory _instance = new RemoteFileSystemFactory();
-	
+public class RemoteFileSystemFactory {
+
 	// private default constructor
-	private RemoteFileSystemFactory() {}
+	private RemoteFileSystemFactory() {
+	}
 
-	public static RemoteFileSystemFactory getInstance()
-	{
-		return _instance;
+	public static RemoteFileSystem getRemoteFileSystem(FTPEpr p_oEpr, boolean p_bConnect)
+			throws RemoteFileSystemException {
+		URL url = null;
+		try {
+			url = p_oEpr.getURL();
+			if (url.getProtocol().equals(RemoteFileSystem.FTP_PROTOCOL))
+				return new EdtFtpImpl(p_oEpr, p_bConnect);
+			else if (url.getProtocol().equals(RemoteFileSystem.FTP_PROTOCOL))
+				return new SecureFtpImpl(p_oEpr, p_bConnect);
+
+		} catch (MalformedURLException e) {
+			throw new RemoteFileSystemException(e);
+		} catch (URISyntaxException e) {
+			throw new RemoteFileSystemException(e);
+		} catch (Exception e) {
+			throw new RemoteFileSystemException(e);
+		}
+		throw new RemoteFileSystemException("Unknown or unsupported protocol");
+
 	}
-	
-	public static RemoteFileSystem getRemoteFileSystem(ConfigTree p_oP, boolean p_bConnect) throws RemoteFileSystemException
-	{
-		try
-		{
+
+	// TODO this will be replaced by the new method which takes an EPR rather than a config tree
+	public static RemoteFileSystem getRemoteFileSystem(ConfigTree p_oP,
+			boolean p_bConnect) throws RemoteFileSystemException {
+		try {
 			// TODO get the implementation class from properties.
 			// See SecureFtpImplUnitTest and EdtFtpImplUnitTest for Tests.
-                        // return new SecureFtpImpl(p_oP,p_bConnect);
-			return new EdtFtpImpl(p_oP,p_bConnect);
-		}
-		catch (UnknownHostException ex)
-		{
+			// return new SecureFtpImpl(p_oP,p_bConnect);
+			return new EdtFtpImpl(p_oP, p_bConnect);
+		} catch (UnknownHostException ex) {
 			throw new RemoteFileSystemException(ex);
-		}
-		catch (URISyntaxException e) { 
-			throw new RemoteFileSystemException(e); 
-		} 
-		catch (FileNotFoundException e) {
+		} catch (URISyntaxException e) {
+			throw new RemoteFileSystemException(e);
+		} catch (FileNotFoundException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		} catch (SAXException e) {
@@ -77,5 +90,5 @@
 		}
 		throw new RemoteFileSystemException("Unknown protocol");
 	}
-	
+
 }




More information about the jboss-svn-commits mailing list