Skip to content
stemey edited this page Oct 21, 2012 · 1 revision

Add meta attributes to types attributes or even instances by following hese steps:

  1. setup configuration
    stup a basic entity type repository with subrepositories fo entity type, attributeas and your pojos. Also include the memory-meta.xml.

     <import resource="classpath:/atem/impl/memory-meta.xml" />
     <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="your-pojo-repository" />
     		</list>
     	</property>
     </bean>   
    
  2. Setup meta attributes

    To define meta attributes you need the MetaAttributeService instance from the configuration memory-meta.xml:

     // holderType is the type of the object that we want to add the attribute to
     EntityType<Attribute> holderType = entityTypeRepository.getEntityType(Attribute.class);
     // metaDataType is the type of the meta data we want to attach.
     EntityType<MetaDataExample> metaDataType = entityTypeRepository.getEntityType(MetaDataExample.class);
     // Now we define the meta attribute
     SingleAttribute<MetaDataExample> testMetaAttribute =
     	dynamicMetaAttributeService.addSingleMetaAttribute("test", holderType, metaDataType);
    
  3. Let us attach meta data to a specific attribute

     EntityType<EntityB> entityType = entityTypeRepository.getEntityType(EntityB.class);
     Attribute attribute = entityType.getAttribute("singleA");
     MetaDataExample ex = new MetaDataExample();
     ex.setData("hallo");
     Attribute metaAttribute = holderType.getMetaAttribute("test");
     metaAttribute.setValue(attribute, ex);