org.pf.tools.cda.base.model
Class ClassPackage

java.lang.Object
  extended by org.pf.tools.cda.base.model.AModelObject
      extended by org.pf.tools.cda.base.model.AAnalyzableElement
          extended by org.pf.tools.cda.base.model.ClassPackage
All Implemented Interfaces:
java.lang.Comparable, org.pf.bif.lifecycle.IReleasable, IAnalyzableElement, IClassContainingElement, IStringRepresentation, IExplorableElement, IExplorableElementVisiting, IExplorationModelObject, INamespace, IObjectProperties

public class ClassPackage
extends AAnalyzableElement
implements INamespace, IClassContainingElement, IStringRepresentation

Represents a Java package that contains classes.

Version:
1.5
Author:
Manfred Duchrow

Field Summary
static ClassPackage[] EMPTY_ARRAY
           
 
Fields inherited from class org.pf.tools.cda.base.model.AModelObject
EMPTY_MODEL_OBJECT_ARRAY
 
Fields inherited from interface org.pfsw.odem.INamespace
EMPTY_NAMESPACE_ARRAY
 
Fields inherited from interface org.pf.tools.cda.base.model.IAnalyzableElement
EMPTY_BASE_ARRAY
 
Constructor Summary
ClassPackage(java.lang.String packageName, GenericClassContainer packageContainer)
          Initialize the new instance with a name.
 
Method Summary
 boolean accept(IExplorableElementVisitor visitor)
          Implementation of the visitor pattern (GOF) for all derived interfaces if IExplorableElement.
 boolean acceptNamespaces(INamespacesVisitor visitor)
          Implementation of the visitor pattern (GOF).
 boolean acceptTypes(ITypesVisitor visitor)
          Iterates over all contained IType objects and invokes the visitor's callback method using the types as parameter.
 void addClass(ClassInformation classInfo)
          Add the given class information to the package.
 boolean canHaveDependencies()
          Returns if this object potentially has dependencies to other objects.
static ClassPackage[] collectionToArray(java.util.Collection coll)
          Convert the given collection to a ClassPackage array
 ClassInformation createClassInfo(java.lang.String className)
          Creates a new class info with the given class name and adds it to the package.
 boolean equals(java.lang.Object obj)
          Returns true if the given object equals this object
 ClassInformation findClassInfo(java.lang.String className)
          Returns the classInfo with the given name if it is member or this package.
 ClassInformation findOrCreateClassInfo(java.lang.String className)
          Searches for the class info in this container and returns it if found.
 ClassInformation[] getAllContainedClasses()
          Returns all classes that are contained in this element or any of its structural sub-elements.
 AnalyzableElementType getAnalyzableElementType()
          Returns the type of the analyzable element.
 int getChildCount()
          Returns the current number of children.
 AModelObject[] getChildren()
          Returns the children
 ClassInformation[] getClassInfos()
          Returns the class information of all classes found in this package.
 GenericClassContainer getContainer()
          Returns the container this package resides in
 java.lang.String getContainerName()
          Returns the name of the container the package was found in
 IExplorationContext getContext()
          Returns the context of this object
 ClassPackage[] getDirectReferredPackages()
          Returns all packages this package directly depends on
 java.lang.String getName()
          Returns the name
 int getNumberOfContainedClasses()
          Returns the number of classes in this package
 int getNumberOfDirectReferredPackages()
          Returns the number of packages this package directly depends on.
 ClassFileVersion getRequiredClassFileVersion()
          Returns the highest class file version that one of the contained classes is based on.
 java.lang.String getStringRepresentation()
          Returns the package name
 java.util.Collection<IType> getTypes()
          Returns all types in this namespace.
 Workset getWorkset()
          Returns the workset this element is included in
 int hashCode()
          Returns the hash code of this object
 boolean isDefaultPackage()
          Returns true if this package represents the default package (i.e "")
 boolean knowsContainer()
          Returns true, if the package "knows" in which container it was found
 boolean notFound()
          Returns true, if the package has not been found in any container
 boolean processClassInformationObjects(java.util.Collection<ClassInformation> collection, IClassInformationProcessor processor)
          Calls the given processor for each contained class info object and adds all class info objects that the processor wants (i.e. matches) to the given collection.
 boolean refersTo(IAnalyzableElement analyzableElement)
          Returns true if any of the directly referred packages is identical to the given one.
 void release()
           
 java.lang.String toString()
           
 
Methods inherited from class org.pf.tools.cda.base.model.AAnalyzableElement
canBeAnalyzedForDependencies
 
Methods inherited from class org.pf.tools.cda.base.model.AModelObject
apply, compareTo, countAllElementsRecursivly, getNumberOfAncestors, getProperty, getPropertyNames, setProperty
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.pfsw.odem.IObjectProperties
getProperty, getPropertyNames, setProperty
 

Field Detail

EMPTY_ARRAY

public static final ClassPackage[] EMPTY_ARRAY
Constructor Detail

ClassPackage

public ClassPackage(java.lang.String packageName,
                    GenericClassContainer packageContainer)
Initialize the new instance with a name.

Parameters:
packageName - A valid Java package name (must not be null)
packageContainer - The classpath element that contains the package (must not be null)
Throws:
java.lang.IllegalArgumentException - If any of the arguments is null
Method Detail

getName

public java.lang.String getName()
Description copied from class: AModelObject
Returns the name

Specified by:
getName in interface IExplorationModelObject
Specified by:
getName in class AModelObject

getContainer

public GenericClassContainer getContainer()
Returns the container this package resides in


collectionToArray

public static ClassPackage[] collectionToArray(java.util.Collection coll)
Convert the given collection to a ClassPackage array


getStringRepresentation

public java.lang.String getStringRepresentation()
Returns the package name

Specified by:
getStringRepresentation in interface IStringRepresentation

canHaveDependencies

public boolean canHaveDependencies()
Returns if this object potentially has dependencies to other objects. That is, it can be analyzed by CDA regarding its dependencies.

Overrides:
canHaveDependencies in class AModelObject

addClass

public void addClass(ClassInformation classInfo)
Add the given class information to the package. The class info is only added if it realy belongs to this package (i.e. the package name of the class is equal to this package's name)


getClassInfos

public ClassInformation[] getClassInfos()
Returns the class information of all classes found in this package. Never returns null.


getTypes

public java.util.Collection<IType> getTypes()
Returns all types in this namespace. This method never returns null. If no type is contained in the namespace an empty array will be returned.

Specified by:
getTypes in interface INamespace

getContainerName

public java.lang.String getContainerName()
Returns the name of the container the package was found in


getDirectReferredPackages

public ClassPackage[] getDirectReferredPackages()
Returns all packages this package directly depends on


getNumberOfDirectReferredPackages

public int getNumberOfDirectReferredPackages()
Returns the number of packages this package directly depends on.


refersTo

public boolean refersTo(IAnalyzableElement analyzableElement)
Returns true if any of the directly referred packages is identical to the given one. That means, this package depends on the given package.

Specified by:
refersTo in interface IAnalyzableElement
Parameters:
analyzableElement - The package to check if this package refers to it

equals

public boolean equals(java.lang.Object obj)
Returns true if the given object equals this object

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns the hash code of this object

Overrides:
hashCode in class java.lang.Object

isDefaultPackage

public boolean isDefaultPackage()
Returns true if this package represents the default package (i.e "")


knowsContainer

public boolean knowsContainer()
Returns true, if the package "knows" in which container it was found


notFound

public boolean notFound()
Returns true, if the package has not been found in any container


findClassInfo

public ClassInformation findClassInfo(java.lang.String className)
Returns the classInfo with the given name if it is member or this package. Returns null if not found.


findOrCreateClassInfo

public ClassInformation findOrCreateClassInfo(java.lang.String className)
Searches for the class info in this container and returns it if found. If not found it creates a new class info object and adds it to this container. The new class info will then be returned.


createClassInfo

public ClassInformation createClassInfo(java.lang.String className)
Creates a new class info with the given class name and adds it to the package.


getNumberOfContainedClasses

public int getNumberOfContainedClasses()
Returns the number of classes in this package

Specified by:
getNumberOfContainedClasses in interface IClassContainingElement

getAllContainedClasses

public ClassInformation[] getAllContainedClasses()
Returns all classes that are contained in this element or any of its structural sub-elements. If no classes are contained, an empty array will be returned.

Specified by:
getAllContainedClasses in interface IAnalyzableElement

processClassInformationObjects

public boolean processClassInformationObjects(java.util.Collection<ClassInformation> collection,
                                              IClassInformationProcessor processor)
Calls the given processor for each contained class info object and adds all class info objects that the processor wants (i.e. matches) to the given collection.

Parameters:
collection - The collection to which the matching objects will be added.
processor - The processor that decides whether or not an object must be added.
Returns:
true if processing should continue, otherwise false.

getRequiredClassFileVersion

public ClassFileVersion getRequiredClassFileVersion()
Returns the highest class file version that one of the contained classes is based on. Returns null if no class can be found in this package.

Specified by:
getRequiredClassFileVersion in interface IClassContainingElement

accept

public boolean accept(IExplorableElementVisitor visitor)
Implementation of the visitor pattern (GOF) for all derived interfaces if IExplorableElement.

Specified by:
accept in interface IExplorableElementVisiting
Parameters:
visitor - The implementor of the vistor interface to be called by this method
Returns:
true if processing should be continued, otherwise false

acceptNamespaces

public boolean acceptNamespaces(INamespacesVisitor visitor)
Implementation of the visitor pattern (GOF). Invokes the visitor's callback method using this namespaces as parameter.

Specified by:
acceptNamespaces in interface INamespace
Parameters:
visitor - The implementor of the vistor interface to be called by this method
Returns:
true if processing should be continued, otherwise false

acceptTypes

public boolean acceptTypes(ITypesVisitor visitor)
Iterates over all contained IType objects and invokes the visitor's callback method using the types as parameter.

Specified by:
acceptTypes in interface IExplorableElementVisiting
Parameters:
visitor - The implementor of the vistor interface to be called by this method
Returns:
true if processing should be continued, otherwise false

getAnalyzableElementType

public AnalyzableElementType getAnalyzableElementType()
Returns the type of the analyzable element.

Specified by:
getAnalyzableElementType in interface IAnalyzableElement

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

release

public void release()
Specified by:
release in interface org.pf.bif.lifecycle.IReleasable

getWorkset

public Workset getWorkset()
Returns the workset this element is included in

Specified by:
getWorkset in interface IAnalyzableElement
Specified by:
getWorkset in class AModelObject

getChildCount

public int getChildCount()
Returns the current number of children.

Specified by:
getChildCount in class AModelObject

getChildren

public AModelObject[] getChildren()
Returns the children

Specified by:
getChildren in class AModelObject
Returns:
The children or an empty array (never null)

getContext

public IExplorationContext getContext()
Returns the context of this object

Specified by:
getContext in interface IExplorationModelObject