Package io.kojan.xml

Class Property<EnclosingType,​EnclosingBean,​NestedType>

  • Type Parameters:
    EnclosingType - data type of entity
    EnclosingBean - type of bean associated with the entity
    NestedType - data type of property value
    Direct Known Subclasses:
    Attribute, Relationship

    public abstract class Property<EnclosingType,​EnclosingBean,​NestedType>
    extends java.lang.Object
    Property of data Entity. Serves as a common base class for built-in Attributes and Relationships, as well as other user-defined custom entity properties.

    An entity property is closely related to its corresponding bean property, understood as a pair of Getter and Setter.

    A property can be optional, meaning that no instance of the property is required. If a property is not optional, then at least one instance of it is required for the entity to be valid.

    A property can be unique, meaning that at most one instance of the property can be present. If the property is not unique, then more than one instance of the property is allowed.

    Since non-unique properties allow multiple values, getters return Iterables over values and setters allow multiple calls to add multiple values.

    Author:
    Mikolaj Izdebski
    • Constructor Detail

      • Property

        protected Property​(java.lang.String tag,
                           Getter<EnclosingType,​java.lang.Iterable<NestedType>> getter,
                           Setter<EnclosingBean,​NestedType> setter,
                           boolean optional,
                           boolean unique)
        Initializes the abstract property.
        Parameters:
        tag - XML element tag name used to serialize the property in XML form (see getTag())
        getter - property getter method
        setter - property setter method
        optional - whether the property is optional (see isOptional())
        unique - whether the property is unique (see isUnique())
    • Method Detail

      • dump

        protected abstract void dump​(XMLDumper dumper,
                                     NestedType value)
                              throws XMLException
        Serializes the property into XML format, using given XMLDumper.
        Parameters:
        dumper - the sink to serialize data to
        value - property value to serialize
        Throws:
        XMLException - in case exception occurs during XML serialization
      • parse

        protected abstract NestedType parse​(XMLParser parser)
                                     throws XMLException
        Deserializes the property from XML format, using given XMLParser.
        Parameters:
        parser - the source to deserialize data from
        Returns:
        deserialized property value
        Throws:
        XMLException - in case exception occurs during XML deserialization
      • getTag

        public java.lang.String getTag()
        Determines XML element tag name used to serialize the property in XML form.
        Returns:
        XML element tag name
      • isOptional

        public boolean isOptional()
        Determines whether the property is optional or not.

        A property can be optional, meaning that no instance of the property is required. If a property is not optional, then at least one instance of it is required for the entity to be valid.

        Returns:
        true iff the property is optional
      • isUnique

        public boolean isUnique()
        Determines whether the property is unique or not.

        A property can be unique, meaning that at most one instance of the property can be present. If the property is not unique, then more than one instance of the property is allowed.

        Returns:
        true iff the property is unique
      • getGetter

        public Getter<EnclosingType,​java.lang.Iterable<NestedType>> getGetter()
        Obtain property getter method that can be used to retrieve property value.
        Returns:
        property getter method
      • getSetter

        public Setter<EnclosingBean,​NestedType> getSetter()
        Obtain property setter method that can be used to update property value.
        Returns:
        property setter method