Package io.kojan.xml

Class 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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void dump​(XMLDumper dumper, AttributeType value)
      Serializes the property into XML format, using given XMLDumper.
      static <Type,​Bean,​AttributeType>
      Attribute<Type,​Bean,​AttributeType>
      of​(java.lang.String tag, Getter<Type,​AttributeType> getter, Setter<Bean,​AttributeType> setter, Converter<AttributeType,​java.lang.String> toStringConverter, Converter<java.lang.String,​AttributeType> fromStringConverter)
      Creates a unique, non-optional attribute.
      static <Type,​Bean>
      Attribute<Type,​Bean,​java.lang.String>
      of​(java.lang.String tag, Getter<Type,​java.lang.String> getter, Setter<Bean,​java.lang.String> setter)
      Creates a unique, non-optional String attribute.
      static <Type,​Bean,​AttributeType>
      Attribute<Type,​Bean,​AttributeType>
      ofMulti​(java.lang.String tag, Getter<Type,​java.lang.Iterable<AttributeType>> getter, Setter<Bean,​AttributeType> setter, Converter<AttributeType,​java.lang.String> toStringConverter, Converter<java.lang.String,​AttributeType> fromStringConverter)
      Creates a non-unique, optional attribute.
      static <Type,​Bean>
      Attribute<Type,​Bean,​java.lang.String>
      ofMulti​(java.lang.String tag, Getter<Type,​java.lang.Iterable<java.lang.String>> getter, Setter<Bean,​java.lang.String> setter)
      Creates a non-unique, optional String attribute.
      static <Type,​Bean,​AttributeType>
      Attribute<Type,​Bean,​AttributeType>
      ofOptional​(java.lang.String tag, Getter<Type,​AttributeType> getter, Setter<Bean,​AttributeType> setter, Converter<AttributeType,​java.lang.String> toStringConverter, Converter<java.lang.String,​AttributeType> fromStringConverter)
      Creates a unique, optional attribute.
      static <Type,​Bean>
      Attribute<Type,​Bean,​java.lang.String>
      ofOptional​(java.lang.String tag, Getter<Type,​java.lang.String> getter, Setter<Bean,​java.lang.String> setter)
      Creates a unique, optional String attribute.
      protected AttributeType parse​(XMLParser parser)
      Deserializes the property from XML format, using given XMLParser.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Attribute

        public Attribute​(java.lang.String tag,
                         Getter<EnclosingType,​java.lang.Iterable<AttributeType>> getter,
                         Setter<EnclosingBean,​AttributeType> setter,
                         Converter<AttributeType,​java.lang.String> toStringConverter,
                         Converter<java.lang.String,​AttributeType> fromStringConverter,
                         boolean optional,
                         boolean unique)
        Creates an attribute of an entity.
        Parameters:
        tag - XML element tag name used to serialize the attribute in XML form (see Property.getTag())
        getter - attribute getter method
        setter - attribute setter method
        toStringConverter - function that converts attribute value into a text form
        fromStringConverter - function that converts attribute value from a text form
        optional - whether the attribute is optional (see Property.isOptional())
        unique - whether the attribute is unique (see Property.isUnique())
    • Method Detail

      • of

        public static <Type,​Bean> Attribute<Type,​Bean,​java.lang.String> of​(java.lang.String tag,
                                                                                             Getter<Type,​java.lang.String> getter,
                                                                                             Setter<Bean,​java.lang.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​(java.lang.String tag,
                                                                                                              Getter<Type,​AttributeType> getter,
                                                                                                              Setter<Bean,​AttributeType> setter,
                                                                                                              Converter<AttributeType,​java.lang.String> toStringConverter,
                                                                                                              Converter<java.lang.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,​java.lang.String> ofOptional​(java.lang.String tag,
                                                                                                     Getter<Type,​java.lang.String> getter,
                                                                                                     Setter<Bean,​java.lang.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​(java.lang.String tag,
                                                                                                                      Getter<Type,​AttributeType> getter,
                                                                                                                      Setter<Bean,​AttributeType> setter,
                                                                                                                      Converter<AttributeType,​java.lang.String> toStringConverter,
                                                                                                                      Converter<java.lang.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,​java.lang.String> ofMulti​(java.lang.String tag,
                                                                                                  Getter<Type,​java.lang.Iterable<java.lang.String>> getter,
                                                                                                  Setter<Bean,​java.lang.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​(java.lang.String tag,
                                                                                                                   Getter<Type,​java.lang.Iterable<AttributeType>> getter,
                                                                                                                   Setter<Bean,​AttributeType> setter,
                                                                                                                   Converter<AttributeType,​java.lang.String> toStringConverter,
                                                                                                                   Converter<java.lang.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