org.hibernate.ejb.packaging
Class JarVisitor

java.lang.Object
  extended by org.hibernate.ejb.packaging.JarVisitor
Direct Known Subclasses:
ExplodedJarVisitor, FileZippedJarVisitor, InputStreamZippedJarVisitor

public abstract class JarVisitor
extends Object

Parse a JAR of any form (zip file, exploded directory, ...) apply a set of filters (File filter, Class filter, Package filter) and return the appropriate matching sets of elements

Author:
Emmanuel Bernard

Nested Class Summary
static class JarVisitor.ClassFilter
          Filter on class elements
static class JarVisitor.Entry
          Represent a JAR entry Contains a name and an optional Input stream to the entry
static class JarVisitor.FileFilter
          Filter use to match a file by its name
static class JarVisitor.Filter
          Filter used when searching elements in a JAR
static class JarVisitor.JavaElementFilter
          Filter a Java element (class or package per fully qualified name and annotation existence) At least 1 annotation has to annotate the element and the accept method must match If none annotations are passed, only the accept method must pass.
static class JarVisitor.PackageFilter
          Filter on pachage element
 
Field Summary
protected  URL jarUrl
           
protected  String unqualifiedJarName
           
 
Constructor Summary
protected JarVisitor(String fileName, JarVisitor.Filter[] filters)
           
protected JarVisitor(URL url, JarVisitor.Filter[] filters)
           
 
Method Summary
protected  void addElement(String entryName, InputStream is, InputStream secondIs)
           
protected abstract  void doProcessElements()
           
 JarVisitor.Filter[] getFilters()
           
static URL getJarURLFromURLEntry(URL url, String entry)
          Get the JAR URL of the JAR containing the given entry
 Set[] getMatchingEntries()
          Return the matching entries for each filter in the same order the filter where passed
 String getUnqualifiedJarName()
          Get the unqualified Jar name (ie wo path and wo extension)
static JarVisitor getVisitor(String jarPath, JarVisitor.Filter[] filters)
          Get a JarVisitor to the jar jarPath applying the given filters
static JarVisitor getVisitor(URL jarUrl, JarVisitor.Filter[] filters)
          Build a JarVisitor on the given JAR URL applying th given filters
protected  void unqualify()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

unqualifiedJarName

protected String unqualifiedJarName

jarUrl

protected URL jarUrl
Constructor Detail

JarVisitor

protected JarVisitor(String fileName,
                     JarVisitor.Filter[] filters)

JarVisitor

protected JarVisitor(URL url,
                     JarVisitor.Filter[] filters)
Method Detail

getJarURLFromURLEntry

public static final URL getJarURLFromURLEntry(URL url,
                                              String entry)
                                       throws IllegalArgumentException
Get the JAR URL of the JAR containing the given entry

Parameters:
url -
entry -
Returns:
the JAR URL
Throws:
IllegalArgumentException - if none URL is found

getVisitor

public static final JarVisitor getVisitor(URL jarUrl,
                                          JarVisitor.Filter[] filters)
                                   throws IllegalArgumentException
Build a JarVisitor on the given JAR URL applying th given filters

Throws:
IllegalArgumentException - if the URL is malformed

getVisitor

public static final JarVisitor getVisitor(String jarPath,
                                          JarVisitor.Filter[] filters)
                                   throws IllegalArgumentException
Get a JarVisitor to the jar jarPath applying the given filters

Throws:
IllegalArgumentException - if the jarPath is incorrect

unqualify

protected void unqualify()

getUnqualifiedJarName

public String getUnqualifiedJarName()
Get the unqualified Jar name (ie wo path and wo extension)


getFilters

public JarVisitor.Filter[] getFilters()

getMatchingEntries

public final Set[] getMatchingEntries()
                               throws IOException
Return the matching entries for each filter in the same order the filter where passed

Returns:
array of Set of JarVisitor.Entry
Throws:
IOException - if something went wrong

doProcessElements

protected abstract void doProcessElements()
                                   throws IOException
Throws:
IOException

addElement

protected final void addElement(String entryName,
                                InputStream is,
                                InputStream secondIs)
                         throws IOException
Throws:
IOException