All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.brunneng.jom.converters.PropertyConverter Maven / Gradle / Ivy

There is a newer version: 0.8.5.2
Show newest version
package net.sf.brunneng.jom.converters;

import net.sf.brunneng.jom.info.OperationContextInfo;

import java.util.List;

/**
 * Provide conversion between corresponding properties. Conversion occurs during creation of diff, to make possible
 * to compare corresponding properties. Then, converted values can be used to insert into properties during applying
 * of diff. Class of converter should be specified by
 * {@link net.sf.brunneng.jom.annotations.Converter @Converter} annotation.
 */
public interface PropertyConverter extends MarkersUser {

   /**
    * This method is called to convert from source property to destination if annotation is present in destination
    * side, and vise versa - if it's on source side of association.
    * @param otherPropertiesObjects list of object taken from properties on other side of association. In case
    *                               of {@link net.sf.brunneng.jom.annotations.MapFromMany @MapFromMany} it will
    *                               contain several values, otherwise - one value.
    * @param contextInfo information about {@link net.sf.brunneng.jom.info.OperationContextInfo context}
    *                    in which values are converted. Using of this context is not necessary but it can be useful
    *                    in some situation to help to create result object correctly.
    * @return converted object. Also you can return marker object
    * MarkersUser.EQUAL_TO_DESTINATION_MARKER, which will be treated by mapper as equal equal to destination
    * object. And as result - protect destination object from being changed.
    */
   Object convertFrom(List otherPropertiesObjects, OperationContextInfo contextInfo);

   /**
    * This method is called to convert from destination property to source if annotation is present in destination
    * side, and vise versa - if it's on source side of association.
    * @param currPropertyObject object taken from property on other side of association.
    * @param contextInfo information about {@link net.sf.brunneng.jom.info.OperationContextInfo context}
    *                    in which values are converted. Using of this context is not necessary but it can be useful
    *                    in some situation to help to create result object correctly.
    * @return converted object. Note, that it return not list because mapping from one property to many is not possible.
    * Also you can return marker object MarkersUser.EQUAL_TO_DESTINATION_MARKER, which will be treated by
    * mapper as equal equal to destination object. And as result - protect destination object from being changed.
    */
   Object convertTo(Object currPropertyObject, OperationContextInfo contextInfo);
}