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 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 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 voiddump(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 AttributeTypeDeserializes the property from XML format, using givenXMLParser.
-
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:PropertySerializes the property into XML format, using givenXMLDumper.- Specified by:
dumpin 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:PropertyDeserializes the property from XML format, using givenXMLParser.- Specified by:
parsein 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
-