Package com.thoughtworks.qdox.library
Class AbstractClassLibrary
- java.lang.Object
-
- com.thoughtworks.qdox.library.AbstractClassLibrary
-
- All Implemented Interfaces:
ClassLibrary
,java.io.Serializable
- Direct Known Subclasses:
ClassLoaderLibrary
,ClassNameLibrary
,SourceLibrary
public abstract class AbstractClassLibrary extends java.lang.Object implements ClassLibrary
A ClassLibrary can be compared with a java classloader. Its main task is to serve JavaClasses based on the Fully Qualified Name. AbstractClassLibraries hold a reference a parent library, in which way they can be chained. Besides that it contains a context only for this library.- Since:
- 2.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractClassLibrary()
constructor for root ClassLibraryAbstractClassLibrary(AbstractClassLibrary parent)
constructor for chained ClassLibrary
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract boolean
containsClassReference(java.lang.String name)
This method is used to detect if there's a match with this classname.JavaClass
getJavaClass(java.lang.String name)
First checks if there's a JavaClass available in the private context by this name.JavaClass
getJavaClass(java.lang.String name, boolean createStub)
Try to retrieve the JavaClass by the (binary) name.java.util.Collection<JavaClass>
getJavaClasses()
Get all the classes of the currentAbstractClassLibrary
.protected java.util.Collection<JavaClass>
getJavaClasses(com.thoughtworks.qdox.library.AbstractClassLibrary.ClassLibraryFilter filter)
Subclasses can call this method to gather all JavaClass object, including those from the parent.java.util.Collection<JavaModule>
getJavaModules()
JavaPackage
getJavaPackage(java.lang.String name)
Get the JavaPackage or null if it's not possiblejava.util.Collection<JavaPackage>
getJavaPackages()
Get all packages of the currentAbstractClassLibrary
.protected java.util.Collection<JavaPackage>
getJavaPackages(com.thoughtworks.qdox.library.AbstractClassLibrary.ClassLibraryFilter filter)
java.util.Collection<JavaSource>
getJavaSources()
Return all JavaSources of the current library.protected java.util.Collection<JavaSource>
getJavaSources(com.thoughtworks.qdox.library.AbstractClassLibrary.ClassLibraryFilter filter)
protected Builder
getModelBuilder()
If there's a modelBuilderFactory available, ask it for a new instance.protected Builder
getModelBuilder(java.net.URL url)
protected ModelBuilderFactory
getModelBuilderFactory()
protected ModelWriterFactory
getModelWriterFactory()
boolean
hasClassReference(java.lang.String name)
First checks if the context already has a JavaClass with this name.protected abstract JavaClass
resolveJavaClass(java.lang.String name)
The implementation should check it's sources to see if it can build a JavaClass Model If not, just return null; Once found it will be mapped, so there's no need to keep a reference to this object.protected abstract JavaPackage
resolveJavaPackage(java.lang.String name)
void
setModelBuilderFactory(ModelBuilderFactory factory)
Set the ModelBuilderFactory for this classLibrary.void
setModelWriterFactory(ModelWriterFactory factory)
Set the ModelWriterFactory for this class.
-
-
-
Constructor Detail
-
AbstractClassLibrary
public AbstractClassLibrary()
constructor for root ClassLibrary
-
AbstractClassLibrary
public AbstractClassLibrary(AbstractClassLibrary parent)
constructor for chained ClassLibrary- Parameters:
parent
- the parent library
-
-
Method Detail
-
getJavaModules
public java.util.Collection<JavaModule> getJavaModules()
- Specified by:
getJavaModules
in interfaceClassLibrary
-
getJavaClass
public final JavaClass getJavaClass(java.lang.String name)
First checks if there's a JavaClass available in the private context by this name. Otherwise try to resolve it by the concrete class. If there's still no JavaClass, ask the parent (if available) to resolve it.- Specified by:
getJavaClass
in interfaceClassLibrary
- Parameters:
name
- the binary name of the class- Returns:
- the JavaClass matching the name, otherwise
null
-
getJavaClass
public final JavaClass getJavaClass(java.lang.String name, boolean createStub)
Description copied from interface:ClassLibrary
Try to retrieve the JavaClass by the (binary) name. If the JavaClss doesn't exist and createStub istrue
make a stub, otherwise returnnull
- Specified by:
getJavaClass
in interfaceClassLibrary
- Parameters:
name
- the name of the classcreateStub
- force creation of a stub if the class can't be found- Returns:
- the JavaClass, might be
null
depending on the value of createStub.
-
resolveJavaClass
protected abstract JavaClass resolveJavaClass(java.lang.String name)
The implementation should check it's sources to see if it can build a JavaClass Model If not, just return null; Once found it will be mapped, so there's no need to keep a reference to this object.- Parameters:
name
- the fully qualified name- Returns:
- the resolved JavaClass, otherwise
null
-
getJavaSources
public java.util.Collection<JavaSource> getJavaSources()
Description copied from interface:ClassLibrary
Return all JavaSources of the current library. It's up to the library to decide if also collects JavaSources from it's ancestors- Specified by:
getJavaSources
in interfaceClassLibrary
- Returns:
- all JavaSources as a List, never
null
-
getJavaSources
protected final java.util.Collection<JavaSource> getJavaSources(com.thoughtworks.qdox.library.AbstractClassLibrary.ClassLibraryFilter filter)
- Parameters:
filter
- the classlibrary filter- Returns:
- JavaSources matching the filter
-
getJavaClasses
public java.util.Collection<JavaClass> getJavaClasses()
Get all the classes of the currentAbstractClassLibrary
. Subclasses can overwrite this method by including the following codepublic List<JavaClass> getClasses() { return getJavaClasses( new ClassLibraryFilter() { public boolean accept( AbstractClassLibrary classLibrary ) { return true; } }); }
This example would return all createdJavaClass
objects, including those from the classloaders.- Specified by:
getJavaClasses
in interfaceClassLibrary
- Returns:
- all JavaClasses of this ClassLibrary
-
getJavaClasses
protected final java.util.Collection<JavaClass> getJavaClasses(com.thoughtworks.qdox.library.AbstractClassLibrary.ClassLibraryFilter filter)
Subclasses can call this method to gather all JavaClass object, including those from the parent.- Parameters:
filter
- the classlibrary filter- Returns:
- JavaClasses matching the filter
-
getJavaPackages
public java.util.Collection<JavaPackage> getJavaPackages()
Get all packages of the currentAbstractClassLibrary
. Subclasses can overwrite this method by including the following codepublic List<JavaPackage> getJavaPackages() { return getJavaPackages( new ClassLibraryFilter() { public boolean accept( AbstractClassLibrary classLibrary ) { return true; } }); }
This example would return all createdJavaPackage
objects, including those from the classloaders.- Specified by:
getJavaPackages
in interfaceClassLibrary
- Returns:
- all JavaPackages of this ClassLibrary
-
getJavaPackage
public final JavaPackage getJavaPackage(java.lang.String name)
Description copied from interface:ClassLibrary
Get the JavaPackage or null if it's not possible- Specified by:
getJavaPackage
in interfaceClassLibrary
- Parameters:
name
- the fully qualified name- Returns:
- the JavaPackage matching the name, otherwise
null
-
resolveJavaPackage
protected abstract JavaPackage resolveJavaPackage(java.lang.String name)
-
getJavaPackages
protected final java.util.Collection<JavaPackage> getJavaPackages(com.thoughtworks.qdox.library.AbstractClassLibrary.ClassLibraryFilter filter)
-
hasClassReference
public boolean hasClassReference(java.lang.String name)
First checks if the context already has a JavaClass with this name. If not, find out if this classlibrary is able to build a model for this class Otherwise ask the parent if it could build a JavaClass.- Specified by:
hasClassReference
in interfaceClassLibrary
- Parameters:
name
- the fully qualified name- Returns:
true
if there is a reference, otherwisefalse
-
containsClassReference
protected abstract boolean containsClassReference(java.lang.String name)
This method is used to detect if there's a match with this classname. The name could be constructed based on imports and inner class paths.- Parameters:
name
- the fully qualified name of the class- Returns:
- true if this ClassLibrary has a reference to this class.
-
setModelBuilderFactory
public final void setModelBuilderFactory(ModelBuilderFactory factory)
Set the ModelBuilderFactory for this classLibrary.- Parameters:
factory
- the model builder factory
-
setModelWriterFactory
public final void setModelWriterFactory(ModelWriterFactory factory)
Set the ModelWriterFactory for this class.- Parameters:
factory
- the model writer factory
-
getModelWriterFactory
protected final ModelWriterFactory getModelWriterFactory()
-
getModelBuilderFactory
protected final ModelBuilderFactory getModelBuilderFactory()
-
getModelBuilder
protected Builder getModelBuilder()
If there's a modelBuilderFactory available, ask it for a new instance. Otherwise, return a default ModelBuilder. In both cases, pass this library as argument.- Returns:
- a new instance of a ModelBuilder, never
null
-
getModelBuilder
protected Builder getModelBuilder(java.net.URL url)
-
-