Aggregate

Aggregate #

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="exampleAggregateClass">
   <Attribute name="name" class="String" />
   <Attribute name="reference" class="exampleAggregateClass" />
</AggregateClass>

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

AggregateClass aggregateClass = (AggregateClass) ModelFactory.getDefaultModel().getClass(AggregateClass.CLASS_NAME);
AggregateClass exampleAggregateClass = (AggregateClass) aggregateClass.createSubclass("exampleAggregateClass");
exampleAggregateClass.addAttribute("name", ModelFactory.getDefaultModel().getClass(StringClass.CLASS_NAME));
exampleAggregateClass.addAttribute("reference", ModelFactory.getDefaultModel().getClass("exampleAggregateClass"));
exampleAggregateClass.setAbstract(false);
exampleAggregateClass.finishEditing();

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

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

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 an aggregate object in the casebase.xml file for the given class definition:

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

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="exampleAggregateClass">
   <Attribute name="name" class="String" />
   <Attribute name="reference" class="exampleAggregateClass">
      <Property name="note">Example commentary</Property>
   </Attribute>
</AggregateClass>

During runtime, this can look like:

AggregateClass aggregateClass = (AggregateClass) ModelFactory.getDefaultModel().getClass(AggregateClass.CLASS_NAME);
AggregateClass exampleAggregateClass = (AggregateClass) aggregateClass.createSubclass("exampleAggregateClass");
exampleAggregateClass.addAttribute("name", ModelFactory.getDefaultModel().getClass(StringClass.CLASS_NAME));
exampleAggregateClass.addAttribute("reference", ModelFactory.getDefaultModel().getClass("exampleAggregateClass");

exampleAggregateClass.addAttributeProperty("note", "floor", "Example commentary");

exampleAggregateClass.finishEditing();

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:

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