TrueZIP 6.8.3

de.schlichtherle.io
Class GlobalArchiveDriverRegistry

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

final class GlobalArchiveDriverRegistry
extends ArchiveDriverRegistry

A global registry for archive file suffixes and archive drivers which is configured by the set of all configuration files on the class path. This registry does not have a delegate, so it can only be used as the tail in a registry chain.

When this class is instantiated, it enumerate all instances of the relative path META-INF/services/de.schlichtherle.io.registry.properties on the class path (this ensures that TrueZIP is compatible with JNLP as used by Java Web Start and can be safely added to the Extension Class Path).

The configuration files are processed in arbitrary order. However, configuration files which contain the entry DRIVER=true have lesser priority and will be overruled by any other configuration files which do not contain this entry. This is used by the default configuration file in TrueZIP's JAR: It contains this entry in order to allow any client application provided configuration file to overrule it.

This class may appear to be a singleton (there's not much point in having multiple instances of this class, all with the same configuration). However, it actually isn't a true singleton because it's Serializable in order to support serialization of File instances. This implies that a JVM can send an instance of this class to another JVM, which's own global archive driver registry instance may be configured completely different by its local configuration files. This requires that the ArchiveDrivers used by the global archive driver registry are serializable, too.

Note that it's actually discouraged to serialize File instances. It's only supported due to the implementation of this feature in its base class java.io.File. Instead of serializing File instances, a client application should serialize path names instead, which are plain strings.

Since:
TrueZIP 6.5
Author:
Christian Schlichtherle

Nested Class Summary
 
Nested classes/interfaces inherited from class de.schlichtherle.io.ArchiveDriverRegistry
ArchiveDriverRegistry.IllegalArchiveDriverException
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
 String allSuffixes
          The canonical list of all archive file suffixes in the global registry.
private static String CLASS_NAME
           
 String defaultSuffixes
          The canonical list of archive file suffixes in the global registry which have been configured to be recognized by default.
static GlobalArchiveDriverRegistry INSTANCE
          The (pseudo) singleton instance.
private static String KWD_ALL
           
private static String KWD_NULL
           
private static Logger logger
           
private static String PROP_KEY_DEFAULT_SUFFIXES
           
private static String PROP_KEY_REGISTRY
           
private static long serialVersionUID
           
 
Fields inherited from class de.schlichtherle.io.ArchiveDriverRegistry
KWD_DEFAULT, KWD_DRIVER
 
Constructor Summary
private GlobalArchiveDriverRegistry()
          Creates a new GlobalArchiveDriverRegistry.
 
Method Summary
private  SuffixSet defaultSuffixes()
          Consumes and processes the entry for the keyword DEFAULT in the map.
private static String[] getServices()
          Returns the ordered list of relative path names for configuration files.
private  void logConfiguration()
           
private  void registerArchiveDrivers()
           
private static void registerArchiveDrivers(Map config, ArchiveDriverRegistry driverRegistry, ArchiveDriverRegistry clientRegistry)
          Processes the given config in order to register its archive drivers.
private static void registerArchiveDrivers(String service, ArchiveDriverRegistry driverRegistry, ArchiveDriverRegistry clientRegistry)
          Enumerates all resource URLs for service on the class path and calls registerArchiveDrivers(URL, ArchiveDriverRegistry, ArchiveDriverRegistry) on each instance.
private static void registerArchiveDrivers(URL url, ArchiveDriverRegistry driverRegistry, ArchiveDriverRegistry clientRegistry)
          Loads and processes the given url in order to register the archive drivers in its config resource file.
 
Methods inherited from class de.schlichtherle.io.ArchiveDriverRegistry
decorate, getArchiveDriver, registerArchiveDrivers, suffixes
 
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

logger

private static final Logger logger

KWD_NULL

private static final String KWD_NULL
See Also:
Constant Field Values

KWD_ALL

private static final String KWD_ALL
See Also:
Constant Field Values

PROP_KEY_DEFAULT_SUFFIXES

private static final String PROP_KEY_DEFAULT_SUFFIXES
See Also:
Constant Field Values

PROP_KEY_REGISTRY

private static final String PROP_KEY_REGISTRY
See Also:
Constant Field Values

INSTANCE

public static final GlobalArchiveDriverRegistry INSTANCE
The (pseudo) singleton instance.


defaultSuffixes

public final String defaultSuffixes
The canonical list of archive file suffixes in the global registry which have been configured to be recognized by default.


allSuffixes

public final String allSuffixes
The canonical list of all archive file suffixes in the global registry.

Constructor Detail

GlobalArchiveDriverRegistry

private GlobalArchiveDriverRegistry()
Creates a new GlobalArchiveDriverRegistry. This constructor logs some configuration messages at Level.CONFIG. If an exception occurs during processing of the configuration resource files or no archive drivers are registered, then one or more warnings messages are logged at Level.WARNING, but otherwise the constructor terminates normally. This is to ensure that TrueZIP can be used without throwing exceptions in static initializers just because of a bug in a configuration resource file.

Method Detail

getServices

private static String[] getServices()
Returns the ordered list of relative path names for configuration files. Prior elements take precedence.


registerArchiveDrivers

private void registerArchiveDrivers()

registerArchiveDrivers

private static void registerArchiveDrivers(String service,
                                           ArchiveDriverRegistry driverRegistry,
                                           ArchiveDriverRegistry clientRegistry)
Enumerates all resource URLs for service on the class path and calls registerArchiveDrivers(URL, ArchiveDriverRegistry, ArchiveDriverRegistry) on each instance.

Ensures that configuration files specified by client applications always override configuration files specified by driver implementations.


registerArchiveDrivers

private static void registerArchiveDrivers(URL url,
                                           ArchiveDriverRegistry driverRegistry,
                                           ArchiveDriverRegistry clientRegistry)
Loads and processes the given url in order to register the archive drivers in its config resource file.


registerArchiveDrivers

private static void registerArchiveDrivers(Map config,
                                           ArchiveDriverRegistry driverRegistry,
                                           ArchiveDriverRegistry clientRegistry)
Processes the given config in order to register its archive drivers.

Throws:
NullPointerException - If any archive driver ID in the configuration is null.

defaultSuffixes

private SuffixSet defaultSuffixes()
Consumes and processes the entry for the keyword DEFAULT in the map. If a suffix is specified for which no driver is registered, then a warning is logged and the suffix is removed from the return value.

Returns:
The set of suffixes processed by evaluating the value of the entry with the key DEFAULT in the map of drivers. May be empty, but never null.

logConfiguration

private void logConfiguration()

TrueZIP 6.8.3

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