Aggregate #

This page contains the following content:

Aggregate Objects #

The Aggregate class is used to combine several classes into one class in an object-oriented manner. This combination is realized with attributes that consist of a name and a corresponding data class similar to instance variables of classes in object-oriented programming languages. Arbitrary data classes including other aggregate classes can be used. Consequently, the modeling of deep aggregation hierarchies is possible. As the principle of Aggregate classes is based on object-oriented programming, it is also possible to generate abstract classes by using the XML attribute abstract. In this case, it is not possible to instantiate objects of this class directly.

To create an aggregate class in the model.xml configuration, a new sub-class of class Aggregate using the tag AggregateClass must be specified. The attributes are defined using the inner tags Attribute.

<AggregateClass name="customAggregateClass">
   <Attribute name="name" class="String"/>
   <Attribute name="reference" class="customAggregateClass"/>

To create this class during runtime, the following java code has to be used:

AggregateClass aggregateClass = (AggregateClass) ModelFactory.getDefaultModel().getAggregateSystemClass();
AggregateClass customAggregateClass = (AggregateClass) aggregateClass.createSubclass("customAggregateClass");
customAggregateClass.addAttribute("name", ModelFactory.getDefaultModel().getStringSystemClass());
customAggregateClass.addAttribute("reference", ModelFactory.getDefaultModel().getClass("customAggregateClass"));

It should be noted that for an aggregate class using the setAbstract(false) method call, the class must be set to non-abstract. Otherwise, it cannot be instantiated.

To create an object of this aggregate class, the following java code has to be used:

AggregateObject aggregateObject = (AggregateObject) ModelFactory.getDefaultModel().createObject("customAggregateClass");

StringObject name = (StringObject) ModelFactory.getDefaultModel().getStringSystemClass().newObject();
name.setNativeString("aggregate 1");
aggregateObject.setAttributeValue("name", name);

AggregateObject referenceObject = (AggregateObject) ModelFactory.getDefaultModel().createObject("customAggregateClass");
StringObject nameReference = (StringObject) ModelFactory.getDefaultModel().getStringSystemClass().newObject();
nameReference.setNativeString("aggregate 2");
referenceObject.setAttributeValue("name", nameReference);
referenceObject.setAttributeValue("reference", null);

aggregateObject.setAttributeValue("reference", referenceObject);

Aggregate objects are typically used as cases in a casebase, e.g., for attribute-value based case bases. Thus, the objects can also be written into the casebase, and they can also directly created in the casebase. The following example shows the above created aggregate object in the casebase.xml file for the given class definition:

<cdol:Agg c="customAggregateClass">
    <cdol:AA n="name" v="aggregate 1"/>
    <cdol:OA n="reference">
            <cdol:AA n="name" v="aggregate 2"/>
            <cdol:OA n="reference"/>

Properties #

Additionally, to the properties for data classes it’s possible to define properties for aggregate attributes. Like the data classes properties, properties can be defined in properties. It’s also not possible to set two different values here.

For example, such a property definition can look like:

<AggregateClass name="customAggregateClassProperty">
   <Attribute name="name" class="String" />
   <Attribute name="reference" class="customAggregateClass">
      <Property name="note">Example commentary</Property>

During runtime, this can look like:

AggregateClass aggregateClass = (AggregateClass) ModelFactory.getDefaultModel().getAggregateSystemClass();
AggregateClass customAggregateClass = (AggregateClass) aggregateClass.createSubclass("customAggregateClassProperty");
customAggregateClass.addAttribute("name", ModelFactory.getDefaultModel().getStringSystemClass());
customAggregateClass.addAttribute("reference", ModelFactory.getDefaultModel().getClass("customAggregateClassProperty"));

customAggregateClass.addAttributeProperty("reference", "note", "Example commentary");


To get the value of a property afterwards, the command getAttributeProperty(String attributeName, String propertyName) can be used. To change the value of the property, this property must first be removed and then added again. This can look like:

customAggregateClass.removeAttributeProperty("reference", "note");
customAggregateClass.addAttributeProperty("reference", "note", "Some content");