net.sf.jlayercheck.util
Class XMLConfiguration

java.lang.Object
  extended by net.sf.jlayercheck.util.XMLConfiguration

public class XMLConfiguration
extends Object

Contains a configuration that describes the architecture of the project. It consists of modules that contain packages. Modules can use other modules, but only in a strict directional order, no dependency loops.

An important function is getModelTree(DependencyVisitor) that creates a tree of all modules, packages and classes and their dependencies.

Author:
webmaster@earth3d.org

Field Summary
protected  List<ClassSource> classSources
          Contains the sources defined in the configuration file.
protected  Set<String> entryClasses
          Contains classnames of classes that are used as program entries for the orphaned classes search.
protected  Set<String> excludeList
          Contains the packages that are excluded from the analysis (like java.**).
protected static Logger logger
           
protected  Map<String,Set<String>> moduleDependencies
          Contains the dependencies that belong to one module.
protected  Map<String,Set<String>> modulePackages
          Contains the packages that belong to one module.
 
Constructor Summary
XMLConfiguration()
           
 
Method Summary
 void addClassSource(ClassSource source)
          Adds a new ClassSource.
protected  void addDependencyToModule(String moduleName, String dependencyName)
           
 void addEntryClass(String entryClass)
          Adds a new entry class.
 void addModuleDependency(String moduleName, TreeSet<String> name)
          Adds dependencies from a module to other modules.
protected  void addPackageToExcludeList(String packageName)
           
protected  void addPackageToModule(String moduleName, String packageName)
           
protected  String convertToRegularExpression(String wildcardstring)
          Used internally to convert a string from the wildcard format used in the configuration file into a regular expression.
 TreeNode createIncomingModel(ClassNode node, ModelTree treemodel, DependenciesTreeModel modelToUpdate)
          Creates a dependency tree model for the given node of the given ModelTree.
 TreeNode createModel(ClassNode node, ModelTree treemodel, DependenciesTreeModel modelToUpdate)
          Creates a dependency tree model for the given node of the given ModelTree.
 void cumulateDependencyViolations(ModelTree mt)
          Recalculates the violations state of all nodes of the tree that contain children (e.g.
 Map<String,URL> getAllClassSources()
          Returns a map containing all java class names and an URL that points to the source file.
 List<ClassSource> getClassSources()
          Returns the list of sources for the class and java files.
 Set<String> getEntryClasses()
          Returns a Set of classes that are named as entry classes in the configuration file.
 Set<String> getExcludeList()
          Returns all package entries that are specified to exclude in the configuration file.
 String getMatchingModule(String classname)
          Returns the matching module for the given classname or null.
 ModelTree getModelTree(DependencyVisitor dv)
          Builds a model that contains all dependency information that was retrieved from the class files.
 Map<String,Set<String>> getModuleDependencies()
          Returns the dependencies of all modules.
 Map<String,Set<String>> getModulePackages()
          Returns the packages contained in every module.
 Set<String> getOrphanedClasses(Map<String,Map<String,Set<Integer>>> dependencies)
          Calculates the orphaned classes based on the entry points of the configuration file and the dependency data from the DependencyVisitor.
 Map<String,String> getPackageModules()
          Returns a map that contains the mapping from packages to modules.
 Map<String,Map<String,ClassDependency>> getUnallowedDependencies(Map<String,Map<String,Set<Integer>>> dependencies)
          Returns a map containing the dependencies (from class, to class) that are not allowed by the rules.
 Set<String> getUnspecifiedPackages(Map<String,Map<String,Set<Integer>>> dependencies)
          Returns a list of packages that are not assigned to a module in the given configuration.
protected  Set<String> getUnvisitedDependendClasses(Set<String> visitedClasses, Map<String,Map<String,Set<Integer>>> dependencies, Map<String,URL> allClassSources)
          Returns all classnames that are directly referenced by the visited classes but not yet contained.
 boolean isExcluded(String classname)
          Returns true if the given class is excluded from the analysis.
 boolean isUnallowedDependency(ModuleNode sourceModule, ModuleNode destModule)
          Returns true if the module sourceModule may access destModule.
 boolean isUnallowedDependency(String fromClass, String toClass)
          Returns true if the dependency from fromClass to toClass is not allowed, otherwise false.
 boolean isUnallowedModuleDependency(String fromModule, String toModule)
          Returns true if the dependency from fromModule to toModule is not allowed, otherwise false.
 void updateModelTree(ModelTree mt, File classFile)
          Updates the given modeltree by replacing all information of the given classFile with new information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static Logger logger

modulePackages

protected Map<String,Set<String>> modulePackages
Contains the packages that belong to one module.


moduleDependencies

protected Map<String,Set<String>> moduleDependencies
Contains the dependencies that belong to one module.


classSources

protected List<ClassSource> classSources
Contains the sources defined in the configuration file.


excludeList

protected Set<String> excludeList
Contains the packages that are excluded from the analysis (like java.**).


entryClasses

protected Set<String> entryClasses
Contains classnames of classes that are used as program entries for the orphaned classes search.

Constructor Detail

XMLConfiguration

public XMLConfiguration()
Method Detail

addPackageToExcludeList

protected void addPackageToExcludeList(String packageName)

addDependencyToModule

protected void addDependencyToModule(String moduleName,
                                     String dependencyName)

addPackageToModule

protected void addPackageToModule(String moduleName,
                                  String packageName)

getModuleDependencies

public Map<String,Set<String>> getModuleDependencies()
Returns the dependencies of all modules. The key is the element that depends from all values in the given set. E.g. a dataset a -> (b,c,d) means, that a depends on the modules b, c and d. This normally means that b, c and d are on a lower layer in the architecture.

Returns:
Map with all module dependencies

getModulePackages

public Map<String,Set<String>> getModulePackages()
Returns the packages contained in every module. The key of the Map is the name of the module and the Set contains all package names.

Returns:
Map with all modules and their packages

getMatchingModule

public String getMatchingModule(String classname)
                         throws OverlappingModulesDefinitionException

Returns the matching module for the given classname or null. If more than one module matches, an exception is thrown, because it is a configuration error.

The input must be a classname, not a package name. The last part is expected to be the name of the class.

Returns:
the matching module or null if none was found
Throws:
OverlappingModulesDefinitionException

getPackageModules

public Map<String,String> getPackageModules()
Returns a map that contains the mapping from packages to modules.

Returns:

getClassSources

public List<ClassSource> getClassSources()
Returns the list of sources for the class and java files.

Returns:
list of sources

getAllClassSources

public Map<String,URL> getAllClassSources()
Returns a map containing all java class names and an URL that points to the source file.

Returns:

getExcludeList

public Set<String> getExcludeList()
Returns all package entries that are specified to exclude in the configuration file.

Returns:

isExcluded

public boolean isExcluded(String classname)
Returns true if the given class is excluded from the analysis.

Parameters:
dependency -
Returns:

convertToRegularExpression

protected String convertToRegularExpression(String wildcardstring)
Used internally to convert a string from the wildcard format used in the configuration file into a regular expression.

Parameters:
wildcardstring -
Returns:
wildcardstring converted to regular expression

getEntryClasses

public Set<String> getEntryClasses()
Returns a Set of classes that are named as entry classes in the configuration file. These classes are points where the execution of the system can start. All classes that are directly or indirectly referenced from these named entry classes are marked as used, all others are marked as unused/orphaned.

Returns:
the entryClasses

getOrphanedClasses

public Set<String> getOrphanedClasses(Map<String,Map<String,Set<Integer>>> dependencies)
                               throws OrphanedSearchException
Calculates the orphaned classes based on the entry points of the configuration file and the dependency data from the DependencyVisitor.

Parameters:
dv - the dependency data to use
Throws:
OrphanedSearchException

getUnvisitedDependendClasses

protected Set<String> getUnvisitedDependendClasses(Set<String> visitedClasses,
                                                   Map<String,Map<String,Set<Integer>>> dependencies,
                                                   Map<String,URL> allClassSources)
                                            throws OrphanedSearchException
Returns all classnames that are directly referenced by the visited classes but not yet contained.

Parameters:
visitedClasses -
dv - the dependencies to use
allClassSources - a map containing all classnames for which java source files are available
Returns:
Set containing class names
Throws:
OrphanedSearchException

getUnallowedDependencies

public Map<String,Map<String,ClassDependency>> getUnallowedDependencies(Map<String,Map<String,Set<Integer>>> dependencies)
                                                                 throws OverlappingModulesDefinitionException
Returns a map containing the dependencies (from class, to class) that are not allowed by the rules.

Parameters:
xcp - the configuration to use
Returns:
Throws:
OverlappingModulesDefinitionException

isUnallowedDependency

public boolean isUnallowedDependency(String fromClass,
                                     String toClass)
                              throws OverlappingModulesDefinitionException
Returns true if the dependency from fromClass to toClass is not allowed, otherwise false.

Parameters:
fromClass -
toClass -
Returns:
Throws:
OverlappingModulesDefinitionException

isUnallowedModuleDependency

public boolean isUnallowedModuleDependency(String fromModule,
                                           String toModule)
Returns true if the dependency from fromModule to toModule is not allowed, otherwise false.

Parameters:
fromModule -
toModule -
Returns:

getUnspecifiedPackages

public Set<String> getUnspecifiedPackages(Map<String,Map<String,Set<Integer>>> dependencies)
                                   throws OverlappingModulesDefinitionException
Returns a list of packages that are not assigned to a module in the given configuration.

Parameters:
xcp -
Returns:
Throws:
OverlappingModulesDefinitionException

getModelTree

public ModelTree getModelTree(DependencyVisitor dv)
                       throws OverlappingModulesDefinitionException
Builds a model that contains all dependency information that was retrieved from the class files. It can be used for displaying the dependencies in a tree view.

Parameters:
dv -
Returns:
Throws:
OverlappingModulesDefinitionException

updateModelTree

public void updateModelTree(ModelTree mt,
                            File classFile)
                     throws OverlappingModulesDefinitionException,
                            FileNotFoundException,
                            IOException
Updates the given modeltree by replacing all information of the given classFile with new information.

Parameters:
mt -
dv -
classFile -
Throws:
OverlappingModulesDefinitionException
IOException
FileNotFoundException

isUnallowedDependency

public boolean isUnallowedDependency(ModuleNode sourceModule,
                                     ModuleNode destModule)
Returns true if the module sourceModule may access destModule.

Parameters:
sourceModule -
destModule -
Returns:

cumulateDependencyViolations

public void cumulateDependencyViolations(ModelTree mt)
Recalculates the violations state of all nodes of the tree that contain children (e.g. packages and modules).

Parameters:
ModelTree - the tree that should be recalculated

createModel

public TreeNode createModel(ClassNode node,
                            ModelTree treemodel,
                            DependenciesTreeModel modelToUpdate)
Creates a dependency tree model for the given node of the given ModelTree.

Parameters:
node -
treemodel -
xmlconf - the configuration used to determine which dependencies are allowed
Returns:

createIncomingModel

public TreeNode createIncomingModel(ClassNode node,
                                    ModelTree treemodel,
                                    DependenciesTreeModel modelToUpdate)
Creates a dependency tree model for the given node of the given ModelTree.

Parameters:
node -
treemodel -
xmlconf - the configuration used to determine which dependencies are allowed
Returns:

addEntryClass

public void addEntryClass(String entryClass)
Adds a new entry class. An entry class is a class where the program can start (e.g. a class that contains a main method, an Applet class or a servlet). It is used to detect orphaned classes.

Parameters:
entryClass -

addModuleDependency

public void addModuleDependency(String moduleName,
                                TreeSet<String> name)
Adds dependencies from a module to other modules.

Parameters:
moduleName -
name -

addClassSource

public void addClassSource(ClassSource source)
Adds a new ClassSource.

Parameters:
source -


Copyright © 2007. All Rights Reserved.