Skip to content
stemey edited this page Feb 1, 2013 · 7 revisions

A java class is represented by the Type interface. PrimitiveType and EntityType extend Type. PrimitiveType represents all java primitive types and their wrappers.

##EntityType An EntityType contains attributes. The attributes represent the fields or java bean properties of the associated java class. An EntityType is usually retrieved from the EntityTypeRepository singleton by its associated class, an instance or its name:

EntityType<Person> personType = entityTypeRepository.getEntityType(Person.class);
Person willi = findWIlli();
EntityType<Person> personType = entityTypeRepository.getEntityType(willi);
EntityType<?> personType = entityTypeRepository.getEntityType("org.atemsource.Person");

The attributes and the super type of an EntityType can be accessed like this:

EntityType<Being> beingType = personType.getSuperType();
Attribute nameAttribute = personType.getAttribute("name");

To retrieve an attribute's value :

Person willi = findWilli();
String willisName = nameAttribute.getValue(willi);

An attribute has a targetType, which is the Type of the referenced objects. An attribute also has a returnClass which is the java class of the object returned by 'getValue()'. In case of a multi valued attribute like a 'java.util.List' these two types are different. The returnClass is 'java.util.List' and the targetType is the type of the contained elements in the List. This information is not available by java reflection.

You can get a reference to an EntityType from the EntityTypRepository by its associated class, its name or an instance of the EntityType. The EntityTypeRepository like most other objects in Atem is a component that should be injected into the client code. EntityType<Person> entityType = entityTypeRepository.getEntityType(Person.class);

Access to the EntityType's attributes is possible via their name. entityType.getDeclaredAttribute("firstName");

To modifiy an attribute's value:

// primitive attribute of type String
SingleAttribute<String> firstNameAttribute = (SingleAttribute<String>) entityType.getDeclaredAttribute("firstName") 
String firstName = firstNameAttribute.getValue(person);
// a collectionAttribute with returnClass java.util.List
ListAttribute<Address> adressAttribute = (ListAttribute<Address>) entityType.getAttribute("addresses");
List<Address> addresses = addressAttribute.getValue(person);
// adding an element to the list.
addressAttribute.addElement(person,new Address());

There are three types of attributes.

1. SingleAttribute

Defines an attribute which is a reference to a single instance. The value can be read and written.

SingleAttribute<String> nameAttribute = (SingleAttribute<String>)personType.geAttribute("name");

2. CollectionAttribute

A CollectionAttribute represents a multi valued attribute.

CollectionAttribute<List,Person> friendsAttribute = (CollectionAttribute<List,Person>)personType.geAttribute("friends");
// iterate over the list of friends
Iterator<Person> willisFirends = friendsAttribute.getIterator(willi);
// add John to the list of willis friends
willisFriends.addElement(willi,john);

The CollectionSortType defines whether this is sorted, ordered or neither. The colelction can be modified by adding and removing elements. in the case of orderable Collections it is also possible to use indx based operations.

3. MapAttribute

A map attribute is a ternary association to another type. The map can be modified by adding entries, removing entries and changing values associated with a certain key.

PrimitiveType

A Java class can be declared to be represented by a PrimitiveType. A date type like java.util.Date and java.util.Calendar are declared to be PrimitiveTypes. A PrimitiveTypesRegistrar is reposnible for regiszering a new primitive type:

public interface PrimitiveTypeRegistrar
{
	public PrimitiveType<?>[] getTypes();
}

Clone this wiki locally