TrueZIP 6.8.3

de.schlichtherle.io
Class ArchiveDriverRegistry

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap
          extended by de.schlichtherle.io.ArchiveDriverRegistry
All Implemented Interfaces:
Serializable, Cloneable, Map
Direct Known Subclasses:
GlobalArchiveDriverRegistry

 class ArchiveDriverRegistry
extends HashMap

The head of a chain of registries for archive file suffixes and archive drivers. Each element in the chain is an instance of this class which maps single archive file suffixes (not lists) [String] to the fully qualified class name, class object or instance of an archive driver [String, Class or ArchiveDriver]. The getArchiveDriver(java.lang.String) method can then be used to recursively lookup an archive driver for a given (file name) suffix in the registry chain.

This class is serializable in order to meet the requirements of the File class. However, it's not really recommended to serialize this class: Together with the instance, all associated archive drivers are serialized too, which is pretty inefficient for a single instance.

Since:
TrueZIP 6.5
Author:
Christian Schlichtherle

Nested Class Summary
(package private) static class ArchiveDriverRegistry.IllegalArchiveDriverException
           
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
private static String CLASS_NAME
           
private  ArchiveDriverRegistry delegate
          The delegate used to lookup archive drivers when no driver is configured locally.
(package private) static String KWD_DEFAULT
           
(package private) static String KWD_DRIVER
           
private static Logger logger
           
private static ResourceBundle resources
           
private static long serialVersionUID
           
 
Constructor Summary
ArchiveDriverRegistry()
          Creates an empty ArchiveDriverRegistry.
ArchiveDriverRegistry(ArchiveDriverRegistry delegate, Map config)
          Creates a new DefaultArchiveDriverRegistry by decorating the configuration of delegate with mappings for all entries in config.
 
Method Summary
private static ArchiveDriver createArchiveDriver(Object driver)
          Creates an archive driver from the given blueprint.
 SuffixSet decorate(SuffixSet set)
          Decorates the given suffix set by adding all suffixes which map to a valid archive driver and removing all suffixes which map to null in the local registry.
 ArchiveDriver getArchiveDriver(String suffix)
          Returns the archive driver for the given canonical suffix or null if no archive driver is found in the registry.
private static String getString(String key)
           
private static String getString(String key, String arg)
           
private  void registerArchiveDriver(String list, Object driver, boolean eager)
          Registers the given archive id for the given list of suffixes.
(package private)  void registerArchiveDrivers(Map config, boolean eager)
          Processes the given config and adds the configured archive driver mappings.
 SuffixSet suffixes()
          Returns the set of all suffixes which map to a valid archive driver in the registry.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

CLASS_NAME

private static final String CLASS_NAME
See Also:
Constant Field Values

resources

private static final ResourceBundle resources

logger

private static final Logger logger

KWD_DRIVER

static final String KWD_DRIVER
See Also:
Constant Field Values

KWD_DEFAULT

static final String KWD_DEFAULT
See Also:
Constant Field Values

delegate

private final ArchiveDriverRegistry delegate
The delegate used to lookup archive drivers when no driver is configured locally. May be null.

Constructor Detail

ArchiveDriverRegistry

ArchiveDriverRegistry()
Creates an empty ArchiveDriverRegistry.


ArchiveDriverRegistry

ArchiveDriverRegistry(ArchiveDriverRegistry delegate,
                      Map config)
Creates a new DefaultArchiveDriverRegistry by decorating the configuration of delegate with mappings for all entries in config.

Parameters:
delegate - The ArchiveDriverRegistry which's configuration is to be virtually inherited.
config - A map of suffix lists and archive drivers. Each key in this map must be a non-null, non-empty archive file suffix list, obeying the usual syntax. Each value must either be an archive driver instance, an archive driver class, a string with the fully qualified name name of an archive driver class, or null. A null archive driver may be used to shadow a mapping for the same archive driver in delegate, effectively removing it.
Throws:
NullPointerException - If any parameter or configuration element other than an archive driver is null.
IllegalArgumentException - If any other parameter precondition does not hold or an illegal keyword is found in the configuration.
See Also:
Syntax Definition for Suffix Lists
Method Detail

registerArchiveDrivers

final void registerArchiveDrivers(Map config,
                                  boolean eager)
Processes the given config and adds the configured archive driver mappings.

Parameters:
config - A map of suffix lists and archive driver IDs. Each key in this map must be a non-null, non-empty suffix list, obeying the usual syntax. Each value must either be an archive driver instance, an archive driver class, or a string with the fully qualified name name of an archive driver class.
eager - Iff true, archive drivers are immediately instantiated and the keyword DEFAULT is not allowed.
Throws:
NullPointerException - If any parameter or config element is null.
IllegalArgumentException - If any other parameter precondition does not hold or the keyword DRIVER is found.

registerArchiveDriver

private void registerArchiveDriver(String list,
                                   Object driver,
                                   boolean eager)
Registers the given archive id for the given list of suffixes.

Parameters:
eager - Whether the archive driver shall be instantiated or not.
Throws:
NullPointerException - If id is null.
ClassCastException - If eager is false and driver isn't a string.
ArchiveDriverRegistry.IllegalArchiveDriverException - If eager is true and driver can't get instantiated for some reason. The cause is wrapped in the exception.

getArchiveDriver

public final ArchiveDriver getArchiveDriver(String suffix)
Returns the archive driver for the given canonical suffix or null if no archive driver is found in the registry.

This instance is the head element of the registry chain. If this head element does not hold an archive driver for the given suffix, then the next element in the registry chain is searched. This repeats recursively until either an archive driver is found or the end of the chain is reached.

An archive driver is looked up in the registry as follows:

  1. If the registry holds a string, it's supposed to be the fully qualified class name of an ArchiveDriver implementation. The class will be loaded and stored in the registry.
  2. If the registry then holds a class instance, it's instantiated with its no-arguments constructor, cast to the ArchiveDriver type and stored in the registry.
  3. If the registry then holds an instance of an ArchiveDriver implementation, it's returned.
  4. Otherwise, null is returned.
This method is thread safe.

Throws:
RuntimeException - A subclass is thrown if loading or instantiating an archive driver class fails.

createArchiveDriver

private static final ArchiveDriver createArchiveDriver(Object driver)
Creates an archive driver from the given blueprint.

Parameters:
driver - A string with the fully qualified class name of an archive driver implementation, a class instance for an archive driver implementation, an archive driver instance or null.
Returns:
An archive driver instance or null iff driver is null.
Throws:
ArchiveDriverRegistry.IllegalArchiveDriverException - If an archive driver cannot get returned. The cause is wrapped in the exception.

suffixes

public final SuffixSet suffixes()
Returns the set of all suffixes which map to a valid archive driver in the registry. This includes the registry built by the entire chain, not just the local registry.


decorate

public final SuffixSet decorate(SuffixSet set)
Decorates the given suffix set by adding all suffixes which map to a valid archive driver and removing all suffixes which map to null in the local registry.

Parameters:
set - A non-null set of canonical archive file suffixes.
Returns:
set, decorated according to the mappings in the local registry.

getString

private static final String getString(String key)

getString

private static final String getString(String key,
                                      String arg)

TrueZIP 6.8.3

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.