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
Information for a class to be included in code generated from schema.
- Author:
- Dennis M. Sosnoski
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classInformation for a data structure component of a class definition.protected static classInformation for a leaf node of the data structure tree.protected static classInformation for an interior node of the data structure tree. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected final StringBase class name (for use when generating separate classes for nested structures).private ClassBuilderBuilder for class.protected final ClassDecorator[]Decorators to be called in order during class code generation.private booleanClass generated flag.protected final BindingHolderHolder for class binding definition.protected final ImportsTrackerTracker for imports.protected final LazyListHolders for inner classes defined within this class (nullif an inner class).protected StringClass used for initializing list instances.private final StringSimple class name.protected final NameConverterName conversion handler.protected UniqueNameSetValue names used in class.protected final ClassHolderContaining class (nullif not an inner class).protected final PackageHolderPackage containing class.private SchemaCustomCustomizations for the schema containing the schema component matching this class.private TypeDataSuperclass to be extended as part of schema model (nullif none).private StringSuperclass name to be extended if extension not required by model (nullif none).protected final booleanUse inner classes for substructures flag.private static final SchemaDocumentationGeneratorSchema documentation generator.private static final LoggerLogger for class.private static final TransformerNull transformer used to output text form of documentation. -
Constructor Summary
ConstructorsModifierConstructorDescriptionClassHolder(String name, String base, PackageHolder pack, BindingHolder holder, NameConverter nconv, ClassDecorator[] decorators, boolean inner, boolean simple) Constructor.protectedClassHolder(String name, ClassHolder context, boolean simple) Constructor for creating a child inner class definition. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddField(FieldDeclaration field) Add separately-constructed field to this class definition.booleanAdd import for class.voidaddInterface(String interf) Add an interface to this class definition.voidaddMethod(MethodDeclaration method) Add separately-constructed method declaration to this class definition.voidaddType(TypeDeclaration type) Add separately-constructed inner class declaration to this class definition.voidbuildDataStructure(GroupItem group, BindingHolder bindhold) Convert an item structure to a class representation.private static StringbuildName(String name, PackageHolder pack) Build fully-qualified class nameprotected static Stringdescribe(ClassHolder.DataNode node) Describe the schema component associated with a node.protected StringextractDocumentation(AnnotatedBase element) Extract schema documentation from an element.protected voidfinishClass(ElementBase binding) Finish class construction.abstract voidgenerate(boolean verbose, SourceBuilder builder) Generate this class.protected voidgenerateInner(boolean verbose, SourceBuilder builder) Generate any inner classes of this class.protected ClassBuilderGet the builder for this class.FieldDeclaration[]Get the fields defined in this class.Get imports information.String[]Get the interfaces implemented by this class.MethodDeclaration[]Get the methods defined in this class.getName()Get simple name.Get containing class of inner class.Get containing package.Get the schema customization associated with root schema component matching this class.Get a sorted array of the field names and types defined in this class.Get base class to be extended.Get name of base class to be extended.getTypeName(String type) Get the name to be used for a type.protected voidImport the type associated with an item, if not directly accessibleprotected voidinitClass(boolean verbose, ClassBuilder builder, ClassHolder.ParentNode root) Initialize the class construction.booleanCheck if the class has been generated.booleanCheck if superclass is forced by schema model.voidsetListImplementation(String list) Set name of list implementation class to be used for initializing instances.voidsetSuperClass(TypeData sclas) Set superclass to be extended.voidsetSuperClassName(String base) Set name of base class to be extended.Methods inherited from class org.jibx.schema.codegen.TypeData
getBindingName, getFullName, isPregenerated, isSimpleValueMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jibx.schema.codegen.IClassHolder
getFullName
-
Field Details
-
COLLECTION_VARIABLE_TYPE
- See Also:
-
COLLECTION_VARIABLE_NAME
- See Also:
-
s_logger
private static final Logger s_loggerLogger for class. -
s_generator
Schema documentation generator. -
s_transformer
Null transformer used to output text form of documentation. -
m_name
Simple class name. -
m_superClass
Superclass to be extended as part of schema model (nullif none). -
m_superName
Superclass name to be extended if extension not required by model (nullif none). -
m_generated
private boolean m_generatedClass generated flag. -
m_classBuilder
Builder for class. -
m_schemaCustom
Customizations for the schema containing the schema component matching this class. -
m_package
Package containing class. -
m_holder
Holder for class binding definition. -
m_nameConverter
Name conversion handler. -
m_baseName
Base class name (for use when generating separate classes for nested structures). -
m_decorators
Decorators to be called in order during class code generation. -
m_useInnerClasses
protected final boolean m_useInnerClassesUse inner classes for substructures flag. -
m_inners
Holders for inner classes defined within this class (nullif an inner class). -
m_outerClass
Containing class (nullif not an inner class). -
m_importsTracker
Tracker for imports. -
m_listImplClass
Class used for initializing list instances. -
m_nameSet
Value names used in class.
-
-
Constructor Details
-
ClassHolder
public ClassHolder(String name, 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
Constructor for creating a child inner class definition.- Parameters:
name- class namecontext- parent classsimple- simple value flag
-
-
Method Details
-
buildName
Build fully-qualified class name- Parameters:
name- simple class namepack- package information- Returns:
- fully-qualified class name
-
getSchemaCustom
Get the schema customization associated with root schema component matching this class.- Returns:
- schema customization
-
extractDocumentation
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
nullif none
-
describe
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
Import the type associated with an item, if not directly accessible- Parameters:
value-
-
buildDataStructure
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
Get containing package.- Returns:
- package
-
getName
Get simple name.- Specified by:
getNamein interfaceIClassHolder- Returns:
- name
-
getOuterClass
Get containing class of inner class.- Specified by:
getOuterClassin interfaceIClassHolder- Returns:
- outer containing class, or
nullif not an inner class
-
getSuperClass
Get base class to be extended.- Returns:
- base (
nullif none)
-
setSuperClass
Set superclass to be extended.- Parameters:
sclas- (nullif none)
-
isSuperClassForced
public boolean isSuperClassForced()Check if superclass is forced by schema model.- Specified by:
isSuperClassForcedin interfaceIClassHolder- Returns:
trueif superclass forced,falseif not
-
getSuperClassName
Get name of base class to be extended.- Specified by:
getSuperClassNamein interfaceIClassHolder- Returns:
- base (
nullif none)
-
setSuperClassName
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:
setSuperClassNamein interfaceIClassHolder- Parameters:
base- fully-qualified class name of base class (nullif none)
-
setListImplementation
Set name of list implementation class to be used for initializing instances.- Specified by:
setListImplementationin 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:
trueif generated,falseif not
-
getBuilder
Get the builder for this class.- Returns:
- builder
-
getInterfaces
Get the interfaces implemented by this class.- Specified by:
getInterfacesin interfaceIClassHolder- Returns:
- interface names
-
getImports
Get imports information.- Returns:
- imports
-
getFields
public FieldDeclaration[] getFields()Get the fields defined in this class.- Specified by:
getFieldsin interfaceIClassHolder- Returns:
- fields
-
getMethods
public MethodDeclaration[] getMethods()Get the methods defined in this class.- Specified by:
getMethodsin interfaceIClassHolder- Returns:
- methods
-
addImport
Add import for class. If the requested import doesn't conflict with the current set it's added, otherwise it's ignored.- Specified by:
addImportin interfaceIClassHolder- Parameters:
fqname- fully qualified class name- Returns:
trueif added as import
-
getTypeName
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:
getTypeNamein interfaceIClassHolder- Parameters:
type- fully qualified class name- Returns:
- name
-
addInterface
Add an interface to this class definition.- Specified by:
addInterfacein interfaceIClassHolder- Parameters:
interf- interface type
-
addField
public void addField(FieldDeclaration field) Add separately-constructed field to this class definition.- Specified by:
addFieldin interfaceIClassHolder- Parameters:
field-
-
addMethod
public void addMethod(MethodDeclaration method) Add separately-constructed method declaration to this class definition.- Specified by:
addMethodin interfaceIClassHolder- Parameters:
method-
-
addType
public void addType(TypeDeclaration type) Add separately-constructed inner class declaration to this class definition.- Specified by:
addTypein interfaceIClassHolder- Parameters:
type-
-
getSortedFields
Get a sorted array of the field names and types defined in this class.- Returns:
- sorted pairs
-
initClass
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
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
Generate any inner classes of this class.- Parameters:
verbose-builder- class source file builder
-
generate
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
-