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 entityEnclosingBean
- type of bean associated with the entityAttributeType
- 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 Converter
s 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Converter
<String, AttributeType> private final Converter
<AttributeType, String> -
Constructor Summary
ConstructorsConstructorDescriptionAttribute
(String tag, Getter<EnclosingType, Iterable<AttributeType>> getter, Setter<EnclosingBean, AttributeType> setter, Converter<AttributeType, String> toStringConverter, Converter<String, AttributeType> fromStringConverter, boolean optional, boolean unique) Creates an attribute of an entity. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
dump
(XMLDumper dumper, AttributeType value) Serializes the property into XML format, using givenXMLDumper
.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.Creates a unique, non-optional String attribute.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.Creates a non-unique, optional String attribute.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.Creates a unique, optional String attribute.protected AttributeType
Deserializes the property from XML format, using givenXMLParser
.
-
Field Details
-
toStringConverter
-
fromStringConverter
-
-
Constructor Details
-
Attribute
public Attribute(String tag, Getter<EnclosingType, Iterable<AttributeType>> getter, Setter<EnclosingBean, AttributeType> setter, Converter<AttributeType, String> toStringConverter, Converter<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 (seeProperty.getTag()
)getter
- attribute getter methodsetter
- attribute setter methodtoStringConverter
- function that converts attribute value into a text formfromStringConverter
- function that converts attribute value from a text formoptional
- whether the attribute is optional (seeProperty.isOptional()
)unique
- whether the attribute is unique (seeProperty.isUnique()
)
-
-
Method Details
-
of
public static <Type,Bean> Attribute<Type,Bean, ofString> (String tag, Getter<Type, String> getter, Setter<Bean, String> setter) Creates a unique, non-optional String attribute.- Type Parameters:
Type
- data type of entityBean
- type of bean associated with the entity- Parameters:
tag
- attribute XML tag namegetter
- entity bean getter method that returns value of the attributesetter
- entity bean setter method that returns value of the attribute- Returns:
- created attribute
-
of
public static <Type,Bean, Attribute<Type,AttributeType> Bean, ofAttributeType> (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 entityBean
- type of bean associated with the entityAttributeType
- type of attribute value- Parameters:
tag
- attribute XML tag namegetter
- entity bean getter method that returns value of the attributesetter
- entity bean setter method that returns value of the attributetoStringConverter
- function that converts attribute value into a text formfromStringConverter
- function that converts attribute value from a text form- Returns:
- created attribute
-
ofOptional
public static <Type,Bean> Attribute<Type,Bean, ofOptionalString> (String tag, Getter<Type, String> getter, Setter<Bean, String> setter) Creates a unique, optional String attribute.- Type Parameters:
Type
- data type of entityBean
- type of bean associated with the entity- Parameters:
tag
- attribute XML tag namegetter
- entity bean getter method that returns value of the attributesetter
- entity bean setter method that returns value of the attribute- Returns:
- created attribute
-
ofOptional
public static <Type,Bean, Attribute<Type,AttributeType> Bean, ofOptionalAttributeType> (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 entityBean
- type of bean associated with the entityAttributeType
- type of attribute value- Parameters:
tag
- attribute XML tag namegetter
- entity bean getter method that returns value of the attributesetter
- entity bean setter method that returns value of the attributetoStringConverter
- function that converts attribute value into a text formfromStringConverter
- function that converts attribute value from a text form- Returns:
- created attribute
-
ofMulti
public static <Type,Bean> Attribute<Type,Bean, ofMultiString> (String tag, Getter<Type, Iterable<String>> getter, Setter<Bean, String> setter) Creates a non-unique, optional String attribute.- Type Parameters:
Type
- data type of entityBean
- type of bean associated with the entity- Parameters:
tag
- attribute XML tag namegetter
- entity bean getter method that returns value of the attributesetter
- entity bean setter method that returns value of the attribute- Returns:
- created attribute
-
ofMulti
public static <Type,Bean, Attribute<Type,AttributeType> Bean, ofMultiAttributeType> (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 entityBean
- type of bean associated with the entityAttributeType
- type of attribute value- Parameters:
tag
- attribute XML tag namegetter
- entity bean getter method that returns value of the attributesetter
- entity bean setter method that returns value of the attributetoStringConverter
- function that converts attribute value into a text formfromStringConverter
- function that converts attribute value from a text form- Returns:
- created attribute
-
dump
Description copied from class:Property
Serializes the property into XML format, using givenXMLDumper
.- Specified by:
dump
in classProperty<EnclosingType,
EnclosingBean, AttributeType> - Parameters:
dumper
- the sink to serialize data tovalue
- property value to serialize- Throws:
XMLException
- in case exception occurs during XML serialization
-
parse
Description copied from class:Property
Deserializes the property from XML format, using givenXMLParser
.- Specified by:
parse
in classProperty<EnclosingType,
EnclosingBean, AttributeType> - Parameters:
parser
- the source to deserialize data from- Returns:
- deserialized property value
- Throws:
XMLException
- in case exception occurs during XML deserialization
-