/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software License
 * version 1.1, a copy of which has been included  with this distribution in
 * the LICENSE.txt file.
 */
package org.apache.commons.vfs;

import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.commons.vfs.impl.DefaultFileReplicator;
import org.apache.commons.vfs.impl.DefaultFileSystemManager;
import org.apache.commons.vfs.impl.PrivilegedFileReplicator;
import org.apache.commons.vfs.provider.FileProvider;
import org.apache.commons.vfs.provider.FileReplicator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * A static factory for {@link FileSystemManager} instances.
 *
 * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
 * @version $Revision: 1.4 $ $Date: 2002/08/21 14:28:07 $
 */
public class FileSystemManagerFactory
{
    private static final Resources REZ =
        ResourceManager.getPackageResources( FileSystemManagerFactory.class );
    private static FileSystemManager instance;

    private FileSystemManagerFactory()
    {
    }

    /**
     * Returns the default {@link FileSystemManager} instance.
     */
    public synchronized static FileSystemManager getManager()
        throws FileSystemException
    {
        if ( instance == null )
        {
            instance = doCreateManager();
        }
        return instance;
    }

    /**
     * Creates a file system manager instance.
     *
     * @todo Load manager config from a file.
     * @todo Ignore missing providers.
     */
    private static FileSystemManager doCreateManager()
        throws FileSystemException
    {
        final DefaultFileSystemManager mgr = new DefaultFileSystemManager();

        // Set the logger
        final Log logger = LogFactory.getLog( FileSystemManagerFactory.class );
        mgr.setLogger( logger );

        // Set the replicator
        FileReplicator replicator = new DefaultFileReplicator();
        replicator = new PrivilegedFileReplicator( replicator );
        mgr.setReplicator( replicator );

        // Add the default providers
        FileProvider provider = createProvider( "org.apache.commons.vfs.provider.local.DefaultLocalFileSystemProvider" );
        mgr.addProvider( "file", provider );
        provider = createProvider( "org.apache.commons.vfs.provider.zip.ZipFileSystemProvider" );
        mgr.addProvider( "zip", provider );
        mgr.addProvider( "jar", provider );
        provider = createProvider( "org.apache.commons.vfs.provider.ftp.FtpFileSystemProvider" );
        mgr.addProvider( "ftp", provider );
        provider = createProvider( "org.apache.commons.vfs.provider.smb.SmbFileSystemProvider" );
        mgr.addProvider( "smb", provider );
        provider = createProvider( "org.apache.commons.vfs.provider.url.UrlFileProvider" );
        mgr.setDefaultProvider( provider );

        return mgr;
    }

    /**
     * Creates a provider.
     */
    private static FileProvider createProvider( final String providerClassName )
        throws FileSystemException
    {
        try
        {
            final Class providerClass = Class.forName( providerClassName );
            return (FileProvider)providerClass.newInstance();
        }
        catch ( final Exception e )
        {
            final String message = REZ.getString( "create-provider.error", providerClassName );
            throw new FileSystemException( message, e );
        }
    }
}

@@ -928,17 +928,17 @@
 sion: 1.
-4
+5
  $ $Date
@@ -952,18 +952,18 @@
 08/2
-1 14:28:07
+2 02:13:30
  $%0A 
@@ -2542,32 +2542,130 @@
 p%22, provider );%0A
+        provider = createProvider( %22org.apache.commons.vfs.provider.jar.JarFileSystemProvider%22 );%0A
         mgr.addP

Use the new Jar provider instead of the Zip provider for jar: URLs.