sk.baka.webvm.analyzer.classloader
Class ResourceLink

java.lang.Object
  extended by sk.baka.webvm.analyzer.classloader.ResourceLink
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DirResourceLink, JarResourceLink, ResourceLinkGroup

public abstract class ResourceLink
extends Object
implements Serializable

Represents an on-disk package or a package item.

Author:
Martin Vysny
See Also:
Serialized Form

Constructor Summary
ResourceLink()
           
 
Method Summary
protected  void assertNotPackage()
          Asserts that this is not a package.
protected  void assertPackage()
          Asserts that this is a package.
static ResourceLink findFirstByName(List<ResourceLink> links, String name)
          Finds first link with given name.
abstract  File getContainer()
          Returns a file link to the resource container containing these links.
abstract  String getFullName()
          Returns a full name, including parent packages and full path to the root.
abstract  long getLength()
          Returns length of underlying resource.
abstract  String getName()
          Returns the package/resource name.
static List<String> getNames(List<ResourceLink> links)
          Returns a list of names from given list of links
abstract  boolean isPackage()
          Checks if resource denoted by this object is actually a package, or just a resource file.
abstract  boolean isRoot()
          Checks if this resource link denotes a root of a jar/directory.
abstract  List<ResourceLink> list()
          Lists all direct child packages and items of this package.
 List<ResourceLink> listAndGroup()
          Lists all direct child packages and items of this package.
static ResourceLink newFor(File file)
          Opens given directory or jar file and allows package and resource enumeration.
abstract  InputStream open()
          Opens a stream to the file denoted by this link.
abstract  List<ResourceLink> search(String substring)
          Performs a search for given substring.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceLink

public ResourceLink()
Method Detail

newFor

public static ResourceLink newFor(File file)
Opens given directory or jar file and allows package and resource enumeration.

Parameters:
file - the resource directory or a jar file
Returns:
new resource enumerator.

getNames

public static List<String> getNames(List<ResourceLink> links)
Returns a list of names from given list of links

Parameters:
links - not null
Returns:
never null

findFirstByName

public static ResourceLink findFirstByName(List<ResourceLink> links,
                                           String name)
Finds first link with given name.

Parameters:
links - a list of links, must not be null
name - the name of the resource.
Returns:
the link with given name, never null
Throws:
IllegalArgumentException - if no such link exists

search

public abstract List<ResourceLink> search(String substring)
                                   throws IOException
Performs a search for given substring. The substring matching must be performed in the last resource path item only - i.e. the function will match the following for "a": /a, /a/a, /b/a, but not /a/b.

Parameters:
substring - a string to search, must not be null.
Returns:
non-null list of matched resources, may be empty.
Throws:
IOException - on i/o error

getLength

public abstract long getLength()
                        throws IOException
Returns length of underlying resource.

Returns:
the length or -1 if not known or invoked on a package.
Throws:
IOException - on i/o error

listAndGroup

public final List<ResourceLink> listAndGroup()
                                      throws IOException
Lists all direct child packages and items of this package. It is invalid to call this method on a non-package resource. Groups single-package-child names together.

Returns:
list of all children.
Throws:
IOException - on i/o error

list

public abstract List<ResourceLink> list()
                                 throws IOException
Lists all direct child packages and items of this package. It is invalid to call this method on a non-package resource.

Returns:
list of all children.
Throws:
IOException - on i/o error

isPackage

public abstract boolean isPackage()
Checks if resource denoted by this object is actually a package, or just a resource file.

Returns:
true if this is a package, false otherwise. Root link is always a package.

open

public abstract InputStream open()
                          throws IOException
Opens a stream to the file denoted by this link. It is invalid to call this method on a package resource.

Returns:
the file contents.
Throws:
IOException - on i/o error

getName

public abstract String getName()
Returns the package/resource name. Does not include names of the parent packages nor any slash characters. Name of the root package is a full directory/jar file name.

Returns:
the name of the resource denoted by this link.

getFullName

public abstract String getFullName()
Returns a full name, including parent packages and full path to the root. Must not end with a slash.

Returns:
a full name.

isRoot

public abstract boolean isRoot()
Checks if this resource link denotes a root of a jar/directory.

Returns:
true if this is a jar/directory root, false otherwise.

getContainer

public abstract File getContainer()
Returns a file link to the resource container containing these links. Required to be valid only for root links.

Returns:
file denoting the container or null.

toString

public String toString()
Overrides:
toString in class Object

assertPackage

protected void assertPackage()
Asserts that this is a package.


assertNotPackage

protected void assertNotPackage()
Asserts that this is not a package.



Copyright © 2010 Baka. All Rights Reserved.