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 classClassHolder.DataNodeInformation for a data structure component of a class definition.protected static classClassHolder.LeafNodeInformation for a leaf node of the data structure tree.protected static classClassHolder.ParentNodeInformation for an interior node of the data structure tree.
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringCOLLECTION_VARIABLE_NAMEprotected static java.lang.StringCOLLECTION_VARIABLE_TYPEprotected java.lang.Stringm_baseNameBase class name (for use when generating separate classes for nested structures).private ClassBuilderm_classBuilderBuilder for class.protected ClassDecorator[]m_decoratorsDecorators to be called in order during class code generation.private booleanm_generatedClass generated flag.protected BindingHolderm_holderHolder for class binding definition.protected ImportsTrackerm_importsTrackerTracker for imports.protected LazyListm_innersHolders for inner classes defined within this class (nullif an inner class).protected java.lang.Stringm_listImplClassClass used for initializing list instances.private java.lang.Stringm_nameSimple class name.protected NameConverterm_nameConverterName conversion handler.protected UniqueNameSetm_nameSetValue names used in class.protected ClassHolderm_outerClassContaining class (nullif not an inner class).protected PackageHolderm_packagePackage containing class.private SchemaCustomm_schemaCustomCustomizations for the schema containing the schema component matching this class.private TypeDatam_superClassSuperclass to be extended as part of schema model (nullif none).private java.lang.Stringm_superNameSuperclass name to be extended if extension not required by model (nullif none).protected booleanm_useInnerClassesUse inner classes for substructures flag.private static SchemaDocumentationGenerators_generatorSchema documentation generator.private static Loggers_loggerLogger for class.private static javax.xml.transform.Transformers_transformerNull 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.protectedClassHolder(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 voidaddField(FieldDeclaration field)Add separately-constructed field to this class definition.booleanaddImport(java.lang.String fqname)Add import for class.voidaddInterface(java.lang.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 java.lang.StringbuildName(java.lang.String name, PackageHolder pack)Build fully-qualified class nameprotected static java.lang.Stringdescribe(ClassHolder.DataNode node)Describe the schema component associated with a node.protected java.lang.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 ClassBuildergetBuilder()Get the builder for this class.FieldDeclaration[]getFields()Get the fields defined in this class.ImportsTrackergetImports()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.StringgetName()Get simple name.IClassHoldergetOuterClass()Get containing class of inner class.PackageHoldergetPackage()Get containing package.SchemaCustomgetSchemaCustom()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.TypeDatagetSuperClass()Get base class to be extended.java.lang.StringgetSuperClassName()Get name of base class to be extended.java.lang.StringgetTypeName(java.lang.String type)Get the name to be used for a type.protected voidimportValueType(ClassHolder.DataNode value)Import the type associated with an item, if not directly accessibleprotected voidinitClass(boolean verbose, ClassBuilder builder, ClassHolder.ParentNode root)Initialize the class construction.booleanisGenerated()Check if the class has been generated.booleanisSuperClassForced()Check if superclass is forced by schema model.voidsetListImplementation(java.lang.String list)Set name of list implementation class to be used for initializing instances.voidsetSuperClass(TypeData sclas)Set superclass to be extended.voidsetSuperClassName(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 (nullif none).
-
m_superName
private java.lang.String m_superName
Superclass name to be extended if extension not required by model (nullif 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 (nullif an inner class).
-
m_outerClass
protected final ClassHolder m_outerClass
Containing class (nullif 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
nullif 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:
getNamein interfaceIClassHolder- Returns:
- name
-
getOuterClass
public IClassHolder getOuterClass()
Get containing class of inner class.- Specified by:
getOuterClassin interfaceIClassHolder- Returns:
- outer containing class, or
nullif not an inner class
-
getSuperClass
public TypeData getSuperClass()
Get base class to be extended.- Returns:
- base (
nullif none)
-
setSuperClass
public void setSuperClass(TypeData sclas)
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
public java.lang.String getSuperClassName()
Get name of base class to be extended.- Specified by:
getSuperClassNamein interfaceIClassHolder- Returns:
- base (
nullif 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:
setSuperClassNamein interfaceIClassHolder- Parameters:
base- fully-qualified class name of base class (nullif none)
-
setListImplementation
public void setListImplementation(java.lang.String list)
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
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:
getInterfacesin 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:
getFieldsin interfaceIClassHolder- Returns:
- fields
-
getMethods
public MethodDeclaration[] getMethods()
Get the methods defined in this class.- Specified by:
getMethodsin 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:
addImportin interfaceIClassHolder- Parameters:
fqname- fully qualified class name- Returns:
trueif 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:
getTypeNamein 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:
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
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
-
-