Package org.apache.commons.vfs2.util
Class DelegatingFileSystemOptionsBuilder
- java.lang.Object
-
- org.apache.commons.vfs2.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);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DelegatingFileSystemOptionsBuilder.Context
Context.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>>>
beanMethods
private static org.apache.commons.logging.Log
log
private FileSystemManager
manager
private static java.util.Map<java.lang.String,java.lang.Class<?>>
PRIMATIVE_TO_OBJECT
private static java.lang.Class<java.lang.String>[]
STRING_PARAM
-
Constructor Summary
Constructors Constructor Description DelegatingFileSystemOptionsBuilder(FileSystemManager manager)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
convertValuesAndInvoke(java.lang.reflect.Method configSetter, DelegatingFileSystemOptionsBuilder.Context ctx)
Tries to convert the value and pass it to the given methodprivate java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>>
createSchemeMethods(java.lang.String scheme)
Creates the list of all set*() methods for the given schemeprivate boolean
fillConfigSetters(DelegatingFileSystemOptionsBuilder.Context ctx)
Fills all available set*() methods for the context-scheme into the context.protected FileSystemManager
getManager()
private java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>>
getSchemeMethods(java.lang.String scheme)
Gets (cached) list of set*() methods for the given schemeprivate void
invokeSetter(java.lang.Class<?> valueParameter, DelegatingFileSystemOptionsBuilder.Context ctx, java.lang.reflect.Method configSetter, java.lang.Object values)
Invokes the method with the converted valuesvoid
setConfigClass(FileSystemOptions fso, java.lang.String scheme, java.lang.String name, java.lang.Class<?> className)
Sets a single class value.void
setConfigClasses(FileSystemOptions fso, java.lang.String scheme, java.lang.String name, java.lang.Class<?>[] classNames)
Sets an array of class values.void
setConfigString(FileSystemOptions fso, java.lang.String scheme, java.lang.String name, java.lang.String value)
Sets a single string value.void
setConfigStrings(FileSystemOptions fso, java.lang.String scheme, java.lang.String name, java.lang.String[] values)
Sets an array of string value.private void
setValues(DelegatingFileSystemOptionsBuilder.Context ctx)
Sets the values using the informations of the given context.
-
-
-
Field Detail
-
STRING_PARAM
private static final java.lang.Class<java.lang.String>[] STRING_PARAM
-
PRIMATIVE_TO_OBJECT
private static final java.util.Map<java.lang.String,java.lang.Class<?>> PRIMATIVE_TO_OBJECT
-
log
private static final org.apache.commons.logging.Log log
-
manager
private final FileSystemManager manager
-
beanMethods
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>>> beanMethods
-
-
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
Sets a single string value.- Parameters:
fso
- FileSystemOptionsscheme
- schemename
- namevalue
- value- Throws:
FileSystemException
- if an error occurs.
-
setConfigStrings
public void setConfigStrings(FileSystemOptions fso, java.lang.String scheme, java.lang.String name, java.lang.String[] values) throws FileSystemException
Sets an array of string value.- Parameters:
fso
- FileSystemOptionsscheme
- schemename
- namevalues
- values- Throws:
FileSystemException
- if an error occurs.
-
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
Sets a single class value.The class has to implement a no-args constructor, else the instantiation might fail.
- Parameters:
fso
- FileSystemOptionsscheme
- schemename
- nameclassName
- className- Throws:
FileSystemException
- if an error occurs.java.lang.IllegalAccessException
- if a class canoot be accessed.java.lang.InstantiationException
- if a class cannot be instantiated.
-
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
Sets an array of class values.The class has to implement a no-args constructor, else the instantiation might fail.
- Parameters:
fso
- FileSystemOptionsscheme
- schemename
- nameclassNames
- classNames- Throws:
FileSystemException
- if an error occurs.java.lang.IllegalAccessException
- if a class canoot be accessed.java.lang.InstantiationException
- if a class cannot be instantiated.
-
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<java.lang.String,java.util.List<java.lang.reflect.Method>> getSchemeMethods(java.lang.String scheme) throws FileSystemException
Gets (cached) list of set*() methods for the given scheme- Throws:
FileSystemException
-
createSchemeMethods
private java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> createSchemeMethods(java.lang.String scheme) throws FileSystemException
Creates the list of all set*() methods for the given scheme- Throws:
FileSystemException
-
-