com.sun.jini.tool.classdepend
Class ClassDepend

java.lang.Object
  extended by com.sun.jini.tool.classdepend.ClassDepend

public class ClassDepend
extends Object

Provides a utility for computing which classes are depended on by a set of classes. This class is not thread safe.


Method Summary
 Pattern createPattern(Collection names)
          Creates a pattern that matches class names for any of the names in the argument.
 Set filterClassDependencyRelationShipMap(Map dependencyRelationShipMap, ClassDependParameters cdp)
          This method applies optional filters to provide methods to support the original API of ClassDep.
 Map getDependencyRelationshipMap(Collection rootClasses, boolean recurse)
          This method builds the entire DependencyRelationShipMap that can be used to analyse class dependencies.
static void main(String[] args)
           
 boolean matches(String string, Pattern pattern)
          Checks if the string matches the pattern, returning false if the pattern is null.
static ClassDepend newInstance(String classpath, String platform, boolean warn)
          Public Factory method for creating a new instance of ClassDepend.
protected  void noteClassLoadingFailed(String name, IOException e)
          Called when attempts to load the bytecodes for the specified class fail.
protected  void noteClassNotFound(String name)
          Called when the specified class is not found.
 boolean printClassesWithFileSeparator()
           
 void setPrintClassesWithFileSeparator(boolean printClassesWithFileSeparator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static ClassDepend newInstance(String classpath,
                                      String platform,
                                      boolean warn)
                               throws MalformedURLException,
                                      IOException
Public Factory method for creating a new instance of ClassDepend. The classpath argument specifies the classpath that will be used to look up the class bytecode for classes whose dependencies are being computed. If the value specified is null, then the system class loader will be used. Otherwise, a URLClassLoader will be constructed using the URLs specified by classpath and with a parent class loader that is the parent of the system class loader. The platform argument specifies the classpath that will be used to find classes that should be considered part of the platform and should be excluded from consideration when computing dependencies. If the value specified is null, then the parent of the system class loader will be used. Otherwise, a URLClassLoader will be constructed using the URLs specified by platform and with a parent class loader that is the parent of the system class loader.

Parameters:
classpath - the classpath for finding classes, or null
platform - the classpath for finding platform classes, or null
warn - print warnings instead of throwing an exception when a Class can't be found or when ClassLoading fails.
Returns:
ClassDepend
Throws:
MalformedURLException
IOException

main

public static void main(String[] args)

getDependencyRelationshipMap

public Map getDependencyRelationshipMap(Collection rootClasses,
                                        boolean recurse)
                                 throws IOException,
                                        ClassNotFoundException
This method builds the entire DependencyRelationShipMap that can be used to analyse class dependencies. Computes information about class dependencies. The computation of dependencies starts with the classes that match the names in rootClasses. Classes are found in a URL class loader by the classpath specified in the constructor.

Parameters:
rootClasses -
recurse - If true, this option causes ClassDepend to inspect class files for dependencies. If false, ClassDepend doesn't inspect class files, it simply gathers the names of class files from within Package directories and JAR files.
Returns:
result
Throws:
IOException
ClassNotFoundException
See Also:
ClassDependencyRelationship

filterClassDependencyRelationShipMap

public Set filterClassDependencyRelationShipMap(Map dependencyRelationShipMap,
                                                ClassDependParameters cdp)
This method applies optional filters to provide methods to support the original API of ClassDep.

Parameters:
dependencyRelationShipMap - The initial map before filtering.
cdp - The parameters for filtration.
Returns:
Set result The result after filtration.
See Also:
ClassDependParameters, ClassDependencyRelationship

noteClassNotFound

protected void noteClassNotFound(String name)
                          throws ClassNotFoundException
Called when the specified class is not found.

This implementation throws a ClassNotFoundException.

Parameters:
name - the class name
Throws:
ClassNotFoundException - to signal that processing should terminate and the exception should be thrown to the caller

noteClassLoadingFailed

protected void noteClassLoadingFailed(String name,
                                      IOException e)
                               throws IOException
Called when attempts to load the bytecodes for the specified class fail.

Parameters:
name - the class name
e - the exception caused by the failure
Throws:
IOException - to signal that processing should terminate and the exception should be thrown to the caller

createPattern

public Pattern createPattern(Collection names)
Creates a pattern that matches class names for any of the names in the argument. Returns null if the argument is empty. xNames that end in '.*' match classes in the package, names that end in '.**' match classes in the package and it's subpackage. Other names match the class.

Parameters:
names -
Returns:

matches

public boolean matches(String string,
                       Pattern pattern)
Checks if the string matches the pattern, returning false if the pattern is null.

Parameters:
string -
pattern -
Returns:

printClassesWithFileSeparator

public boolean printClassesWithFileSeparator()

setPrintClassesWithFileSeparator

public void setPrintClassesWithFileSeparator(boolean printClassesWithFileSeparator)


Copyright 2007, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.