org.apache.commons.vfs.util
Class DelegatingFileSystemOptionsBuilder

java.lang.Object
  extended by org.apache.commons.vfs.util.DelegatingFileSystemOptionsBuilder

public class DelegatingFileSystemOptionsBuilder
extends java.lang.Object

This class use reflection to set a configuration value using the fileSystemConfigBuilder associated the a scheme.

Example:

 FileSystemOptions fso = new FileSystemOptions();
 DelegatingFileSystemOptionsBuilder delegate = new DelegatingFileSystemOptionsBuilder(VFS.getManager());
 delegate.setConfigString(fso, "sftp", "identities", "c:/tmp/test.ident");
 delegate.setConfigString(fso, "http", "proxyPort", "8080");
 delegate.setConfigClass(fso, "sftp", "userinfo", TrustEveryoneUserInfo.class);
 

Version:
$Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
Author:
Mario Ivankovits

Nested Class Summary
private static class DelegatingFileSystemOptionsBuilder.Context
           
 
Field Summary
private  java.util.Map beanMethods
           
private  org.apache.commons.logging.Log log
           
private  FileSystemManager manager
           
private static java.util.Map primitiveToObject
           
private static java.lang.Class[] STRING_PARAM
           
 
Constructor Summary
DelegatingFileSystemOptionsBuilder(FileSystemManager manager)
          Constructor.
Pass in your fileSystemManager instance.
 
Method Summary
private  boolean convertValuesAndInvoke(java.lang.reflect.Method configSetter, DelegatingFileSystemOptionsBuilder.Context ctx)
          tries to convert the value and pass it to the given method
private  java.util.Map createSchemeMethods(java.lang.String scheme)
          create the list of all set*() methods for the given scheme
private  boolean fillConfigSetters(DelegatingFileSystemOptionsBuilder.Context ctx)
          fills all available set*() methods for the context-scheme into the context.
protected  FileSystemManager getManager()
           
private  java.util.Map getSchemeMethods(java.lang.String scheme)
          get (cached) list of set*() methods for the given scheme
private  void invokeSetter(java.lang.Class valueParameter, DelegatingFileSystemOptionsBuilder.Context ctx, java.lang.reflect.Method configSetter, java.lang.Object values)
          invokes the method with the converted values
 void setConfigClass(FileSystemOptions fso, java.lang.String scheme, java.lang.String name, java.lang.Class className)
          Set a single class value.
The class has to implement a no-args constructor, else the instantiation might fail.
 void setConfigClasses(FileSystemOptions fso, java.lang.String scheme, java.lang.String name, java.lang.Class[] classNames)
          Set an array of class values.
The class has to implement a no-args constructor, else the instantiation might fail.
 void setConfigString(FileSystemOptions fso, java.lang.String scheme, java.lang.String name, java.lang.String value)
          Set a single string value.
 void setConfigStrings(FileSystemOptions fso, java.lang.String scheme, java.lang.String name, java.lang.String[] values)
          Set an array of string value.
private  void setValues(DelegatingFileSystemOptionsBuilder.Context ctx)
          sets the values using the informations of the given context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log

STRING_PARAM

private static final java.lang.Class[] STRING_PARAM

manager

private final FileSystemManager manager

beanMethods

private final java.util.Map beanMethods

primitiveToObject

private static final java.util.Map primitiveToObject
Constructor Detail

DelegatingFileSystemOptionsBuilder

public DelegatingFileSystemOptionsBuilder(FileSystemManager manager)
Constructor.
Pass in your fileSystemManager instance.

Parameters:
manager - the manager to use to get the fileSystemConfigBuilder assocated to a scheme
Method Detail

getManager

protected FileSystemManager getManager()

setConfigString

public void setConfigString(FileSystemOptions fso,
                            java.lang.String scheme,
                            java.lang.String name,
                            java.lang.String value)
                     throws FileSystemException
Set a single string value.

Parameters:
fso - FileSystemOptions
scheme - scheme
name - name
value - value
Throws:
FileSystemException

setConfigStrings

public void setConfigStrings(FileSystemOptions fso,
                             java.lang.String scheme,
                             java.lang.String name,
                             java.lang.String[] values)
                      throws FileSystemException
Set an array of string value.

Parameters:
fso - FileSystemOptions
scheme - scheme
name - name
values - values
Throws:
FileSystemException

setConfigClass

public void setConfigClass(FileSystemOptions fso,
                           java.lang.String scheme,
                           java.lang.String name,
                           java.lang.Class className)
                    throws FileSystemException,
                           java.lang.IllegalAccessException,
                           java.lang.InstantiationException
Set a single class value.
The class has to implement a no-args constructor, else the instantiation might fail.

Parameters:
fso - FileSystemOptions
scheme - scheme
name - name
className - className
Throws:
FileSystemException
java.lang.IllegalAccessException
java.lang.InstantiationException

setConfigClasses

public void setConfigClasses(FileSystemOptions fso,
                             java.lang.String scheme,
                             java.lang.String name,
                             java.lang.Class[] classNames)
                      throws FileSystemException,
                             java.lang.IllegalAccessException,
                             java.lang.InstantiationException
Set an array of class values.
The class has to implement a no-args constructor, else the instantiation might fail.

Parameters:
fso - FileSystemOptions
scheme - scheme
name - name
classNames - classNames
Throws:
FileSystemException
java.lang.IllegalAccessException
java.lang.InstantiationException

setValues

private void setValues(DelegatingFileSystemOptionsBuilder.Context ctx)
                throws FileSystemException
sets the values using the informations of the given context.

Throws:
FileSystemException

convertValuesAndInvoke

private boolean convertValuesAndInvoke(java.lang.reflect.Method configSetter,
                                       DelegatingFileSystemOptionsBuilder.Context ctx)
                                throws FileSystemException
tries to convert the value and pass it to the given method

Throws:
FileSystemException

invokeSetter

private void invokeSetter(java.lang.Class valueParameter,
                          DelegatingFileSystemOptionsBuilder.Context ctx,
                          java.lang.reflect.Method configSetter,
                          java.lang.Object values)
                   throws FileSystemException
invokes the method with the converted values

Throws:
FileSystemException

fillConfigSetters

private boolean fillConfigSetters(DelegatingFileSystemOptionsBuilder.Context ctx)
                           throws FileSystemException
fills all available set*() methods for the context-scheme into the context.

Throws:
FileSystemException

getSchemeMethods

private java.util.Map getSchemeMethods(java.lang.String scheme)
                                throws FileSystemException
get (cached) list of set*() methods for the given scheme

Throws:
FileSystemException

createSchemeMethods

private java.util.Map createSchemeMethods(java.lang.String scheme)
                                   throws FileSystemException
create the list of all set*() methods for the given scheme

Throws:
FileSystemException