Package org.jibx.schema.codegen
Class StructureClassHolder
- java.lang.Object
-
- org.jibx.schema.codegen.TypeData
-
- org.jibx.schema.codegen.ClassHolder
-
- 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
Fields Modifier and Type Field Description 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 static java.util.Map
s_formatMap
Default format definitions map.private static Logger
s_logger
Logger for class.-
Fields inherited from class org.jibx.schema.codegen.ClassHolder
COLLECTION_VARIABLE_NAME, COLLECTION_VARIABLE_TYPE, m_baseName, m_decorators, m_holder, m_importsTracker, m_inners, m_listImplClass, m_nameConverter, m_nameSet, m_outerClass, m_package, m_useInnerClasses
-
-
Constructor Summary
Constructors Modifier Constructor Description StructureClassHolder(java.lang.String name, java.lang.String base, PackageHolder pack, BindingHolder holder, 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
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(QName wrapname, boolean wrapopt, BindingHolder holder, 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 base, Item item)
Convert base name to collection name.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.private void
setValueHandlingOptions(Item item, ValueElement value, BindingHolder holder)
Set serializer/deserializer options for a <value> component of the binding.-
Methods inherited from class org.jibx.schema.codegen.ClassHolder
addField, addImport, addInterface, addMethod, addType, describe, extractDocumentation, finishClass, generateInner, getBuilder, getFields, getImports, getInterfaces, getMethods, getName, getOuterClass, getPackage, getSchemaCustom, getSortedFields, getSuperClass, getSuperClassName, getTypeName, importValueType, initClass, isGenerated, isSuperClassForced, setListImplementation, setSuperClass, setSuperClassName
-
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
-
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 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_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, BindingHolder holder, NameConverter nconv, ClassDecorator[] decorators, boolean inner)
Constructor.- Parameters:
name
- class namebase
- base class namepack
- package informationholder
- binding holdernconv
- name converterdecorators
- class decoratorsinner
- 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 namecontext
- parent class
-
-
Method Detail
-
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 treesupertext
- schema documentation passed in for item treeparent
- containing data nodebindhold
- 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 classClassHolder
- Parameters:
group
- item groupbindhold
- 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 base, Item item)
Convert base name to collection name. If using ajava.util.List
representation the name is converted to singular form and "List" is appended; if using an array representation the name is converted to plural form.- Parameters:
base
-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 descriptionvaldesc
- description of this value within groupbuilder
-
-
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
- nodeforce
- optional state forced flagstruct
- 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
- binding containing the value definitionvalue
- binding component
-
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
- binding containing the structure or collection definitionstruct
- binding component
-
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 flagnode
- 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 nodedef
- target definitionsingle
- flag for single childholder
- holder for binding definitionbindcomp
- containing binding element- Returns:
- binding structure
-
newCollection
private CollectionElement newCollection(QName wrapname, boolean wrapopt, BindingHolder holder, ClassHolder.DataNode node)
Create a new collection element for the binding. This initializes the create and declared types of the collection as appropriate, along with the wrapper name and optional status.- Parameters:
wrapname
- name to be used for wrapper collection or structure,null
if nonewrapopt
- wrapper element optional flag (should befalse
if wrapname isnull
)holder
- binding definition tracking informationnode
- data node associated with collection- Returns:
- collection element
-
setValueHandlingOptions
private void setValueHandlingOptions(Item item, ValueElement value, BindingHolder holder)
Set serializer/deserializer options for a <value> component of the binding. If the item defining the item is a reference, this uses the definition type name as the format and makes sure the definition namespace is defined within the binding being generated. If the item defining the item is a builtin type, this sets the format and/or serializer/deserializer methods based on the type definition.- Parameters:
item
-value
-holder
-
-
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 bindingwrapname
- name to be used for wrapper collection or structure,null
if nonewrapopt
- wrapper element optional flag (should befalse
if wrapname isnull
)single
- parent node binding component can be modified by child flag (single path from parent)bindcomp
- binding definition component corresponding to the parent nodeholder
- binding definition tracking information
-
generate
public void generate(boolean verbose, SourceBuilder builder)
Generate this class.- Specified by:
generate
in classClassHolder
- Parameters:
verbose
-builder
- class source file builder
-
-