Class ClassCustom

  • All Implemented Interfaces:
    IApply

    public class ClassCustom
    extends NestingBase
    implements IApply
    Class customization information. This supports direct class customizations (such as the corresponding element name, when building a concrete mapping) and also acts as a container for individual fields and/or properties.
    Author:
    Dennis M. Sosnoski
    • Field Detail

      • s_allowedAttributes

        public static final StringArray s_allowedAttributes
        Enumeration of allowed attribute names
      • ELEMENT_NAME

        public static final java.lang.String ELEMENT_NAME
        Element name in XML customization file.
        See Also:
        Constant Field Values
      • s_representationEnum

        public static final EnumSet s_representationEnum
      • m_name

        private java.lang.String m_name
      • m_elementName

        private java.lang.String m_elementName
      • m_typeName

        private java.lang.String m_typeName
      • m_createType

        private java.lang.String m_createType
      • m_factoryMethod

        private java.lang.String m_factoryMethod
      • m_enumValueMethod

        private java.lang.String m_enumValueMethod
      • m_form

        private int m_form
      • m_includes

        private java.lang.String[] m_includes
      • m_excludes

        private java.lang.String[] m_excludes
      • m_useSuper

        private boolean m_useSuper
      • m_requireds

        private java.lang.String[] m_requireds
      • m_optionals

        private java.lang.String[] m_optionals
      • m_serializer

        private java.lang.String m_serializer
      • m_deserializer

        private java.lang.String m_deserializer
      • m_children

        private final java.util.ArrayList m_children
      • m_isApplied

        private boolean m_isApplied
      • m_typeQName

        private QName m_typeQName
      • m_elementQName

        private QName m_elementQName
      • m_classInformation

        private IClass m_classInformation
    • Constructor Detail

      • ClassCustom

        ClassCustom​(NestingBase parent,
                    java.lang.String name)
        Constructor.
        Parameters:
        parent -
        name - class simple name (without package)
    • Method Detail

      • preSet

        private void preSet​(IUnmarshallingContext uctx)
        Make sure all attributes are defined.
        Parameters:
        uctx - unmarshalling context
      • getName

        public java.lang.String getName()
        Get fully-qualified class name.
        Returns:
        class name
      • getSimpleName

        public java.lang.String getSimpleName()
        Get simple class name.
        Returns:
        class name
      • getElementName

        public java.lang.String getElementName()
        Get the element name to be used for this class in a concrete mapping.
        Returns:
        element name
      • getElementQName

        public QName getElementQName()
        Get the qualified element name to be used for this class in a concrete mapping.
        Returns:
        element name
      • getTypeName

        public java.lang.String getTypeName()
        Get the type name to be used for this class in an abstract mapping.
        Returns:
        type name
      • getCreateType

        public java.lang.String getCreateType()
        Get the type name to be used when creating an instance of this class.
        Returns:
        type name
      • setCreateType

        public void setCreateType​(java.lang.String type)
        Set the type name to be used when creating an instance of this class.
        Parameters:
        type -
      • getSerializer

        public java.lang.String getSerializer()
        Get serializer method.
        Returns:
        serializer
      • getDeserializer

        public java.lang.String getDeserializer()
        Get deserializer method.
        Returns:
        deserializer
      • getEnumValueMethod

        public java.lang.String getEnumValueMethod()
        Get the method used to retrieve the text value for an enum class.
        Returns:
        method name
      • getFactoryMethod

        public java.lang.String getFactoryMethod()
        Get the factory method to be used when creating an instance of this class.
        Returns:
        method name
      • getTypeQName

        public QName getTypeQName()
        Get the qualified type name to be used for this class in an abstract mapping.
        Returns:
        type qname
      • getForm

        public int getForm()
        Get the representation code.
        Returns:
        value from s_representationEnum enumeration
      • getExcludes

        public java.lang.String[] getExcludes()
        Get list of names to be excluded from class representation.
        Returns:
        excludes (null if none)
      • getIncludes

        public java.lang.String[] getIncludes()
        Get list of names to be included in class representation.
        Returns:
        includes (null if none)
      • isUseSuper

        public boolean isUseSuper()
        Check for superclass to be included in binding.
        Returns:
        true if superclass included, false if not
      • isConcreteClass

        public boolean isConcreteClass()
        Check if this is a directly instantiable class (not an interface, and not abstract)
        Returns:
        true if instantiable, false if not
      • isSimpleValue

        public boolean isSimpleValue()
        Check if class represents a simple text value.
        Returns:
        text value flag
      • isAbstractMappingForced

        public boolean isAbstractMappingForced()
        Check if abstract mapping required for class.
        Returns:
        abstract mapping flag
      • isConcreteMappingForced

        public boolean isConcreteMappingForced()
        Check if concrete mapping required for class. If a 'form' setting is defined for the class it returns the flag based on that setting, and otherwise returns based on the nesting abstract mapping flag.
        Returns:
        abstract mapping flag
      • getChildren

        public java.util.List getChildren()
        Get list of children.
        Returns:
        list
      • addChild

        protected void addChild​(CustomBase child)
        Add child.
        Parameters:
        child -
      • setFormText

        private void setFormText​(java.lang.String text,
                                 IUnmarshallingContext ictx)
        Form set text method. This is intended for use during unmarshalling. TODO: add validation
        Parameters:
        text -
        ictx -
      • getFormText

        private java.lang.String getFormText()
        Form get text method. This is intended for use during marshalling.
        Returns:
        text
      • mapPropertyReadMethods

        private java.util.Map mapPropertyReadMethods​(IClassItem[] methods,
                                                     java.util.Set inclset,
                                                     java.util.Set exclset)
        Build map from member names to read access methods. This assumes that each public, non-static, no-argument method which returns a value and has a name beginning with "get" or "is" is a property read access method. It maps the corresponding property name to the method, and returns the map.
        Parameters:
        methods -
        inclset - set of member names to be included (null if not specified)
        exclset - set of member names to be excluded (null if not specified, ignored if inclset is non-null)
        Returns:
        map
      • mapPropertyWriteMethods

        private java.util.Map mapPropertyWriteMethods​(IClassItem[] methods,
                                                      java.util.Set inclset,
                                                      java.util.Set exclset)
        Build map from member names to write access methods. This assumes that each public, non-static, single-argument method which returns void and has a name beginning with "set" is a property write access method. It maps the corresponding property name to the method, and returns the map.
        Parameters:
        methods -
        inclset - set of member names to be included (null if not specified)
        exclset - set of member names to be excluded (null if not specified, ignored if inclset is non-null)
        Returns:
        map
      • mapFields

        private java.util.Map mapFields​(IClassItem[] fields,
                                        java.lang.String[] prefs,
                                        java.lang.String[] suffs,
                                        java.util.Set inclset,
                                        java.util.Set exclset)
        Build map from member names to fields. This includes all non-static and non-transient fields of the class.
        Parameters:
        fields -
        prefs - prefixes to be stripped in deriving names
        suffs - suffixes to be stripped in deriving names
        inclset - set of member names to be included (null if not specified)
        exclset - set of member names to be excluded (null if not specified, ignored if inclset is non-null)
        Returns:
        map
      • findPropertyType

        private java.lang.String findPropertyType​(IClassItem gmeth,
                                                  IClassItem smeth,
                                                  IClassLocator icl)
        Find the most specific type for a property based on the access methods.
        Parameters:
        gmeth - read access method (null if not defined)
        smeth - write access method (null if not defined)
        icl -
        Returns:
        most specific type name
      • stripNames

        private static java.lang.String[] stripNames​(java.lang.String[] names)
        Utility method to strip any leading non-alphanumeric characters from an array of name strings.
        Parameters:
        names - (null if none)
        Returns:
        array of stripped names (null if none)
      • classifyNames

        private static void classifyNames​(java.lang.String[] names,
                                          java.util.Set elems,
                                          java.util.Set attrs)
        Classify an array of names as elements or attributes, based on leading flag characters ('@' for an attribute, '<' for an element).
        Parameters:
        names - (null if none)
        elems - set of element names
        attrs - set of attribute names
      • apply

        public void apply​(IClassLocator icl)
        Apply customizations to class to fill out members. The name handling gets tricky, because of the variety of options provided. The user can specify value names to be included and/or excluded for the class, and also value names to be treated as optional or required. If an 'includes' list is given, only the values on that list are processed from the class, along with any values with their own child elements. If an 'excludes' list is given, only the names not on that list are processed. If neither an 'includes' nor an 'excludes' list is present, all values defined by the class will be processed. It is an error if the same name occurs on both an 'excludes' list and any other list, or if a name on the 'excludes' list has a child element present. It is also an error if the same name occurs on both the 'optionals' and 'requireds' list. Each list name can also be flagged with a leading indicator character to say whether the value should be represented as an attribute ('@') or element ('<'). The order of child elements is also partially determined by the lists, with the 'includes' list processed first, then the 'requireds' list, then the 'optionals' list, then the child elements, then any values not yet processed.
        Specified by:
        apply in interface IApply
        Parameters:
        icl - class locator
      • getMember

        public ValueCustom getMember​(java.lang.String name)
        Get customization information for a member by name. This method may only be called after apply(IClassLocator).
        Parameters:
        name -
        Returns:
        customization, or null if none
      • getClassInformation

        public IClass getClassInformation()
        Get actual class information. This method may only be called after apply(IClassLocator).
        Returns:
        class information
      • getMembers

        public java.util.Collection getMembers()
        Get collection of members in class.
        Returns:
        members