Data Classes

Data Classes #

This page contains the following content:

Data Classes in ProCAKE #

ProCAKE provides several data classes. Please refer to the following sections for more details:

The data class hierarchy is as follows: Data-Class-Hierarchy

The figure shows the hierarchy of built-in system classes. Please note that not all system classes are instantiable. Such abstract classes must first be subclassed (by user classes) to be able to create objects. For example, the URI class can be subclassed as follows:

URIClassImpl customUriClass =
  (URIClassImpl) ModelFactory.getDefaultModel().getURISystemClass().createSubclass("MyURI");
  customUriClass.setOntologyName("MyOnto");
  customUriClass.setAbstract(false);
  customUriClass.finishEditing();

Analogous to the Java perspective, data objects in ProCAKE represent the concrete data. In addition, each data object has its own data class implementation in ProCAKE that is implemented itself as a Java class. By this means, we explicitly model the relationship between data objects and the respective system and user classes.

Object IDs #

Each data object, that instances a data class in ProCAKE, can have an objectId. This id is necessary to identify an object in an object pool. For this purpose, the id must be unique.

The id can be set manually in the casebase or afterwards by using the method setId(String objectId). In this case, the user is responsible for ensuring that this id is unique. Otherwise, an exception would be thrown, when this object is read to an object pool.

For example, an id can be set in a casebase as follows:

<cdol:V id="exampleId" c="Void"/>

This represents a Void object, which can be identified by the id exampleId. It’s important to ensure, that no other object has this id.

During runtime, the id can be set as follows:

voidObject.setId("exampleId");

Note, that this requires an object voidObject, that has to be created before.

If an object without an id is read into an object pool, an id is generated. This id consists of two parts: the base and the offset. The base is a namespace and depends on the location, where the object is stored. Mainly this is an object pool. The offset is an unique id that must be unique within the object pool and is managed by the object pool itself. This type of new objectIds can be created manually using the method ObjectPoolFactory.newObjectId(String objectPoolId, String offset). This method is also called automatically by the method WriteableObjectPool.store(DataObject dataObject), if no id is set.

Properties #

In ProCAKE it’s possible to add properties to data classes. These properties store information about the object, which are additionally to the main value of a data object. ProCAKE knows several predefined properties, but user-defined ones are also possible.

A property is a key-value pair, whereby the key as well as the value must be a string. This restriction is necessary to be able to embed the properties into XML. If another data type has to be handled an encoding to and from string must be realized. It’s also possible to create a property, which extends further more properties.

For example, a property for an atomic class can be created as follows:

<StringClass name="customStringClass">
   <Property name="testProperty">
      <Property name="valueOne">1</Property>
      <Property name="valueTwo" value="2"/>
   </Property>
</StringClass>

Here, a property TestProperty is added, which contains two more properties: The property valueOne contains the value 1, the property valueTwo contains the value 2. It’s possible, to set a value using the parameter value. Otherwise, the value can be written in the inner tags. It’s not possible to set both values. In this case, an exception will be thrown.

If a property contains other properties, a value for this property can only be given by using the value parameter. Other inputs will be ignored.

To create this property during runtime, the following code would be used:

StringClass stringClass = ModelFactory.getDefaultModel().getClass(StringClass.CLASS_NAME);
StringClass customStringClass = (StringClass) stringClass.createSubclass("customStringClass");

stringClass.addProperty("testProperty", null);
stringClass.addProperty("valueOne", "1");
stringClass.addProperty("valueTwo", "2");

customStringClass.finishEditing();

To get the value of a property afterwards, the command getProperty(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:

stringClass.removeProperty("valueOne");
stringClass.addProperty("valueOne", "5");

There is also the possibility to set properties for aggregate classes. This is described here.