Package io.kojan.xml

Class Attribute<EnclosingType,EnclosingBean,AttributeType>

java.lang.Object
io.kojan.xml.Property<EnclosingType,EnclosingBean,AttributeType>
io.kojan.xml.Attribute<EnclosingType,EnclosingBean,AttributeType>
Type Parameters:
EnclosingType - data type of entity
EnclosingBean - type of bean associated with the entity
AttributeType - data type of attribute value

public class Attribute<EnclosingType,EnclosingBean,AttributeType> extends Property<EnclosingType,EnclosingBean,AttributeType>
Attribute of an Entity. A simple Property with text representation.

Attribute values have a specified Java type. There are Converters that allow to convert attribute values to and from their text (String) representation.

When stored in XML form, an attribute is represented by a XML element with specified tag. Text content of the element specifies property value.

Author:
Mikolaj Izdebski
  • Constructor Details

  • Method Details

    • of

      public static <Type, Bean> Attribute<Type,Bean,String> of(String tag, Getter<Type,String> getter, Setter<Bean,String> setter)
      Creates a unique, non-optional String attribute.
      Type Parameters:
      Type - data type of entity
      Bean - type of bean associated with the entity
      Parameters:
      tag - attribute XML tag name
      getter - entity bean getter method that returns value of the attribute
      setter - entity bean setter method that returns value of the attribute
      Returns:
      created attribute
    • of

      public static <Type, Bean, AttributeType> Attribute<Type,Bean,AttributeType> of(String tag, Getter<Type,AttributeType> getter, Setter<Bean,AttributeType> setter, Converter<AttributeType,String> toStringConverter, Converter<String,AttributeType> fromStringConverter)
      Creates a unique, non-optional attribute.
      Type Parameters:
      Type - data type of entity
      Bean - type of bean associated with the entity
      AttributeType - type of attribute value
      Parameters:
      tag - attribute XML tag name
      getter - entity bean getter method that returns value of the attribute
      setter - entity bean setter method that returns value of the attribute
      toStringConverter - function that converts attribute value into a text form
      fromStringConverter - function that converts attribute value from a text form
      Returns:
      created attribute
    • ofOptional

      public static <Type, Bean> Attribute<Type,Bean,String> ofOptional(String tag, Getter<Type,String> getter, Setter<Bean,String> setter)
      Creates a unique, optional String attribute.
      Type Parameters:
      Type - data type of entity
      Bean - type of bean associated with the entity
      Parameters:
      tag - attribute XML tag name
      getter - entity bean getter method that returns value of the attribute
      setter - entity bean setter method that returns value of the attribute
      Returns:
      created attribute
    • ofOptional

      public static <Type, Bean, AttributeType> Attribute<Type,Bean,AttributeType> ofOptional(String tag, Getter<Type,AttributeType> getter, Setter<Bean,AttributeType> setter, Converter<AttributeType,String> toStringConverter, Converter<String,AttributeType> fromStringConverter)
      Creates a unique, optional attribute.
      Type Parameters:
      Type - data type of entity
      Bean - type of bean associated with the entity
      AttributeType - type of attribute value
      Parameters:
      tag - attribute XML tag name
      getter - entity bean getter method that returns value of the attribute
      setter - entity bean setter method that returns value of the attribute
      toStringConverter - function that converts attribute value into a text form
      fromStringConverter - function that converts attribute value from a text form
      Returns:
      created attribute
    • ofMulti

      public static <Type, Bean> Attribute<Type,Bean,String> ofMulti(String tag, Getter<Type,Iterable<String>> getter, Setter<Bean,String> setter)
      Creates a non-unique, optional String attribute.
      Type Parameters:
      Type - data type of entity
      Bean - type of bean associated with the entity
      Parameters:
      tag - attribute XML tag name
      getter - entity bean getter method that returns value of the attribute
      setter - entity bean setter method that returns value of the attribute
      Returns:
      created attribute
    • ofMulti

      public static <Type, Bean, AttributeType> Attribute<Type,Bean,AttributeType> ofMulti(String tag, Getter<Type,Iterable<AttributeType>> getter, Setter<Bean,AttributeType> setter, Converter<AttributeType,String> toStringConverter, Converter<String,AttributeType> fromStringConverter)
      Creates a non-unique, optional attribute.
      Type Parameters:
      Type - data type of entity
      Bean - type of bean associated with the entity
      AttributeType - type of attribute value
      Parameters:
      tag - attribute XML tag name
      getter - entity bean getter method that returns value of the attribute
      setter - entity bean setter method that returns value of the attribute
      toStringConverter - function that converts attribute value into a text form
      fromStringConverter - function that converts attribute value from a text form
      Returns:
      created attribute
    • dump

      protected void dump(XMLDumper dumper, AttributeType value) throws XMLException
      Description copied from class: Property
      Serializes the property into XML format, using given XMLDumper.
      Specified by:
      dump in class Property<EnclosingType,EnclosingBean,AttributeType>
      Parameters:
      dumper - the sink to serialize data to
      value - property value to serialize
      Throws:
      XMLException - in case exception occurs during XML serialization
    • parse

      protected AttributeType parse(XMLParser parser) throws XMLException
      Description copied from class: Property
      Deserializes the property from XML format, using given XMLParser.
      Specified by:
      parse in class Property<EnclosingType,EnclosingBean,AttributeType>
      Parameters:
      parser - the source to deserialize data from
      Returns:
      deserialized property value
      Throws:
      XMLException - in case exception occurs during XML deserialization