Skip to content
stemey edited this page Oct 25, 2012 · 4 revisions

Atem provides an alternative to the standard java reflection API. The Atem API comes with implementations for different kinds of objects like Pojos, Jpa entities, Jackson representation of Json or Atem dynamic entities. In order to get started one needs to configure at least one subrepository providing an implementation of the api. Let us start with the Pojo repository.

First you need to include the atem maven dependencies:

<depedency>
	<groupId>org.atemsource</groupId>
	<artifactId>atem-impl</artifactId>
	<version>...</version>
</dependency>

Also include the spring container. Include the following spring configuration to define the EntityTypeRepository singleton:

<import src"classpath:/atem/pojo/entitytype.xml"/>

<bean class="org.atemsource.atem.impl.EntityTypeRepositoryImpl">
	<property name="subRepositories">
		<list>
			<ref bean="atem-entityType-repository"/>
			<ref bean="atem-attribute-repository"/>
			<ref bean="foo-bar-pojo-repository"/>
		</list>
	</property>
</bean>

<bean id="foo-bar-pojo-repository" parent="atem-scanned-pojo-repository">
	<property name="includedPackage" value="foo.bar"/>
</bean>

This configuration imports the basic spring bean definitions for pojo repositories. The imported spring configuration contains an abstract definition of the ScannedPojoEntityTypeRepository. This repository scans the classpath defined by the property "package" and creates types for all the classes it finds.

To use the Atem API and have reflective access to a class in the package foo.bar one does the following:

@inject
private EntityTypeRepository entityTypeRepository

public int getAttributeCountOfEntityA() {
	EntityType<foo.bar.EntityA> type = entityTypeRepository.getEntityType(foo.bar.EntityA.class);
	return type.getAttributes().size();
}

Checkout the implementation wiki for more details on cofiguring the pojo repository and other repositories.

Using a utility

To use one of the utilities the corresponding maven dependencies need to be included:

<dependency>
	<groupId>org.atemsource</groupId>
	<artifactId>atem-utility</artifactId>
	<version>...</version>
</dependency>

The extra spring configuration needs to be provided. Some utilities require a special subrepository to be present. Let us start with the comparison utility. All you need to do is add this line to your configuration:

<import src"classpath:/meta/utility/compare-example.xml"/>

Now we can do a comparison:

@inject
private ComparisonBuilderFactory comparisBuilderFactory;

public boolean isEqual(EntityA old, EntityA new) {
	ComparisonBuilder comparisonBuilder = comparisonBuilderFactory.create(EntityA.class);
	comparisonBuilder.include("importantProperty");
	Comparison comparison = comparisonBuilder.create();
	return comparison.getDifferences(old,new).size()==0;
}

Checkout the [utility wiki] (https://github.com/stemey/atem.utility.github.com/wiki/Home) for more information on utilities and their usage.

Clone this wiki locally