Jump to contentWelcome to Vionta.net
Xesta: Collection sorting strategies

The object binding technique is actually limiting. The possibilities of what we could do or the way that we may interact with an Xml file is almost endless. Annotation strategies are small properties added to the mapping annotation in order to define specific behaviours.

Element identifying and sorting

  • Bind By Key (BIND_COLLECTION_BY_KEY) In this case, the collection elements should have a mapped property that uniquely identifies the elements on the Xml side. This key is used to add, remove or sort the elements before serializing. This is the default case if a key attribute is defined.

@Bind(expression = "./reporting/plugins",classNames = "net.vionta.xml.xesta.test.beansamples.pom.both.Plugin")private ArrayList plugins = new ArrayList();...

In this case the child element has a key attribute.

@Bind(expression = "plugin")public class Plugin implements Serializable {

@Bind(expression="artifactId", key = true)private String id;...

  • Bind Collection by positon (BIND_COLLECTION_BY_POSITION). In this case we assume that elements can't or should not be identified and possition should be used instead. Bind by position is assumed when no key attribute is defined on the child elements.

@Bind( expression="table:table-row", namespaceAlias = {"table"},namespaceUris = {"urn:oasis:names:tc:opendocument:xmlns:table:1.0"}, collectionBindStrategy = SerializingMode.BIND_COLLECTION_BY_POSITION)public class Row implements Serializable {

@Bind(collectionBindStrategy = SerializingMode.BIND_COLLECTION_BY_POSITION,namespaceAlias = {"table"},namespaceUris = {"urn:oasis:names:tc:opendocument:xmlns:table:1.0"})private List cells = new ArrayList();
  • Append new elements as last (BIND_COLLECTION_APPEND_LAST). This strategy assumes that the bind is made by key, but new elements are appended at the end of the xml file.

  • Insert new elements as first (BIND_COLLECTION_APPEND_FIRST). This strategy assumes that the bind is made by key, but new elements are insered at the beguinning of the xml file.

  • Full collection reset (BIND_COLLECTION_FULL_RESET). This strategy is equivalent to traditional object binding. It erases all the data related to the collection and serializes the information taking the object information as an argument.