Remote Systems
v6.4.1

com.ibm.etools.systems.core.archiveutils
Class ArchiveHandlerManager

java.lang.Object
  extended bycom.ibm.etools.systems.core.archiveutils.ArchiveHandlerManager

public class ArchiveHandlerManager
extends Object

This class manages all the Archive Handlers that correspond to the archive file that the system would like to deal with. It contains methods for registering handlers with file types, as well as utilities for getting at the contents of archives that the Manager represents. This class is designed to be a singleton class, so the best way to use it is to use statements of the form "ArchiveHandlerManager.getInstance().method".


Field Summary
protected  HashMap _handlers
           
protected  HashMap _handlerTypes
           
protected static ArchiveHandlerManager _instance
           
static String VIRTUAL_CANONICAL_SEPARATOR
           
static String VIRTUAL_SEPARATOR
           
 
Constructor Summary
ArchiveHandlerManager()
           
 
Method Summary
static String cleanUpVirtualPath(String fullVirtualName)
          Converts the virtual path given by fullVirtualName to the standard virtual form ('/' as separator, no leading or trailing '/'s)
 boolean createEmptyArchive(File newFile)
           
 void dispose()
          Disposes of all registered handlers.
 void disposeOfRegisteredHandlerFor(File file)
          Removes the handler associated with file, freeing the file to be used by other processes.
 String getClassification(File file, String virtualPath)
          Returns the classification for the entry in a archive with the given virtual path.
 String getComment(File archive)
           
 VirtualChild[] getContents(File file, String virtualpath)
          Returns the children of an object in the virtual file system.
 long getExpandedSize(File archive)
           
protected  String getExtension(File file)
           
protected  String getExtension(String filename)
           
 VirtualChild[] getFolderContents(File file, String virtualpath)
          Returns the children of an object in the virtual file system that are folders.
static ArchiveHandlerManager getInstance()
           
 Constructor getProperConstructor(Class handlerType)
           
 String[] getRegisteredExtensions()
          Returns the extensions for archive types that have been registered with the ArchiveHandlerManager.
 ISystemArchiveHandler getRegisteredHandler(File file)
          Returns the registered handler for the File file.
 VirtualChild getVirtualObject(String fullyQualifiedName)
          Given the absolute path to a virtual object, returns that object as a VirtualChild.
protected  boolean handlerHasProperConstructor(Class handlerType)
          Returns whether or not handlerType has a constructor that takes only one parameter, a java.io.File.
protected  boolean handlerImplementsISystemArchiveHandler(Class handlerType)
          Returns whether or not handlerType or one of its superclasses implements ISystemArchiveHandler.
 boolean isArchive(File file)
          Tests whether a file is an known type of archive.
 boolean isRegisteredArchive(String filename)
          Tests whether a file is an known type of archive, based on the file name.
static boolean isVirtual(String path)
          Tests whether the absolute path given by path refers to a virtual object.
 boolean setRegisteredHandler(String ext, Class handlerType)
          Registers an extension and a handler type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VIRTUAL_SEPARATOR

public static final String VIRTUAL_SEPARATOR
See Also:
Constant Field Values

VIRTUAL_CANONICAL_SEPARATOR

public static final String VIRTUAL_CANONICAL_SEPARATOR
See Also:
Constant Field Values

_instance

protected static ArchiveHandlerManager _instance

_handlers

protected HashMap _handlers

_handlerTypes

protected HashMap _handlerTypes
Constructor Detail

ArchiveHandlerManager

public ArchiveHandlerManager()
Method Detail

getInstance

public static ArchiveHandlerManager getInstance()
Returns:
The singleton instance of this class.

getContents

public VirtualChild[] getContents(File file,
                                  String virtualpath)
                           throws IOException
Returns the children of an object in the virtual file system.

Parameters:
file - The archive in whose virtual file system the children reside.
virtualpath - The parent virtual object whose children this method is to return. To get the top level virtualchildren in the archive, set virtualpath to "" or null.
Returns:
An array of VirtualChild objects representing the children of the virtual object in file referred to by virtualpath. If no class implementing ISystemArchiveHandler can be found that corresponds to file, then this method returns null. If the virtual object has no children, this method also returns null.
Throws:
IOException - if there was a problem getting the registered handler for the file. This usually means the archive is corrupted.

getFolderContents

public VirtualChild[] getFolderContents(File file,
                                        String virtualpath)
Returns the children of an object in the virtual file system that are folders.

Parameters:
file - The archive in whose virtual file system the children reside.
virtualpath - The parent virtual object whose children this method is to return. To get the top level virtualchildren in the archive, set virtualpath to "" or null.
Returns:
An array of VirtualChild objects representing the children of the virtual object in file referred to by virtualpath that are themselves folders. If no class implementing ISystemArchiveHandler can be found that corresponds to file, then this method returns null. If the virtual object has no children, this method also returns null.

isArchive

public boolean isArchive(File file)
Tests whether a file is an known type of archive.

Parameters:
file - the file to test.
Returns:
true if and only if the file is an archive whose type is registered with the ArchiveHandlerManager.

isRegisteredArchive

public boolean isRegisteredArchive(String filename)
Tests whether a file is an known type of archive, based on the file name.

Returns:
true if and only if the file is an archive whose type is registered with the ArchiveHandlerManager.

getExtension

protected String getExtension(File file)
Parameters:
file - the file whose extension we are computing.
Returns:
the extension of file. "Extension" is defined as any letters in the filename after the last ".". Returns "" if there is no extension.

getExtension

protected String getExtension(String filename)
Parameters:
filename - the name of the file whose extension we are computing.
Returns:
the extension of filename. "Extension" is defined as any letters in the filename after the last ".". Returns "" if there is no extension.

getVirtualObject

public VirtualChild getVirtualObject(String fullyQualifiedName)
Given the absolute path to a virtual object, returns that object as a VirtualChild.

Parameters:
fullyQualifiedName - The absolute path to the object. Usually consists of the fullyQualifiedName of the archive, followed by the virtual path separator (defined in ArchiveHandlerManager.VIRTUAL_SEPARATOR) followed by the virtual path to the object within the archive's virtual file system.

getRegisteredHandler

public ISystemArchiveHandler getRegisteredHandler(File file)
Returns the registered handler for the File file. If no handler exists for that file yet, create it. If the extension of file is not registered, then returns null.


getProperConstructor

public Constructor getProperConstructor(Class handlerType)

setRegisteredHandler

public boolean setRegisteredHandler(String ext,
                                    Class handlerType)
Registers an extension and a handler type.

Parameters:
ext - The extension to register with the ArchiveHandlerManager
handlerType - The class of handler to register with ext. Note that any class passed in must implement ISystemArchiveHandler.
Returns:
Whether or not the registration was successful.

handlerHasProperConstructor

protected boolean handlerHasProperConstructor(Class handlerType)
Returns whether or not handlerType has a constructor that takes only one parameter, a java.io.File.


handlerImplementsISystemArchiveHandler

protected boolean handlerImplementsISystemArchiveHandler(Class handlerType)
Returns whether or not handlerType or one of its superclasses implements ISystemArchiveHandler.


disposeOfRegisteredHandlerFor

public void disposeOfRegisteredHandlerFor(File file)
Removes the handler associated with file, freeing the file to be used by other processes.


isVirtual

public static boolean isVirtual(String path)
Tests whether the absolute path given by path refers to a virtual object.

Parameters:
path -
Returns:
True if and only if the absolute path refers to a virtual object.

cleanUpVirtualPath

public static String cleanUpVirtualPath(String fullVirtualName)
Converts the virtual path given by fullVirtualName to the standard virtual form ('/' as separator, no leading or trailing '/'s)

Parameters:
fullVirtualName - the path to convert
Returns:
the new path in standard form

dispose

public void dispose()
Disposes of all registered handlers.


createEmptyArchive

public boolean createEmptyArchive(File newFile)

getRegisteredExtensions

public String[] getRegisteredExtensions()
Returns the extensions for archive types that have been registered with the ArchiveHandlerManager.


getComment

public String getComment(File archive)

getExpandedSize

public long getExpandedSize(File archive)

getClassification

public String getClassification(File file,
                                String virtualPath)
Returns the classification for the entry in a archive with the given virtual path.

Parameters:
file - the archive file.
virtualPath - the virtual path.
Returns:
the classification for the virtual file.

Remote Systems
v6.4.1

Copyright © 2005 IBM Corp. All Rights Reserved.

Note: This documentation is for part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.