org.jibx.schema.codegen
Class StructureClassHolder

java.lang.Object
  extended by org.jibx.schema.codegen.ClassHolder
      extended by org.jibx.schema.codegen.StructureClassHolder
All Implemented Interfaces:
IClassHolder

public class StructureClassHolder
extends ClassHolder

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

Author:
Dennis M. Sosnoski

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jibx.schema.codegen.ClassHolder
ClassHolder.DataNode, ClassHolder.LeafNode, ClassHolder.ParentNode
 
Field Summary
private static java.lang.String LIST_DESERIALIZE_PREFIX
           
private static java.lang.String LIST_SERIALIZE_PREFIX
           
private  ContainerElementBase m_bindingElement
          Binding definition element for this class.
private  boolean m_collectionPresent
          Flag for collection present in class.
private  ClassHolder.ParentNode m_dataRoot
          Root node for data structure of class.
protected  UniqueNameSet m_selectSet
          Selection property names used in class (lazy create, null if none).
private  java.lang.String m_superName
          Name to be used with superclass reference (null if none).
private static java.util.Map s_formatMap
          Default format definitions map.
private static org.apache.log4j.Logger s_logger
          Logger for class.
 
Fields inherited from class org.jibx.schema.codegen.ClassHolder
COLLECTION_INSTANCE_TYPE, COLLECTION_VARIABLE_NAME, COLLECTION_VARIABLE_TYPE, m_baseName, m_decorators, m_importsTracker, m_inners, m_nameConverter, m_nameSet, m_outerClass, m_package, m_schemaCustom, m_useInnerClasses
 
Constructor Summary
  StructureClassHolder(java.lang.String name, java.lang.String base, PackageHolder pack, NameConverter nconv, ClassDecorator[] decorators, boolean inner)
          Constructor.
private StructureClassHolder(java.lang.String name, StructureClassHolder context)
          Constructor for creating a child inner class definition.
 
Method Summary
private  void addFixedNames(ClassHolder.ParentNode wrapper)
          Add all fixed names in a group to the set of names defined for this class.
private  void addFlagProperty(java.lang.String basename, ClassHolder.DataNode node, ClassBuilder builder)
          Add a flag property to the class.
private  void addInnerFormats(MappingElementBase mapping)
          Recursively add all inner enumeration classes as formats to a <mapping> definition.
private  StructureElement addReferenceStructure(ClassHolder.LeafNode leaf, DefinitionItem def, boolean single, BindingHolder holder, ContainerElementBase bindcomp)
          Build the binding structure element for a reference to a class.
private  void addRepeatedProperty(java.lang.String basename, ClassHolder.DataNode node, ClassBuilder builder)
          Add a multiple-valued property to the class.
private  void addSimpleProperty(java.lang.String basename, ClassHolder.DataNode node, ClassBuilder builder)
          Add a simple property to the class.
private  void addToBinding(ClassHolder.ParentNode parent, QName wrapname, boolean wrapopt, boolean single, ContainerElementBase bindcomp, BindingHolder holder)
          Generate the binding for a parent node of the data structure tree.
private  void addToClass(ClassHolder.ParentNode parent)
          Generate the fields and methods for a wrapper around one or more properties.
private  void addToTree(GroupItem struct, java.lang.String supertext, ClassHolder.ParentNode parent, BindingHolder bindhold)
          Populate a class data representation tree based on a supplied item tree.
 void buildDataStructure(GroupItem group, BindingHolder bindhold)
          Convert an item structure to a class representation.
private  ValueElement buildValueBinding(ClassHolder.DataNode node, QName wrapname, java.lang.String gname, java.lang.String sname, BindingHolder holder)
          Build a <value> binding component for a field.
private  void checkIfMethod(ClassHolder.DataNode node, java.lang.String seldesc, java.lang.String valdesc, ClassBuilder builder)
          Generate a test method for a value, if it's part of a group with a selector.
private  java.lang.String findDocumentation(boolean top, ClassHolder.DataNode node)
          Find the schema documentation associated with a data node.
private  void fixFlexibleNames(ClassHolder.ParentNode parent, boolean innamed)
          Handle value name assignments for a group within this class.
 void generate(boolean verbose, SourceBuilder builder, BindingHolder holder)
          Generate this class.
private  void generateSelectorCheck(ClassHolder.DataNode value, BlockBuilder block, ClassBuilder builder)
          Generate the code to check the selection on any containing selector group.
private  void generateSelectorSet(ClassHolder.DataNode value, BlockBuilder block, ClassBuilder builder)
          Generate the code to check and set the selection on any containing selector group.
private  CollectionElement newCollection(ClassHolder.DataNode node)
          Create a new collection element for the binding.
 void setBinding(ContainerElementBase container)
          Set the binding component linked to this class.
private  void setCollectionName(java.lang.String name, Item item)
          Convert collection name to lower case and append "List" for purposes of uniqueness.
private  void setMemberNames(java.lang.String basename, ClassHolder.DataNode node)
          Set the field and get/set access method names for a property.
private static void setName(QName qname, BindingHolder holder, StructureElementBase struct)
          Set the name and namespace URI for a <structure> or <collection> binding component.
private static void setName(QName qname, BindingHolder holder, ValueElement value)
          Set the name and namespace URI for a <value> binding component.
private  void setStructureOptional(ClassHolder.DataNode value, boolean force, StructureElementBase struct)
          Set the optional state of a structure or collection element in the binding.
 void setSuperName(java.lang.String name)
          Set the name to be used with the superclass reference.
 
Methods inherited from class org.jibx.schema.codegen.ClassHolder
addField, addImport, addInterface, addMethod, addType, describe, extractDocumentation, generateInner, getBindingName, getBuilder, getFields, getFullName, getImports, getInterfaces, getMethods, getName, getNamespace, getOuterClass, getPackage, getSortedFields, getSuperClass, getSuperClassName, getTypeName, importValueType, initClass, isGenerated, setNamespace, setSuperClass, setSuperClassName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LIST_DESERIALIZE_PREFIX

private static final java.lang.String LIST_DESERIALIZE_PREFIX
See Also:
Constant Field Values

LIST_SERIALIZE_PREFIX

private static final java.lang.String LIST_SERIALIZE_PREFIX
See Also:
Constant Field Values

s_logger

private static final org.apache.log4j.Logger s_logger
Logger for class.


s_formatMap

private static final java.util.Map s_formatMap
Default format definitions map.


m_collectionPresent

private boolean m_collectionPresent
Flag for collection present in class.


m_dataRoot

private ClassHolder.ParentNode m_dataRoot
Root node for data structure of class.


m_bindingElement

private ContainerElementBase m_bindingElement
Binding definition element for this class.


m_superName

private java.lang.String m_superName
Name to be used with superclass reference (null if none).


m_selectSet

protected UniqueNameSet m_selectSet
Selection property names used in class (lazy create, null if none).

Constructor Detail

StructureClassHolder

public StructureClassHolder(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

StructureClassHolder

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

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

setSuperName

public void setSuperName(java.lang.String name)
Set the name to be used with the superclass reference. This is only needed in the case where the class to be constructed represents an element definition of some named type.

Parameters:
name - element name

addToTree

private void addToTree(GroupItem struct,
                       java.lang.String supertext,
                       ClassHolder.ParentNode parent,
                       BindingHolder bindhold)
Populate a class data representation tree based on a supplied item tree. The mapping between the two trees is not one-to-one since item groupings may be ignored where irrelevant.

Parameters:
struct - root item in tree
supertext - schema documentation passed in for item tree
parent - containing data node
bindhold - associated binding definition holder

buildDataStructure

public void buildDataStructure(GroupItem group,
                               BindingHolder bindhold)
Convert an item structure to a class representation. This may include creating subsidiary classes (either as inner classes, or as separate standalone classes), where necessary.

Overrides:
buildDataStructure in class ClassHolder
Parameters:
group - item group
bindhold - associated binding definition holder

setBinding

public void setBinding(ContainerElementBase container)
Set the binding component linked to this class.

Parameters:
container - binding definition element (<mapping> or <structure>)

addInnerFormats

private void addInnerFormats(MappingElementBase mapping)
Recursively add all inner enumeration classes as formats to a <mapping> definition. This is used to create the <format> elements for all nested enumerations, which need to be direct children of the <mapping> element for the top-level class.

Parameters:
mapping -

addFixedNames

private void addFixedNames(ClassHolder.ParentNode wrapper)
Add all fixed names in a group to the set of names defined for this class. This calls itself recursively to handle nested groups.

Parameters:
wrapper -

setCollectionName

private void setCollectionName(java.lang.String name,
                               Item item)
Convert collection name to lower case and append "List" for purposes of uniqueness.

Parameters:
name -
item -

fixFlexibleNames

private void fixFlexibleNames(ClassHolder.ParentNode parent,
                              boolean innamed)
Handle value name assignments for a group within this class. This calls itself recursively to handle nested groups.

Parameters:
parent -
innamed - flag for parent group name already fixed

generateSelectorSet

private void generateSelectorSet(ClassHolder.DataNode value,
                                 BlockBuilder block,
                                 ClassBuilder builder)
Generate the code to check and set the selection on any containing selector group. This should be used when setting any value, including inside selector methods (if used), since selector groups may be nested.

Parameters:
value -
block -
builder -

generateSelectorCheck

private void generateSelectorCheck(ClassHolder.DataNode value,
                                   BlockBuilder block,
                                   ClassBuilder builder)
Generate the code to check the selection on any containing selector group. This should be used when getting any value, including inside selector methods (if used), since selector groups may be nested.

Parameters:
value -
block -
builder -

checkIfMethod

private void checkIfMethod(ClassHolder.DataNode node,
                           java.lang.String seldesc,
                           java.lang.String valdesc,
                           ClassBuilder builder)
Generate a test method for a value, if it's part of a group with a selector.

Parameters:
node -
seldesc - containing group description
valdesc - description of this value within group
builder -

setStructureOptional

private void setStructureOptional(ClassHolder.DataNode value,
                                  boolean force,
                                  StructureElementBase struct)
Set the optional state of a structure or collection element in the binding. The name for the structure or collection must be set before calling this method, since the presence or absence of a name determines whether optional status is passed down from a parent.

Parameters:
value - node
force - optional state forced flag
struct - binding structure

setName

private static void setName(QName qname,
                            BindingHolder holder,
                            ValueElement value)
Set the name and namespace URI for a <value> binding component. The value style must be set before making this call, since element and attribute elements are handled differently.

Parameters:
qname - qualified name to be set (null if none)
holder -
value -

setName

private static void setName(QName qname,
                            BindingHolder holder,
                            StructureElementBase struct)
Set the name and namespace URI for a <structure> or <collection> binding component.

Parameters:
qname - qualified name to be set (null if none)
holder -
struct -

buildValueBinding

private ValueElement buildValueBinding(ClassHolder.DataNode node,
                                       QName wrapname,
                                       java.lang.String gname,
                                       java.lang.String sname,
                                       BindingHolder holder)
Build a <value> binding component for a field.

Parameters:
node -
wrapname -
gname -
sname -
holder -
Returns:
constructed binding component

setMemberNames

private void setMemberNames(java.lang.String basename,
                            ClassHolder.DataNode node)
Set the field and get/set access method names for a property.

Parameters:
basename -
node -

addSimpleProperty

private void addSimpleProperty(java.lang.String basename,
                               ClassHolder.DataNode node,
                               ClassBuilder builder)
Add a simple property to the class. This adds the actual field definition, along with the appropriate access methods.

Parameters:
basename -
node -
builder -

addRepeatedProperty

private void addRepeatedProperty(java.lang.String basename,
                                 ClassHolder.DataNode node,
                                 ClassBuilder builder)
Add a multiple-valued property to the class. This adds the actual field definition, along with the appropriate access methods.

Parameters:
basename -
node -
builder -

addFlagProperty

private void addFlagProperty(java.lang.String basename,
                             ClassHolder.DataNode node,
                             ClassBuilder builder)
Add a flag property to the class. This adds the actual field definition, along with the appropriate access methods.

Parameters:
basename -
node -
builder -

findDocumentation

private java.lang.String findDocumentation(boolean top,
                                           ClassHolder.DataNode node)
Find the schema documentation associated with a data node. If the node has documentation set and does not have a separate class, this just returns the documentation from that node. Otherwise, it moves up the node tree until it finds a documented node, terminating if any parent has more than one child or when it reaches the node matching the root of the class data structure.

Parameters:
top - use topmost documentation found flag
node - starting node
Returns:
documentation

addToClass

private void addToClass(ClassHolder.ParentNode parent)
Generate the fields and methods for a wrapper around one or more properties. This calls itself recursively to handle nested wrappers.

Parameters:
parent -

addReferenceStructure

private StructureElement addReferenceStructure(ClassHolder.LeafNode leaf,
                                               DefinitionItem def,
                                               boolean single,
                                               BindingHolder holder,
                                               ContainerElementBase bindcomp)
Build the binding structure element for a reference to a class.

Parameters:
leaf - reference node
def - target definition
single - flag for single child
holder - holder for binding definition
bindcomp - containing binding element
Returns:
binding structure

newCollection

private CollectionElement newCollection(ClassHolder.DataNode node)
Create a new collection element for the binding. This initializes the create and declared types of the collection as appropriate.

Parameters:
node - data node associated with collection
Returns:
collection element

addToBinding

private void addToBinding(ClassHolder.ParentNode parent,
                          QName wrapname,
                          boolean wrapopt,
                          boolean single,
                          ContainerElementBase bindcomp,
                          BindingHolder holder)
Generate the binding for a parent node of the data structure tree. This calls itself recursively to handle nested subtrees. TODO: This needs a more structured approach to creating the binding, which probably involves trying to merge the binding components down a particular branch of the tree as long as there's only one child (creating new structures as needed when the child has a name and there's already a name, or the child has a property and there's already a property, etc.)

Parameters:
parent - node to be added to binding
wrapname - name to be used for wrapper collection or structure, null if none
wrapopt - wrapper element optional flag (should be false if wrapname is null)
single - parent node binding component can be modified by child flag (single path from parent)
bindcomp - binding definition component corresponding to the parent node
holder - binding definition tracking information

generate

public void generate(boolean verbose,
                     SourceBuilder builder,
                     BindingHolder holder)
Generate this class.

Specified by:
generate in class ClassHolder
Parameters:
verbose -
builder - class source file builder
holder - binding holder


Project Web Site