Package org.jibx.binding.model
Class ClassHierarchyContext
- java.lang.Object
-
- org.jibx.binding.model.ClassHierarchyContext
-
public class ClassHierarchyContext extends java.lang.Object
Context for components using a hierarchy of definitions based on class type. This is used to track conversion definitions in the form of format and template elements. The access methods take the different levels of nesting into account, automatically delegating to the containing context (if defined) when a lookup fails.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashSet
m_compatibleTypeSet
Set of compatible type names.private java.util.HashMap
m_nameToComponentMap
Map from format names toString
conversions (lazy create).private ClassHierarchyContext
m_outerContext
Link to containing context.private java.util.HashMap
m_typeToComponentMap
Map from type name to binding component.
-
Constructor Summary
Constructors Modifier Constructor Description protected
ClassHierarchyContext(ClassHierarchyContext outer)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
accumulateInterfaces(IClass clas, java.util.Set intfset)
Accumulate all the interfaces implemented (both directly and indirectly) by a class.void
addNamedComponent(java.lang.String label, ElementBase comp, ValidationContext vctx)
Add named component to set defined at this level.void
addTypedComponent(IClass clas, ElementBase comp, ValidationContext vctx)
Add typed component to set defined at this level.ClassHierarchyContext
getContaining()
Get containing context.ElementBase
getMostSpecificComponent(IClass clas)
Get best binding component for class.ElementBase
getNamedComponent(java.lang.String name)
Get named binding component definition.ElementBase
getSpecificComponent(java.lang.String name)
Get specific binding component for type.boolean
isCompatibleType(IClass clas)
Checks if a class is compatible with one or more components.
-
-
-
Field Detail
-
m_outerContext
private final ClassHierarchyContext m_outerContext
Link to containing context.
-
m_typeToComponentMap
private java.util.HashMap m_typeToComponentMap
Map from type name to binding component.
-
m_compatibleTypeSet
private java.util.HashSet m_compatibleTypeSet
Set of compatible type names.
-
m_nameToComponentMap
private java.util.HashMap m_nameToComponentMap
Map from format names toString
conversions (lazy create).
-
-
Constructor Detail
-
ClassHierarchyContext
protected ClassHierarchyContext(ClassHierarchyContext outer)
Constructor.- Parameters:
outer
- containing context (null
if at root of tree)
-
-
Method Detail
-
getContaining
public ClassHierarchyContext getContaining()
Get containing context.- Returns:
- containing context information (
null
if at root of tree)
-
accumulateInterfaces
private void accumulateInterfaces(IClass clas, java.util.Set intfset)
Accumulate all the interfaces implemented (both directly and indirectly) by a class.- Parameters:
clas
-intfset
- set of interfaces
-
addTypedComponent
public void addTypedComponent(IClass clas, ElementBase comp, ValidationContext vctx)
Add typed component to set defined at this level. This associates the component with the type for class hierarchy-based lookups.- Parameters:
clas
- class information to be associated with componentcomp
- definition component to be addedvctx
- validation context in use
-
addNamedComponent
public void addNamedComponent(java.lang.String label, ElementBase comp, ValidationContext vctx)
Add named component to set defined at this level. TODO: Make this use qname instead of text- Parameters:
label
- name to be associated with componentcomp
- definition component to be addedvctx
- validation context in use
-
getSpecificComponent
public ElementBase getSpecificComponent(java.lang.String name)
Get specific binding component for type. Looks for an exact match on the type name, checking the containing definitions if a matching component is not found at this level.- Parameters:
name
- fully qualified class name to be converted- Returns:
- binding component for class, or
null
if not found
-
getNamedComponent
public ElementBase getNamedComponent(java.lang.String name)
Get named binding component definition. Finds the component with the supplied name, checking the containing definitions if the component is not found at this level.- Parameters:
name
- component name to be found- Returns:
- binding component with name, or
null
if not found
-
getMostSpecificComponent
public ElementBase getMostSpecificComponent(IClass clas)
Get best binding component for class. Finds the component based on a fully qualified class name. If a specific component for the actual class is not found (either in this or a containing level) this returns the most specific superclass component.- Parameters:
clas
- information for target class- Returns:
- binding component definition for class, or
null
if none found
-
isCompatibleType
public boolean isCompatibleType(IClass clas)
Checks if a class is compatible with one or more components. If a specific component for the actual class is not found (either in this or a containing level) this checks for components that handle subclasses or implementations of the class.- Parameters:
clas
- information for target class- Returns:
true
if compatible type,false
if not
-
-