org.jboss.virtual
Class AssembledDirectory

java.lang.Object
  extended by org.jboss.virtual.VirtualFile
      extended by org.jboss.virtual.AssembledDirectory
All Implemented Interfaces:
Serializable

public class AssembledDirectory
extends VirtualFile

Extension of VirtualFile that represents a virtual directory that can be composed of arbitrary files and resources spread throughout the file system or embedded in jar files.

Version:
$Revision: 1.1 $
Author:
Bill Burke, Ales Justin
See Also:
Serialized Form

Constructor Summary
AssembledDirectory(AssembledDirectoryHandler handler)
           
 
Method Summary
 VirtualFile addBytes(byte[] bytes, String name)
          Add raw bytes as a file to this assembled directory
 VirtualFile addChild(VirtualFile vf)
          Add a VirtualFile as a child to this AssembledDirectory.
 VirtualFile addChild(VirtualFile vf, String newName)
          Add a VirtualFile as a child to this AssembledDirectory.
 void addClass(Class<?> clazz)
          Find the underlying .class file representing this class and create it within this directory, along with its packages.
 void addClass(String className)
          Find the underlying .class file representing this class and create it within this directory, along with its packages.
 void addClass(String className, ClassLoader loader)
          Find the underlying .class file representing this class and create it within this directory, along with its packages.
 void addPath(VirtualFile root)
          Add files recursively from root, using the no jars filter.
 void addPath(VirtualFile root, VirtualFileFilter recurseFilter)
          Add files recursively from root, using the filter.
 VirtualFile addResource(String resource)
          Add a classloader found resource to as a child to this AssembledDirectory.
 VirtualFile addResource(String resource, ClassLoader loader)
          Add a classloader found resource to as a child to this AssembledDirectory.
 VirtualFile addResource(String resource, ClassLoader loader, String newName)
          Add a classloader found resource to as a child to this AssembledDirectory.
 VirtualFile addResource(String resource, String newName)
          Add a classloader found resource to as a child to this AssembledDirectory.
 VirtualFile addResource(URL url)
          Add a resource identified by the URL as a child to this AssembledDirectory.
 void addResources(Class<?> baseResource, String[] includes, String[] excludes)
          Locate the .class resource of baseResource.
 void addResources(String baseResource, String[] includes, String[] excludes)
          From the baseResource, determine the base of that resource i.e.
 void addResources(String baseResource, String[] includes, String[] excludes, ClassLoader loader)
          From the baseResource, determine the base of that resource i.e.
static boolean antMatch(String path, String expression)
          Determine whether a given file path matches an Ant pattern.
static AssembledDirectory createAssembledDirectory(String name, String rootName)
          Create assembled directory.
static Pattern getPattern(String matcher)
          Create a regular expression pattern from an Ant file matching pattern
 AssembledDirectory mkdir(String name)
          Create a directory within this directory.
 AssembledDirectory mkdirs(String path)
          Make any directories for the give path to a file.
 
Methods inherited from class org.jboss.virtual.VirtualFile
checkStreams, cleanup, close, closeStreams, delete, delete, equals, exists, findChild, getChild, getChildren, getChildren, getChildrenRecursively, getChildrenRecursively, getLastModified, getName, getParent, getPathName, getSize, getVFS, hasBeenModified, hashCode, isArchive, isHidden, isLeaf, openStream, toString, toURI, toURL, visit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AssembledDirectory

public AssembledDirectory(AssembledDirectoryHandler handler)
Method Detail

createAssembledDirectory

public static AssembledDirectory createAssembledDirectory(String name,
                                                          String rootName)
                                                   throws IOException,
                                                          URISyntaxException
Create assembled directory.

Parameters:
name - context's name
rootName - root name
Returns:
new assembled directory instance
Throws:
IOException - for any IO error
URISyntaxException - for any URI error

addPath

public void addPath(VirtualFile root)
             throws IOException
Add files recursively from root, using the no jars filter.

Parameters:
root - the root
Throws:
IOException - for any error

addPath

public void addPath(VirtualFile root,
                    VirtualFileFilter recurseFilter)
             throws IOException
Add files recursively from root, using the filter.

Parameters:
root - the root
recurseFilter - the recurse filter
Throws:
IOException - for any error

addClass

public void addClass(Class<?> clazz)
Find the underlying .class file representing this class and create it within this directory, along with its packages. So, if you added com.acme.Customer class, then a directory structure com/acme would be created and an entry in the acme directory would be the .class file.

Parameters:
clazz - the class

addClass

public void addClass(String className)
Find the underlying .class file representing this class and create it within this directory, along with its packages. So, if you added com.acme.Customer class, then a directory structure com/acme would be created and an entry in the acme directory would be the .class file.

Parameters:
className - the class name

addClass

public void addClass(String className,
                     ClassLoader loader)
Find the underlying .class file representing this class and create it within this directory, along with its packages. So, if you added com.acme.Customer class, then a directory structure com/acme would be created and an entry in the acme directory would be the .class file.

Parameters:
className - the class name
loader - ClassLoader to look for class resource

mkdirs

public AssembledDirectory mkdirs(String path)
Make any directories for the give path to a file.

Parameters:
path - must be a path to a file as last element in path does not have a directory created
Returns:
directory file will live in

addResources

public void addResources(Class<?> baseResource,
                         String[] includes,
                         String[] excludes)
Locate the .class resource of baseResource. From this resource, determine the base of the resource i.e. what jar or classpath directory it lives in. Once the base of the resource is found, scan all files recursively within the base using the include and exclude patterns. A mirror file structure will be created within this AssembledDirectory. Ths is very useful when you want to create a virtual jar that contains a subset of .class files in your classpath. The include/exclude patterns follow the Ant file pattern matching syntax. See ant.apache.org for more details.

Parameters:
baseResource - the base resource
includes - the includes
excludes - the excludes

addResources

public void addResources(String baseResource,
                         String[] includes,
                         String[] excludes)
From the baseResource, determine the base of that resource i.e. what jar or classpath directory it lives in. The Thread.currentThread().getContextClassloader() will be used Once the base of the resource is found, scan all files recursively within the base using the include and exclude patterns. A mirror file structure will be created within this AssembledDirectory. Ths is very useful when you want to create a virtual jar that contains a subset of .class files in your classpath. The include/exclude patterns follow the Ant file pattern matching syntax. See ant.apache.org for more details.

Parameters:
baseResource - the base resource
includes - the includes
excludes - the excludes

addResources

public void addResources(String baseResource,
                         String[] includes,
                         String[] excludes,
                         ClassLoader loader)
From the baseResource, determine the base of that resource i.e. what jar or classpath directory it lives in. The loader parameter will be used to find the resource. Once the base of the resource is found, scan all files recursively within the base using the include and exclude patterns. A mirror file structure will be created within this AssembledDirectory. Ths is very useful when you want to create a virtual jar that contains a subset of .class files in your classpath. The include/exclude patterns follow the Ant file pattern matching syntax. See ant.apache.org for more details.

Parameters:
baseResource - the base resource
includes - the includes
excludes - the excludes
loader - the loader

getPattern

public static Pattern getPattern(String matcher)
Create a regular expression pattern from an Ant file matching pattern

Parameters:
matcher - the matcher pattern
Returns:
the pattern instance

antMatch

public static boolean antMatch(String path,
                               String expression)
Determine whether a given file path matches an Ant pattern.

Parameters:
path - the path
expression - the expression
Returns:
true if we match

addChild

public VirtualFile addChild(VirtualFile vf)
Add a VirtualFile as a child to this AssembledDirectory.

Parameters:
vf - the virtual file
Returns:
the file

addChild

public VirtualFile addChild(VirtualFile vf,
                            String newName)
Add a VirtualFile as a child to this AssembledDirectory. This file will be added under a new aliased name.

Parameters:
vf - the virtual file
newName - the new name
Returns:
new file

addResource

public VirtualFile addResource(String resource)
Add a classloader found resource to as a child to this AssembledDirectory. The base file name of the resource will be used as the child's name. Thread.currentThread.getCOntextClassLoader() will be used to load the resource.

Parameters:
resource - the resource
Returns:
the file

addResource

public VirtualFile addResource(String resource,
                               String newName)
Add a classloader found resource to as a child to this AssembledDirectory. The newName parameter will be used as the name of the child. Thread.currentThread.getCOntextClassLoader() will be used to load the resource.

Parameters:
resource - the resource
newName - the new name
Returns:
the file

addResource

public VirtualFile addResource(String resource,
                               ClassLoader loader)
Add a classloader found resource to as a child to this AssembledDirectory. The base file name of the resource will be used as the child's name. The loader parameter will be used to load the resource.

Parameters:
resource - the resource
loader - the loader
Returns:
the file

addResource

public VirtualFile addResource(URL url)
Add a resource identified by the URL as a child to this AssembledDirectory.

Parameters:
url - the url
Returns:
the file

addResource

public VirtualFile addResource(String resource,
                               ClassLoader loader,
                               String newName)
Add a classloader found resource to as a child to this AssembledDirectory. The newName parameter will be used as the name of the child. The loader parameter will be used to load the resource.

Parameters:
resource - the resource
loader - the loader
newName - the new name
Returns:
the file

addBytes

public VirtualFile addBytes(byte[] bytes,
                            String name)
Add raw bytes as a file to this assembled directory

Parameters:
bytes - the bytes
name - the name
Returns:
the file

mkdir

public AssembledDirectory mkdir(String name)
Create a directory within this directory.

Parameters:
name - the name
Returns:
the directory


Copyright © 2009 JBoss, A division of Red Hat, Inc. All Rights Reserved.