com.sun.enterprise.tools.verifier.apiscan.classfile
Class ClosureCompilerImpl
java.lang.Object
com.sun.enterprise.tools.verifier.apiscan.classfile.ClosureCompilerImpl
- All Implemented Interfaces:
- ClosureCompiler
public class ClosureCompilerImpl
- extends Object
- implements ClosureCompiler
This is single most important class of the apiscan package. This class is
used to compute the complete closure of a set of classes. It uses ClassFile
to find out dependencies of a class. For each references class
name, it loads the corresponding ClassFile using the ClassFileLoader passed
to it in constructor. Then it recurssively computes the dependencies until it
visits either Java primitive classes or the class name matches the exclude
list. Example of using this class is given below...
String classpath="your own classpath";
ClassFileLoader cfl=ClassFileLoaderFactory.newInstance(new
Object[]{classpath});
ClosureCompilerImpl cc=new ClosureCompilerImpl(cfl);
cc.addExcludePattern("java.");//exclude all classes that start with java.
Most of the J2SE classes will be excluded thus.
cc.addExcludePattern("javax.");//Most of the J2EE classes can be excluded
like this.
cc.addExcludePackage("org.omg.CORBA");//Exclude classes whose package name is
org.omg.CORBA
cc.addExcludeClass("mypackage.Foo");//Exclude class whose name is
myPackage.Foo
boolean successful=cc.buildClosure("a.b.MyEjb");
successful=cc.buildClosure("a.b.YourEjb") && successful; //note the order of
&&.
Collection closure=cc.getClosure();//now closure contains the union of
closure for the two classes.
Map failed=cc.getFailed();//now failure contains the union of failures for
the two classes.
cc.reset();//clear the results collected so far so that we can start afresh.
//Now you can again start computing closure of another set of classes.
//The excluded stuff are still valid.
- Author:
- Sanjeeb.Sahoo@Sun.COM
ClosureCompilerImpl
public ClosureCompilerImpl(ClassFileLoader loader)
- Parameters:
loader
- the ClassFileLoader that is used to load the referenced
classes.
ClosureCompilerImpl
public ClosureCompilerImpl(ClosureCompilerImplBase imp)
- I don't expect this constructor to be used. Only defined for
testing purpose.
- Parameters:
imp
- the implementation in the bridge design pattern.
addExcludedClass
public void addExcludedClass(String className)
- Parameters:
className
- the class name to be excluded from closure
computation. It is in the external class name format
(i.e. java.util.Map$Entry instead of java.util.Map.Entry).
When the closure compiler sees a class matches this
name, it does not try to compute its closure any
more. It merely adds this name to the closure. So the
final closure will contain this class name, but not
its dependencies.
addExcludedPackage
public void addExcludedPackage(String pkgName)
- Parameters:
pkgName
- the package name of classes to be excluded from
closure computation. It is in the external format
(i.e. java.lang (See no trailing '.'). When the
closure compiler sees a class whose package name
matches this name, it does not try to compute the
closure of that class any more. It merely adds that
class name to the closure. So the final closure will
contain that class name, but not its dependencies.
addExcludedPattern
public void addExcludedPattern(String pattern)
- Parameters:
pattern
- the pattern for the names of classes to be excluded from
closure computation. It is in the external format (i.e.
org.apache.). When the closure compiler sees a class whose
name begins with this pattern, it does not try to compute
the closure of that class any more. It merely adds that
class name to the closure. So the final closure will
contain that class name, but not its dependencies. Among
all the excluded list, it is given the lowest priority in
search order.
buildClosure
public boolean buildClosure(String className)
- Specified by:
buildClosure
in interface ClosureCompiler
- Parameters:
className
- class name (in external format) whose closure will
be computed.
- Returns:
- true if it can compute the closure for all the classes that are
new to it, else false. In other words, this operation is not
idempotent. e.g. ClosureCompiler cc; cc.reset(); boolean
first=cc.buildClosure("a.B"); boolean second=cc.buildClosure("a.B");
second will always be true irrespective of value of first. This
is because it uses list of classes that it has already visited.
That list gets cleared when
ClosureCompiler.reset()
is called).
buildClosure
public boolean buildClosure(JarFile jar)
throws IOException
- Parameters:
jar
- whose classes it will try to build closure of. This is a
convenience method which iterates over all the entries in a
jar file and computes their closure.
- Throws:
IOException
getClosure
public Collection getClosure()
- Specified by:
getClosure
in interface ClosureCompiler
- Returns:
- unmodifiable collection of class names which it visited during
closure computation. e.g. Let's say a.class references b1.class
and b2.class. b1.class references c1.class, c2.class and c3.class
b2.class references d1.class, d2.class and d3.class.
c1/c2/d1/d2.class are all not loadable where as c3 and d3.class
are loadable. When we build the closure of a.class, closure will
contain the following... {"a", "b1", "b2", "c3", "d3"}
getFailed
public Map getFailed()
- Specified by:
getFailed
in interface ClosureCompiler
- Returns:
- unmodifiable collection of class names whose closure could not be
computed. The typical reason for not able to build closure for a
class is that class not being found in loader's search path. See
it returns a map which is keyed by the access path and the value
is a list of class names which could not be loaded. e.g. Let's
say a.class references b1.class and b2.class. b1.class references
c1.class, c2.class and c3.class b2.class references d1.class,
d2.class and d3.class. c1/c2/d1/d2.class are all not loadable
where as c3 and d3.class are loadable. When we build the closure
of a.class, failed map will contain the following... {("a:b1",
{"c1","c2"}), ("a.b2", {"d1","d2"})}
reset
public void reset()
- Reset the closure for next closure computation.
Clear the internal cache. It includes the result it has collected since
last reset(). But it does not clear the excludedd list. If you want to
reset the excluded list, create a new ClosureCompiler.
- Specified by:
reset
in interface ClosureCompiler
getNativeMethods
public Collection<String> getNativeMethods()
toString
public String toString()
- Overrides:
toString
in class Object
main
public static void main(String[] args)
Copyright © 2013 Oracle Corporation. All Rights Reserved.