Package org.jibx.schema.codegen
Class ClassHolder
- java.lang.Object
-
- org.jibx.schema.codegen.TypeData
-
- org.jibx.schema.codegen.ClassHolder
-
- All Implemented Interfaces:
IClassHolder
- Direct Known Subclasses:
EnumerationClassHolder
,StructureClassHolder
public abstract class ClassHolder extends TypeData implements IClassHolder
Information for a class to be included in code generated from schema.- Author:
- Dennis M. Sosnoski
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ClassHolder.DataNode
Information for a data structure component of a class definition.protected static class
ClassHolder.LeafNode
Information for a leaf node of the data structure tree.protected static class
ClassHolder.ParentNode
Information for an interior node of the data structure tree.
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
COLLECTION_VARIABLE_NAME
protected static java.lang.String
COLLECTION_VARIABLE_TYPE
protected java.lang.String
m_baseName
Base class name (for use when generating separate classes for nested structures).private ClassBuilder
m_classBuilder
Builder for class.protected ClassDecorator[]
m_decorators
Decorators to be called in order during class code generation.private boolean
m_generated
Class generated flag.protected BindingHolder
m_holder
Holder for class binding definition.protected ImportsTracker
m_importsTracker
Tracker for imports.protected LazyList
m_inners
Holders for inner classes defined within this class (null
if an inner class).protected java.lang.String
m_listImplClass
Class used for initializing list instances.private java.lang.String
m_name
Simple class name.protected NameConverter
m_nameConverter
Name conversion handler.protected UniqueNameSet
m_nameSet
Value names used in class.protected ClassHolder
m_outerClass
Containing class (null
if not an inner class).protected PackageHolder
m_package
Package containing class.private SchemaCustom
m_schemaCustom
Customizations for the schema containing the schema component matching this class.private TypeData
m_superClass
Superclass to be extended as part of schema model (null
if none).private java.lang.String
m_superName
Superclass name to be extended if extension not required by model (null
if none).protected boolean
m_useInnerClasses
Use inner classes for substructures flag.private static SchemaDocumentationGenerator
s_generator
Schema documentation generator.private static Logger
s_logger
Logger for class.private static javax.xml.transform.Transformer
s_transformer
Null transformer used to output text form of documentation.
-
Constructor Summary
Constructors Modifier Constructor Description ClassHolder(java.lang.String name, java.lang.String base, PackageHolder pack, BindingHolder holder, NameConverter nconv, ClassDecorator[] decorators, boolean inner, boolean simple)
Constructor.protected
ClassHolder(java.lang.String name, ClassHolder context, boolean simple)
Constructor for creating a child inner class definition.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addField(FieldDeclaration field)
Add separately-constructed field to this class definition.boolean
addImport(java.lang.String fqname)
Add import for class.void
addInterface(java.lang.String interf)
Add an interface to this class definition.void
addMethod(MethodDeclaration method)
Add separately-constructed method declaration to this class definition.void
addType(TypeDeclaration type)
Add separately-constructed inner class declaration to this class definition.void
buildDataStructure(GroupItem group, BindingHolder bindhold)
Convert an item structure to a class representation.private static java.lang.String
buildName(java.lang.String name, PackageHolder pack)
Build fully-qualified class nameprotected static java.lang.String
describe(ClassHolder.DataNode node)
Describe the schema component associated with a node.protected java.lang.String
extractDocumentation(AnnotatedBase element)
Extract schema documentation from an element.protected void
finishClass(ElementBase binding)
Finish class construction.abstract void
generate(boolean verbose, SourceBuilder builder)
Generate this class.protected void
generateInner(boolean verbose, SourceBuilder builder)
Generate any inner classes of this class.protected ClassBuilder
getBuilder()
Get the builder for this class.FieldDeclaration[]
getFields()
Get the fields defined in this class.ImportsTracker
getImports()
Get imports information.java.lang.String[]
getInterfaces()
Get the interfaces implemented by this class.MethodDeclaration[]
getMethods()
Get the methods defined in this class.java.lang.String
getName()
Get simple name.IClassHolder
getOuterClass()
Get containing class of inner class.PackageHolder
getPackage()
Get containing package.SchemaCustom
getSchemaCustom()
Get the schema customization associated with root schema component matching this class.StringPair[]
getSortedFields()
Get a sorted array of the field names and types defined in this class.TypeData
getSuperClass()
Get base class to be extended.java.lang.String
getSuperClassName()
Get name of base class to be extended.java.lang.String
getTypeName(java.lang.String type)
Get the name to be used for a type.protected void
importValueType(ClassHolder.DataNode value)
Import the type associated with an item, if not directly accessibleprotected void
initClass(boolean verbose, ClassBuilder builder, ClassHolder.ParentNode root)
Initialize the class construction.boolean
isGenerated()
Check if the class has been generated.boolean
isSuperClassForced()
Check if superclass is forced by schema model.void
setListImplementation(java.lang.String list)
Set name of list implementation class to be used for initializing instances.void
setSuperClass(TypeData sclas)
Set superclass to be extended.void
setSuperClassName(java.lang.String base)
Set name of base class to be extended.-
Methods inherited from class org.jibx.schema.codegen.TypeData
getBindingName, getFullName, isPregenerated, isSimpleValue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jibx.schema.codegen.IClassHolder
getFullName
-
-
-
-
Field Detail
-
COLLECTION_VARIABLE_TYPE
protected static final java.lang.String COLLECTION_VARIABLE_TYPE
- See Also:
- Constant Field Values
-
COLLECTION_VARIABLE_NAME
protected static final java.lang.String COLLECTION_VARIABLE_NAME
- See Also:
- Constant Field Values
-
s_logger
private static final Logger s_logger
Logger for class.
-
s_generator
private static final SchemaDocumentationGenerator s_generator
Schema documentation generator.
-
s_transformer
private static final javax.xml.transform.Transformer s_transformer
Null transformer used to output text form of documentation.
-
m_name
private final java.lang.String m_name
Simple class name.
-
m_superClass
private TypeData m_superClass
Superclass to be extended as part of schema model (null
if none).
-
m_superName
private java.lang.String m_superName
Superclass name to be extended if extension not required by model (null
if none).
-
m_generated
private boolean m_generated
Class generated flag.
-
m_classBuilder
private ClassBuilder m_classBuilder
Builder for class.
-
m_schemaCustom
private SchemaCustom m_schemaCustom
Customizations for the schema containing the schema component matching this class.
-
m_package
protected final PackageHolder m_package
Package containing class.
-
m_holder
protected final BindingHolder m_holder
Holder for class binding definition.
-
m_nameConverter
protected final NameConverter m_nameConverter
Name conversion handler.
-
m_baseName
protected final java.lang.String m_baseName
Base class name (for use when generating separate classes for nested structures).
-
m_decorators
protected final ClassDecorator[] m_decorators
Decorators to be called in order during class code generation.
-
m_useInnerClasses
protected final boolean m_useInnerClasses
Use inner classes for substructures flag.
-
m_inners
protected final LazyList m_inners
Holders for inner classes defined within this class (null
if an inner class).
-
m_outerClass
protected final ClassHolder m_outerClass
Containing class (null
if not an inner class).
-
m_importsTracker
protected final ImportsTracker m_importsTracker
Tracker for imports.
-
m_listImplClass
protected java.lang.String m_listImplClass
Class used for initializing list instances.
-
m_nameSet
protected UniqueNameSet m_nameSet
Value names used in class.
-
-
Constructor Detail
-
ClassHolder
public ClassHolder(java.lang.String name, java.lang.String base, PackageHolder pack, BindingHolder holder, NameConverter nconv, ClassDecorator[] decorators, boolean inner, boolean simple)
Constructor.- Parameters:
name
- class namebase
- base class namepack
- package informationholder
- binding holdernconv
- name converterdecorators
- class decoratorsinner
- use inner classes for substructuressimple
- simple value flag
-
ClassHolder
protected ClassHolder(java.lang.String name, ClassHolder context, boolean simple)
Constructor for creating a child inner class definition.- Parameters:
name
- class namecontext
- parent classsimple
- simple value flag
-
-
Method Detail
-
buildName
private static java.lang.String buildName(java.lang.String name, PackageHolder pack)
Build fully-qualified class name- Parameters:
name
- simple class namepack
- package information- Returns:
- fully-qualified class name
-
getSchemaCustom
public SchemaCustom getSchemaCustom()
Get the schema customization associated with root schema component matching this class.- Returns:
- schema customization
-
extractDocumentation
protected java.lang.String extractDocumentation(AnnotatedBase element)
Extract schema documentation from an element. This just checks for an annotation element on the supplied element, and if found returns a text string consisting of the content of all documentation element(s). The returned documentation text is suitable for use as JavaDoc content, with any JavaDoc end sequences ('*' followed by '/') substituted with a space added.- Parameters:
element
-- Returns:
- content of documentation elements, or
null
if none
-
describe
protected static java.lang.String describe(ClassHolder.DataNode node)
Describe the schema component associated with a node. If the component for the supplied node is a named element or attribute, this just returns a combination of the name and type of that component. Otherwise, it moves up the node tree until it finds a named element or attribute, terminating if any parent has more than one child. If it can't find an element or attribute name but does find a named type, it uses that type as the name. If all else fails, it just returns the type of the highest level component found.- Parameters:
node
-- Returns:
- name
-
importValueType
protected void importValueType(ClassHolder.DataNode value)
Import the type associated with an item, if not directly accessible- Parameters:
value
-
-
buildDataStructure
public void buildDataStructure(GroupItem group, BindingHolder bindhold)
Convert an item structure to a class representation. Subclasses need to override this method for thie own handling, but should call the base class implementatino first to initialize the schema customization link.- Parameters:
group
- item groupbindhold
- associated binding definition holder
-
getPackage
public PackageHolder getPackage()
Get containing package.- Returns:
- package
-
getName
public java.lang.String getName()
Get simple name.- Specified by:
getName
in interfaceIClassHolder
- Returns:
- name
-
getOuterClass
public IClassHolder getOuterClass()
Get containing class of inner class.- Specified by:
getOuterClass
in interfaceIClassHolder
- Returns:
- outer containing class, or
null
if not an inner class
-
getSuperClass
public TypeData getSuperClass()
Get base class to be extended.- Returns:
- base (
null
if none)
-
setSuperClass
public void setSuperClass(TypeData sclas)
Set superclass to be extended.- Parameters:
sclas
- (null
if none)
-
isSuperClassForced
public boolean isSuperClassForced()
Check if superclass is forced by schema model.- Specified by:
isSuperClassForced
in interfaceIClassHolder
- Returns:
true
if superclass forced,false
if not
-
getSuperClassName
public java.lang.String getSuperClassName()
Get name of base class to be extended.- Specified by:
getSuperClassName
in interfaceIClassHolder
- Returns:
- base (
null
if none)
-
setSuperClassName
public void setSuperClassName(java.lang.String base)
Set name of base class to be extended. This method can only be used if a superclass has not been forced by the schema model. It is always safe to use this method ifgetSuperClassName()
returnsnull
.- Specified by:
setSuperClassName
in interfaceIClassHolder
- Parameters:
base
- fully-qualified class name of base class (null
if none)
-
setListImplementation
public void setListImplementation(java.lang.String list)
Set name of list implementation class to be used for initializing instances.- Specified by:
setListImplementation
in interfaceIClassHolder
- Parameters:
list
- fully-qualified class name of list implementation (non-null
)
-
isGenerated
public boolean isGenerated()
Check if the class has been generated. This should always be called before callinggenerate(boolean, SourceBuilder)
, in order to prevent multiple generation passes over the same class.- Returns:
true
if generated,false
if not
-
getBuilder
protected ClassBuilder getBuilder()
Get the builder for this class.- Returns:
- builder
-
getInterfaces
public java.lang.String[] getInterfaces()
Get the interfaces implemented by this class.- Specified by:
getInterfaces
in interfaceIClassHolder
- Returns:
- interface names
-
getImports
public ImportsTracker getImports()
Get imports information.- Returns:
- imports
-
getFields
public FieldDeclaration[] getFields()
Get the fields defined in this class.- Specified by:
getFields
in interfaceIClassHolder
- Returns:
- fields
-
getMethods
public MethodDeclaration[] getMethods()
Get the methods defined in this class.- Specified by:
getMethods
in interfaceIClassHolder
- Returns:
- methods
-
addImport
public boolean addImport(java.lang.String fqname)
Add import for class. If the requested import doesn't conflict with the current set it's added, otherwise it's ignored.- Specified by:
addImport
in interfaceIClassHolder
- Parameters:
fqname
- fully qualified class name- Returns:
true
if added as import
-
getTypeName
public java.lang.String getTypeName(java.lang.String type)
Get the name to be used for a type. If the type has been imported this returns the short form of the name; otherwise it just returns the fully-qualified name.- Specified by:
getTypeName
in interfaceIClassHolder
- Parameters:
type
- fully qualified class name- Returns:
- name
-
addInterface
public void addInterface(java.lang.String interf)
Add an interface to this class definition.- Specified by:
addInterface
in interfaceIClassHolder
- Parameters:
interf
- interface type
-
addField
public void addField(FieldDeclaration field)
Add separately-constructed field to this class definition.- Specified by:
addField
in interfaceIClassHolder
- Parameters:
field
-
-
addMethod
public void addMethod(MethodDeclaration method)
Add separately-constructed method declaration to this class definition.- Specified by:
addMethod
in interfaceIClassHolder
- Parameters:
method
-
-
addType
public void addType(TypeDeclaration type)
Add separately-constructed inner class declaration to this class definition.- Specified by:
addType
in interfaceIClassHolder
- Parameters:
type
-
-
getSortedFields
public StringPair[] getSortedFields()
Get a sorted array of the field names and types defined in this class.- Returns:
- sorted pairs
-
initClass
protected void initClass(boolean verbose, ClassBuilder builder, ClassHolder.ParentNode root)
Initialize the class construction. This is a support method for use by subclasses, which handles common setup including superclass generation.- Parameters:
verbose
-builder
-root
- data structure tree root node
-
finishClass
protected void finishClass(ElementBase binding)
Finish class construction. This is a support method for use by subclasses, which handles common completion processing- Parameters:
binding
- binding definition component for this class
-
generateInner
protected void generateInner(boolean verbose, SourceBuilder builder)
Generate any inner classes of this class.- Parameters:
verbose
-builder
- class source file builder
-
generate
public abstract void generate(boolean verbose, SourceBuilder builder)
Generate this class. Subclasses must implement this method to first do the appropriate setup and then callinitClass(boolean, ClassBuilder, ParentNode)
before doing their own code generation.- Parameters:
verbose
-builder
- class source file builder
-
-