Class 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
    • 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_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 name
        base - base class name
        pack - package information
        holder - binding holder
        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

      • 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 base,
                                       Item item)
        Convert base name to collection name. If using a java.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 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 - binding containing the value definition
        value - 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 definition
        struct - 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 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​(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 none
        wrapopt - wrapper element optional flag (should be false if wrapname is null)
        holder - binding definition tracking information
        node - 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 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)
        Generate this class.
        Specified by:
        generate in class ClassHolder
        Parameters:
        verbose -
        builder - class source file builder