public class ClassDefEntity extends AbstractEntity implements ClassDef
Extends its reponsibilities as a class definition by implementing runtime handling of class libraries and implementation chains.
To protect against a loop in the implementation chain and to avoid forward
references in exported metadata, each instance is assigned a 'level' (see
adjustLevel()
).
Modifier and Type | Class and Description |
---|---|
static class |
ClassDefEntity.Builder
Builder.
|
static class |
ClassDefEntity.Undefined
Undefined.
|
ClassDef.Loader
Modifier and Type | Field and Description |
---|---|
static String |
ELEMENT_NAME
ClassDef element name.
|
static String |
ENTITY_PREFIX
ClassDef entity prefix.
|
UUID_COMPARATOR
Modifier and Type | Method and Description |
---|---|
void |
addImplemented(ClassDefEntity classDef)
Adds an other class definition entity as an implemented interface.
|
void |
adjustLevel()
Adjust the level of this instance's dependencies.
|
int |
compareTo(Entity other)
Implements Comparable.
|
ClassDefEntity |
copy()
Creates a copy of this entity.
|
<T> T |
createInstance(Class<T> expectedClass)
Creates an instance of the class.
|
boolean |
equals(Object other)
|
Optional<ClassLibEntity> |
getClassLib()
Gets the class library.
|
String |
getClassName()
Gets the referenced class name.
|
String |
getElementName()
Gets the entity element name.
|
List<ClassDefEntity> |
getImplemented()
Gets the List of implemented class definitions.
|
Class<?> |
getInstanceClass()
Gets the class of instances created by this class definition.
|
Class<?> |
getInstanceClass(Optional<ClassLoader> classLoader)
Gets the class of instances created by this class definition.
|
int |
getLevel()
Gets this instance's level.
|
String |
getMember()
Gets the package member name for the class.
|
String |
getPackageName()
Gets the package name for the class.
|
String |
getPrefix()
Gets the class prefix.
|
String |
getReferenceName()
Gets the entity reference name.
|
int |
hashCode() |
boolean |
is(Class<?> classObject)
Asks if this instance implements an interface.
|
boolean |
is(String className)
Asks if this instance implements an interface.
|
boolean |
isDefined()
Asks if this instance is defined.
|
boolean |
isLoaded()
Asks if the class has been loaded.
|
static ClassDefEntity.Builder |
newBuilder()
Returns a new builder.
|
String |
toString()
Returns a string representation of this.
|
getAttributes, getName, getNameInUpperCase, getThisLogger, getUUID, setName, setUUID
public static final String ELEMENT_NAME
public static final String ENTITY_PREFIX
@Nonnull @CheckReturnValue public static ClassDefEntity.Builder newBuilder()
public final void addImplemented(@Nonnull ClassDefEntity classDef)
classDef
- The class definition entity to add.public final void adjustLevel() throws TopologicalErrorException
This implementation uses a reverse level order: an instance without any implementors is at level 0; when an instance is implemented, its level is made negative relative to the implementor. A strictly positive level value indicates that the level has not been adjusted yet.
TopologicalErrorException
- When a recursive reference is found.public final int compareTo(Entity other)
compareTo
in interface Comparable<Entity>
compareTo
in class AbstractEntity
other
- An other Entity.public ClassDefEntity copy()
public <T> T createInstance(Class<T> expectedClass)
Uses the class returned by ClassDef.getInstanceClass()
, thus
triggering the class loading if needed. If either the class loading or
the instance creation fails, an error message is logged and a null value
is returned.
createInstance
in interface ClassDef
T
- The type of the returned value.expectedClass
- The expected class.public final boolean equals(Object other)
For two Entity
to be equal, they must at least be instances of
the same class, have the same UUID
and name.
For two class definition eneity to be equal, they must reference the same class library, have the same class name and implement the same class definitions.
equals
in class AbstractEntity
@Nonnull @CheckReturnValue public final Optional<ClassLibEntity> getClassLib()
public String getClassName()
getClassName
in interface ClassDef
public final String getElementName()
The entity element is used to in the generation of the entity URI.
getElementName
in interface Entity
@Nonnull @CheckReturnValue public final List<ClassDefEntity> getImplemented()
public Class<?> getInstanceClass()
If the class loading fails, an error message is logged and a null value is returned.
Before triggering the class loading, makes sure that the class library is known to the context class loader.
getInstanceClass
in interface ClassDef
public final Class<?> getInstanceClass(Optional<ClassLoader> classLoader)
If the class loading fails, an error message is logged and a null value is returned.
getInstanceClass
in interface ClassDef
classLoader
- The optional class loader to use.@CheckReturnValue public final int getLevel()
The level helps control the declaration order to avoid forward references.
public String getMember()
public String getPackageName()
getPackageName
in interface ClassDef
public final String getPrefix()
Each concrete entity subclass has its own prefix which will be the same for all its instances. This prefix is used to avoid name collision between different classes in a common registry.
public String getReferenceName()
getReferenceName
in interface Entity
public final int hashCode()
hashCode
in class AbstractEntity
@CheckReturnValue public final boolean is(@Nonnull Class<?> classObject) throws UndefinedEntityException
classObject
- A class object.UndefinedEntityException
- When the interface is undefined.@CheckReturnValue public final boolean is(@Nonnull String className) throws UndefinedEntityException
className
- The name of the class or interface.UndefinedEntityException
- When the interface is undefined.@CheckReturnValue public boolean isDefined()
public boolean isLoaded()
public final String toString()
toString
in class AbstractEntity
Copyright © 2003-2019 Serge Brisson. All Rights Reserved.