Class TemplateLabel

java.lang.Object
org.simpleframework.xml.core.TemplateLabel
All Implemented Interfaces:
Label
Direct Known Subclasses:
AttributeLabel, ElementArrayLabel, ElementLabel, ElementListLabel, ElementListUnionLabel, ElementMapLabel, ElementMapUnionLabel, ElementUnionLabel, TextLabel, TextListLabel, VersionLabel

abstract class TemplateLabel extends Object implements Label
The TemplateLabel object is used to provide stock functions that can be used by all implementations. This ensures there is a consistent set of behaviours for each label. It also reduces the number of methods that need to be maintained for each Label implementation.
  • Field Details

    • builder

      private final KeyBuilder builder
      This is the builder that is used to generate label keys.
  • Constructor Details

    • TemplateLabel

      protected TemplateLabel()
      Constructor for the TemplateLabel is used to create a template for other labels. If any of the method implementations are not as required or they should be overridden by the subclass.
  • Method Details

    • getType

      public Type getType(Class type) throws Exception
      This is used to acquire the Type that the type provided is represented by. Typically this will return the field or method represented by the label. However, in the case of unions this will provide an override type.
      Specified by:
      getType in interface Label
      Parameters:
      type - this is the class to acquire the type for
      Returns:
      this returns the type represented by this class
      Throws:
      Exception
    • getLabel

      public Label getLabel(Class type) throws Exception
      This is used to acquire the Label that the type provided is represented by. Typically this will return the same instance. However, in the case of unions this will look for an individual label to match the type provided.
      Specified by:
      getLabel in interface Label
      Parameters:
      type - this is the type to acquire the label for
      Returns:
      this returns the label represented by this type
      Throws:
      Exception
    • getNames

      public String[] getNames() throws Exception
      This returns a Collection of element names. This will typically contain both the name and path of the label. However, if this is a union it can contain many names and paths. This method should never return null.
      Specified by:
      getNames in interface Label
      Returns:
      this returns the names of each of the elements
      Throws:
      Exception
    • getPaths

      public String[] getPaths() throws Exception
      This returns a Collection of element paths. This will typically contain only the path of the label, which is composed using the Path annotation and the name of the label. However, if this is a union it can contain many paths. This method should never return null.
      Specified by:
      getPaths in interface Label
      Returns:
      this returns the names of each of the elements
      Throws:
      Exception
    • getKey

      public Object getKey() throws Exception
      This is the key used to represent this label. The key is used to store the parameter in hash containers. Typically the key is generated from the paths associated with the label.
      Specified by:
      getKey in interface Label
      Returns:
      this is the key used to represent the label
      Throws:
      Exception
    • getEntry

      public String getEntry() throws Exception
      This is typically used to acquire the entry value as acquired from the annotation. However given that the annotation this represents does not have a entry attribute this will always provide a null value for the entry string.
      Specified by:
      getEntry in interface Label
      Returns:
      this will always return null for the entry value
      Throws:
      Exception
    • getDependent

      public Type getDependent() throws Exception
      This is used to acquire the dependent class for this label. This returns null as there are no dependents to the element annotation as it can only hold primitives with no dependents.
      Specified by:
      getDependent in interface Label
      Returns:
      this is used to return the dependent type of null
      Throws:
      Exception
    • isAttribute

      public boolean isAttribute()
      This method is used to determine if the label represents an attribute. This is used to style the name so that elements are styled as elements and attributes are styled as required.
      Specified by:
      isAttribute in interface Label
      Returns:
      this is used to determine if this is an attribute
    • isCollection

      public boolean isCollection()
      This is used to determine if the label is a collection. If the label represents a collection then any original assignment to the field or method can be written to without the need to create a new collection. This allows obscure collections to be used and also allows initial entries to be maintained.
      Specified by:
      isCollection in interface Label
      Returns:
      true if the label represents a collection value
    • isInline

      public boolean isInline()
      This is used to determine whether the label represents an inline XML entity. The ElementList annotation and the Text annotation represent inline items. This means that they contain no containing element and so can not specify overrides or special attributes.
      Specified by:
      isInline in interface Label
      Returns:
      this returns true if the annotation is inline
    • isText

      public boolean isText()
      This is used to determine if the label represents text. If a label represents text it typically does not have a name, instead the empty string represents the name. Also text labels can not exist with other text labels, or elements.
      Specified by:
      isText in interface Label
      Returns:
      this returns true if this label represents text
    • isTextList

      public boolean isTextList()
      This is used to determine if an annotated list is a text list. A text list is a list of elements that also accepts free text. Typically this will be an element list union that will allow unstructured XML such as XHTML to be parsed.
      Specified by:
      isTextList in interface Label
      Returns:
      returns true if the label represents a text list
    • isUnion

      public boolean isUnion()
      This is used to determine if this label is a union. If this is true then this label represents a number of labels and is simply a wrapper for these labels.
      Specified by:
      isUnion in interface Label
      Returns:
      this returns true if the label represents a union