-
Notifications
You must be signed in to change notification settings - Fork 0
Binding
the binding utility creates transformations and the corresponding dynamic target type in a declarative manner. Atem binding can be used instead of jackson to bind java classes to json. Also you can use it to bind java classes to soydata. Features:
- Atem can be used to bind to any dynamic types. Currently supported are json, soydata and atem dynamic entitie.
- Atem bindings are based on Atem transformation and can therefore do more complex transformations than filtering and renaming.
- there is a standard way to create different versions of the binding, if you need to provide different versions of an API. With the advent of app stores the likelihood of more than one client version accessing your API has increased.
The Binder provides the EntityTypeTransformation for a given source type:
@Inject
private Binder binder;
public ObjectNode convert(DomainA source) {
EntityTypeTransformation<DomainA, ObjectNode> transformation = binder
.getTransformation(DomainA.class);
return transformation.convert(source);
}
You can define the versioning of a property with the annotation Version. The Version itself needs to be provided as a String.
@Version(from="1.0",until="1.3")
private String versionedProperty;
To use the transformation of a certain version:
@Inject
private VersionedBinder binder;
public ObjectNode convert(DomainA source) {
EntityTypeTransformation<DomainA, ObjectNode> transformation = binder
.getTransformation(DomainA.class,"1.0");
return transformation.convert(source);
}
###Target type repository
The dynamic target types are created via an instanceof 'TypeFilter'. All Subrepositories are instances of that interface.
###AttributeFilters
A list AttributeFilters can be registeredto filter out the relevant attributes.
public interface AttributeFilter
{
boolean isExcluded(Attribute attribute);
}
###AttributeNameConverter
An AttributeNameConverter converts the attributes' names.
public interface AttributeNameConverter {
String convert(Attribute<?, ?> attribute);
}
###TypeNameConverter
The target type must have a distinct name.
public interface TypeNameConverter {
String convert(EntityType<?> entityType);
}
###Conversion
The conversion of primitive types can be customized by adding default converters to the converterFactory or by annotating the attributes in the source type:
@Conversion(DateConverter.class)
private Date date;
The example configuration below creates json bindings for all classes in the package "org.atemsource.domain.examples". The name of the target type is the source type name preceded by "json:".
<import resource="classpath:/meta/utility/transform-complete.xml" />
<import resource="classpath:/meta/utility/binding.xml" />
<import resource="classpath:/atem/pojo/entitytype.xml" />
<import resource="classpath:/atem/jackson/entitytype.xml" />
<bean id="domain-pojo-repository"
parent="abstract-atem-scanned-pojo-repository">
<property name="includedPackage" value="org.atemsource.domain.examples" />
</bean>
<bean id="atem-json-repository" parent="atem-abstract-json-repository"/>
<bean id="atem-repository"
class="org.atemsource.atem.impl.common.EntityTypeRepositoryImpl"
init-method="init">
<property name="repositories">
<list>
<ref bean="atem-entityType-repository" />
<ref bean="atem-attribute-repository" />
<ref bean="atem-json-repository" />
<ref bean="domain-pojo-repository" />
<ref bean="atem-transformation-subrepository" />
</list>
</property>
</bean>
<bean id="atem-utility-binder" class="org.atemsource.atem.utility.binding.Binder">
<property name="typeFilter" ref="domain-pojo-repository"/>
<property name="subRepository" ref="atem-json-repository" />
<property name="transformationBuilderFactory" ref="atem-utility-transformationBuilderFactory"/>
<property name="typeNameConverter">
<bean class="org.atemsource.atem.utility.binding.PrefixTypeNameConverter">
<property name="prefix" value="json" />
</bean>
</property>
</bean>
####Configuration for different versions
<import resource="classpath:/meta/utility/transform-complete.xml" />
<import resource="classpath:/meta/utility/binding.xml" />
<import resource="classpath:/atem/pojo/entitytype.xml" />
<import resource="classpath:/atem/jackson/entitytype.xml" />
<bean id="domain-pojo-repository"
parent="abstract-atem-scanned-pojo-repository">
<property name="includedPackage" value="org.atemsource.atem.utility.domain" />
</bean>
<bean id="atem-json-repository" parent="atem-abstract-json-repository"/>
<bean id="atem-repository"
class="org.atemsource.atem.impl.common.EntityTypeRepositoryImpl"
init-method="init">
<property name="repositories">
<list>
<ref bean="atem-entityType-repository" />
<ref bean="atem-attribute-repository" />
<ref bean="atem-json-repository" />
<ref bean="domain-pojo-repository" />
<ref bean="atem-transformation-subrepository" />
</list>
</property>
</bean>
<bean id="atem-utility-bindingProcessor"
class="org.atemsource.atem.utility.binding.version.VersionedBinder">
<property name="typeFilter" ref="domain-pojo-repository"/>
<property name="subRepository" ref="atem-json-repository" />
<property name="transformationBuilderFactory" ref="atem-utility-transformationBuilderFactory"/>
<property name="filters">
<list>
<bean
class="org.atemsource.atem.utility.binding.jackson.JacksonIgnoreFilter" />
</list>
</property>
<property name="versionResolver">
<bean
class="org.atemsource.atem.utility.transform.impl.version.VersionResolver">
<property name="parts" value="2" />
<property name="separator" value="\." />
</bean>
</property>
<property name="versions">
<list>
<value>1.0</value>
<value>1.1</value>
</list>
</property>
</bean>