commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam Jack" <aj...@trysybase.com>
Subject [VFS] Dynamic FSM Configuration
Date Sat, 02 Aug 2003 13:20:07 GMT
Hi,

With the (very recent) FTP failures on Gump I notice that my FSM
configuration is more static than I'd like. VFS is now (nicely) much more
dynamic w.r.t providers (with optional compilations) however my
configuration seems pretty tied to the existence of some.

I don't know if what I currently have (attached below) is historical or not,
but I have some issues. I can't go directly to the file configuration
approach because I don't know what working directory I will be run in. Also,
how would I keep my file (there only to be dynamic) in synch with the VFS
one. [I really don't want to limit my users to certain providers, I just
want to be dynamic.]

Here are a few question:

1) Could I load a file from a resource (in my jar, say) and somehow pass
that in to VFS FSM, then do my "final tweaks" w/ Replicator/Base? Is this
the best option?

2) Is there a way I can pass in a provider "ID" and have VFS do the
environment check (against it's own compiled base) and register, or not.

3) Is there a better approach than I have listed here? We just want to be
good VFS users w/ some requirements (tmp/replicator/etc.)

All input appreciated. Thanks in advance/

regards

Adam
--
<http://www.try.sybase.com>
Experience Sybase Technology ...



import org.apache.commons.vfs.AllFileSelector;
import org.apache.commons.vfs.Capability;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSelector;
import org.apache.commons.vfs.FileSystem;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.FileType;
import org.apache.commons.vfs.impl.DefaultFileReplicator;
import org.apache.commons.vfs.impl.DefaultFileSystemManager;
import org.apache.commons.vfs.provider.FileProvider;
import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider;
import org.apache.commons.vfs.provider.temp.TemporaryFileProvider;
import org.apache.commons.vfs.provider.url.UrlFileProvider;
import org.apache.commons.vfs.provider.zip.ZipFileProvider;




public static FileSystemManager createFSM(String name, String base)
	throws FileSystemException {

	DefaultFileSystemManager fsm = new DefaultFileSystemManager();
	fsm.setLogger(LogFactory.getLog(name));

	FileProvider fileProvider = new DefaultLocalFileProvider();
	fsm.addProvider("file", fileProvider);

	FileProvider tmpProvider = new TemporaryFileProvider();
	fsm.addProvider("tmp", tmpProvider);

	ZipFileProvider zipProvider = new ZipFileProvider();
	fsm.addProvider(new String[] { "jar", "zip" }, zipProvider);
	fsm.addExtensionMap("zip", "zip");
	fsm.addExtensionMap("jar", "jar");
	fsm.addExtensionMap("application/zip", "zip");

	fsm.setReplicator(new DefaultFileReplicator());

	//
		// Load FTP only if in the environment, and loadable
		//
		try {
			if (null
				== RelativelySafe.thrownIfLoaded(
					"org.apache.commons.net.ftp.FTPFile")) {
				fsm.addProvider(
					"ftp",
					new org.apache.commons.vfs.provider.ftp.FtpFileProvider());
			}
		}
		catch (Exception e) {
		}

	FileProvider httpProvider = new UrlFileProvider();
	fsm.addProvider("http", httpProvider);
	fsm.setDefaultProvider(httpProvider);

	// Set Base Directory for Resolveing Relative To...
	fsm.setBaseFile(new java.io.File(base));

	fsm.init();

	return fsm;
}


Mime
View raw message