3.2.1: 2012-12-13

net.sf.basedb.util.uri
Class ConnectionManagerUtil

java.lang.Object
  extended by net.sf.basedb.util.uri.ConnectionManagerUtil

public class ConnectionManagerUtil
extends Object

Collects utility methods related to connection managers. Connection manager factories should be registered as extensions to the net.sf.basedb.core.uri.connection-manager extension point. The methods in this class can then be used to get information about installed connection manager factories and to use them for retreiving external file data and information.

Since:
3.0
Author:
Nicklas
Last modified
$Date: 2011-04-28 12:59:18 +0200 (Thu, 28 Apr 2011) $

Field Summary
static String EXTENSION_POINT_ID
          The ID of the connection manager extension point.
 
Constructor Summary
ConnectionManagerUtil()
           
 
Method Summary
private static ConnectionManagerFactory autoDetect(ExtensionsInvoker<ConnectionManagerFactory> invoker, URI uri)
          Use auto-detection and return the first factory that can handle the given uri.
static ConnectionManager createConnectionManager(File file, ConnectionParameters parameters)
          Utility method for creating a connection manager for a file item.
static ConnectionManager createConnectionManager(URI uri, ConnectionParameters parameters)
          Utility method for creating a connection manager.
static ConnectionManagerFactory findFactory(URI uri)
          Find a factory for the given URI.
static List<ConnectionManagerFactory> getFactories()
          Get a list with all connection manager factories.
static ConnectionManagerFactory getFactory(String id)
          Get the connection manager factory with the given extension id.
private static ConnectionManagerFactory getFirst(ExtensionsInvoker<ConnectionManagerFactory> invoker)
          Get the first factory returned by the invoker.
private static ExtensionsInvoker<ConnectionManagerFactory> getInvoker(ClientContext context, ExtensionsFilter filter)
          Get an invoker for using the connection manager factory extensions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXTENSION_POINT_ID

public static final String EXTENSION_POINT_ID
The ID of the connection manager extension point.

See Also:
Constant Field Values
Constructor Detail

ConnectionManagerUtil

public ConnectionManagerUtil()
Method Detail

getFactories

public static List<ConnectionManagerFactory> getFactories()
Get a list with all connection manager factories. No context information will be available to the action factories that creates the connection manager factories.

Returns:
A list with the factories

getFactory

public static ConnectionManagerFactory getFactory(String id)
Get the connection manager factory with the given extension id. No context information will be available to the factory when it is created.

Parameters:
id - The ID of the factory
Returns:
A factory instance or null if not found

findFactory

public static ConnectionManagerFactory findFactory(URI uri)
Find a factory for the given URI. This method will iterate the registered factories in their priority/index order and call ConnectionManagerFactory.supports(URI) for all factories that supports auto-detection. The first one that gives a successful response is returned. If no factory supports the given URI, null is returned.

Note to extension developers: The given uri is available to the action factory as "uri" attribute of the context.

Parameters:
uri - The URI (null is not allowed)
Returns:
An UriHandlerFactory or null if no factory was found

createConnectionManager

public static ConnectionManager createConnectionManager(URI uri,
                                                        ConnectionParameters parameters)
Utility method for creating a connection manager. If a specific factory is specified in the connection parameters, that factory is used, otherwise findFactory(URI) is used for auto-detection. If no factory is found an exception is thrown, otherwise a connection manger is created by the factory method: ConnectionManagerFactory.createConnectionManager(URI, ConnectionParameters)

Parameters:
uri - The URI (required)
parameters - Connection parameters, such as user login/password, etc. (optional)
Returns:
A connection manager

createConnectionManager

public static ConnectionManager createConnectionManager(File file,
                                                        ConnectionParameters parameters)
Utility method for creating a connection manager for a file item. If a specific factory is specified in the connection parameters, that factory is used, otherwise auto-detection is used. The auto-detection is similar to the findFactory(URI) method but this time the context information for the action factory contains the file object and connection parameters.

Parameters:
file - The (external) file (required)
parameters - Connection parameters, such as user login/password, etc. (optional)
Returns:
A connection manager

getInvoker

private static ExtensionsInvoker<ConnectionManagerFactory> getInvoker(ClientContext context,
                                                                      ExtensionsFilter filter)
Get an invoker for using the connection manager factory extensions.


getFirst

private static ConnectionManagerFactory getFirst(ExtensionsInvoker<ConnectionManagerFactory> invoker)
Get the first factory returned by the invoker.


autoDetect

private static ConnectionManagerFactory autoDetect(ExtensionsInvoker<ConnectionManagerFactory> invoker,
                                                   URI uri)
Use auto-detection and return the first factory that can handle the given uri.


3.2.1: 2012-12-13