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 anEntity
. A simpleProperty
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.
- Author:
- Mikolaj Izdebski
-
-
Constructor Summary
Constructors Constructor Description 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.
-
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 givenXMLDumper
.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 givenXMLParser
.
-
-
-
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 (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 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 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,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 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,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 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,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 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,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 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,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 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
protected void dump(XMLDumper dumper, AttributeType value) throws XMLException
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
protected AttributeType parse(XMLParser parser) throws XMLException
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
-
-