org.jibx.schema.codegen
Class ClassHolder

java.lang.Object
  extended by org.jibx.schema.codegen.ClassHolder
All Implemented Interfaces:
IClassHolder
Direct Known Subclasses:
EnumerationClassHolder, StructureClassHolder

public abstract class ClassHolder
extends java.lang.Object
implements IClassHolder

Information for a class to be included in code generated from schema.

Author:
Dennis M. Sosnoski

Nested Class Summary
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
protected static java.lang.String COLLECTION_INSTANCE_TYPE
           
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  java.lang.String m_bindingName
          Class name as used for binding (with '$' marker for inner class).
private  ClassBuilder m_classBuilder
          Builder for class.
protected  ClassDecorator[] m_decorators
          Decorators to be called in order during class code generation.
private  java.lang.String m_fullName
          Fully-qualified class name.
private  boolean m_generated
          Class generated flag.
protected  ImportsTracker m_importsTracker
          Tracker for imports.
protected  LazyList m_inners
          Holders for inner classes defined within this class (null if an inner class).
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.
private  java.lang.String m_namespaceUri
          Schema namespace for component associated with class.
protected  ClassHolder m_outerClass
          Containing class (null if not an inner class).
protected  PackageHolder m_package
          Package containing class.
protected  SchemaCustom m_schemaCustom
          Customizations for the schema containing the schema component matching this class.
private  ClassHolder 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 org.apache.log4j.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
protected ClassHolder(java.lang.String name, ClassHolder context)
          Constructor for creating a child inner class definition.
  ClassHolder(java.lang.String name, java.lang.String base, PackageHolder pack, NameConverter nconv, ClassDecorator[] decorators, boolean inner)
          Constructor.
 
Method Summary
 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.
protected 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.
abstract  void generate(boolean verbose, SourceBuilder builder, BindingHolder holder)
          Generate this class.
protected  void generateInner(boolean verbose, SourceBuilder builder, BindingHolder holder)
          Generate any inner classes of this class.
 java.lang.String getBindingName()
          Get fully-qualified name as used in binding.
protected  ClassBuilder getBuilder()
          Get the builder for this class.
 FieldDeclaration[] getFields()
          Get the fields defined in this class.
 java.lang.String getFullName()
          Get fully-qualified name.
 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.
protected  java.lang.String getNamespace()
          Get the schema namespace for the component associated with this class.
 IClassHolder getOuterClass()
          Get containing class of inner class.
 PackageHolder getPackage()
          Get containing package.
 StringPair[] getSortedFields()
          Get a sorted array of the field names and types defined in this class.
 ClassHolder 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 accessible
protected  void initClass(boolean verbose, ClassBuilder builder, ClassHolder.ParentNode root, BindingHolder holder)
          Initialize the class construction.
 boolean isGenerated()
          Check if the class has been generated.
protected  void setNamespace(java.lang.String uri)
          Set the schema namespace for the component associated with this class.
 void setSuperClass(ClassHolder sclas)
          Set superclass to be extended.
 void setSuperClassName(java.lang.String base)
          Set name of base class to be extended.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLLECTION_INSTANCE_TYPE

protected static final java.lang.String COLLECTION_INSTANCE_TYPE
See Also:
Constant Field Values

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 org.apache.log4j.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_fullName

private final java.lang.String m_fullName
Fully-qualified class name.


m_bindingName

private final java.lang.String m_bindingName
Class name as used for binding (with '$' marker for inner class).


m_namespaceUri

private java.lang.String m_namespaceUri
Schema namespace for component associated with class.


m_superClass

private ClassHolder 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_package

protected final PackageHolder m_package
Package containing class.


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_schemaCustom

protected SchemaCustom m_schemaCustom
Customizations for the schema containing the schema component matching this class.


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,
                   NameConverter nconv,
                   ClassDecorator[] decorators,
                   boolean inner)
Constructor.

Parameters:
name - class name
base - base class name
pack - package information
nconv - name converter
decorators - class decorators
inner - use inner classes for substructures

ClassHolder

protected ClassHolder(java.lang.String name,
                      ClassHolder context)
Constructor for creating a child inner class definition.

Parameters:
name - class name
context - parent class
Method Detail

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 group
bindhold - associated binding definition holder

setNamespace

protected void setNamespace(java.lang.String uri)
Set the schema namespace for the component associated with this class.

Parameters:
uri -

getNamespace

protected java.lang.String getNamespace()
Get the schema namespace for the component associated with this class.

Returns:
uri

getPackage

public PackageHolder getPackage()
Get containing package.

Returns:
package

getName

public java.lang.String getName()
Get simple name.

Specified by:
getName in interface IClassHolder
Returns:
name

getFullName

public java.lang.String getFullName()
Get fully-qualified name.

Specified by:
getFullName in interface IClassHolder
Returns:
name

getOuterClass

public IClassHolder getOuterClass()
Get containing class of inner class.

Specified by:
getOuterClass in interface IClassHolder
Returns:
outer containing class, or null if not an inner class

getBindingName

public java.lang.String getBindingName()
Get fully-qualified name as used in binding. This differs from the standard fully-qualified name in that it uses '$' rather than '.' to delimit inner class names.

Returns:
name

getSuperClass

public ClassHolder getSuperClass()
Get base class to be extended.

Returns:
base (null if none)

setSuperClass

public void setSuperClass(ClassHolder sclas)
Set superclass to be extended.

Parameters:
sclas - (null if none)

getSuperClassName

public java.lang.String getSuperClassName()
Get name of base class to be extended.

Specified by:
getSuperClassName in interface IClassHolder
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 if getSuperClassName() returns null.

Specified by:
setSuperClassName in interface IClassHolder
Parameters:
base - fully-qualified class name of base class (null if none)

isGenerated

public boolean isGenerated()
Check if the class has been generated. This should always be called before calling generate(boolean, SourceBuilder, BindingHolder), 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 interface IClassHolder
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 interface IClassHolder
Returns:
fields

getMethods

public MethodDeclaration[] getMethods()
Get the methods defined in this class.

Specified by:
getMethods in interface IClassHolder
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 interface IClassHolder
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 interface IClassHolder
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 interface IClassHolder
Parameters:
interf - interface type

addField

public void addField(FieldDeclaration field)
Add separately-constructed field to this class definition.

Specified by:
addField in interface IClassHolder
Parameters:
field -

addMethod

public void addMethod(MethodDeclaration method)
Add separately-constructed method declaration to this class definition.

Specified by:
addMethod in interface IClassHolder
Parameters:
method -

addType

public void addType(TypeDeclaration type)
Add separately-constructed inner class declaration to this class definition.

Specified by:
addType in interface IClassHolder
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,
                         BindingHolder holder)
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
holder - binding holder

generateInner

protected void generateInner(boolean verbose,
                             SourceBuilder builder,
                             BindingHolder holder)
Generate any inner classes of this class.

Parameters:
verbose -
builder - class source file builder
holder - binding holder

generate

public abstract void generate(boolean verbose,
                              SourceBuilder builder,
                              BindingHolder holder)
Generate this class. Subclasses must implement this method to first do the appropriate setup and then call initClass(boolean, ClassBuilder, ParentNode, BindingHolder) before doing their own code generation.

Parameters:
verbose -
builder - class source file builder
holder - binding holder


Project Web Site