Utils

Utils #

This page contains the following content:

Utils summarizes several utilities that are used by other CAKE components.

CAKE Composition Manager #

The components of the system are mostly defined by Java interfaces. If a component needs access to another component, only the interfaces should be used and never an implementation. This makes it possible to change an implementation of a component without changing any other component. For example, if the logger should be realized with a database backend, only the implementation changed and not the interface. Consequently, no other component must be adapted to the new backend.

Factories #

The factory classes are the connections between the interfaces and the implementations that should be used. If an object of an interface is needed a request to the corresponding factory is sent which returns the object.

Beside the methods of the Factory interface contains each factory two kind of static methods:

  • get-methods: Each method that begins with “get” reuses an existing object. Therefore, most of these methods beginning with “getDefault” to emphasize this issue.
  • new-methods: Each method that begins with “new” creates a new object. In some factories it is necessary to specify the newly created object as the default object thus the new-method exist with a boolean parameter. The boolean parameter specifies if the newly created object should be set as the default object. An example of the different kinds of method can be found in the data model factory, see ModelFactory.

For further information to the special factories, have a look at the more detailed descriptions, e.g. IOFactory.

Composition Manager #

The task of the composition managers is to connect the factories with the concrete implementation. Which implementation should be used is defined in an XML file. For example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Composition SYSTEM "composition.dtd">

<Composition>
  <Factory name="data_model" class="de.uni_trier.wi2.procake.data.model.ModelFactory">
    <Implementation class="de.uni_trier.wi2.procake.data.model.impl.ModelFactoryObjectImpl">
      <Parameter name="modelName" value="default"/>
      <Parameter name="modelPath" value="/de/uni_trier/procake/model.xml"/>
    </Implementation>
  </Factory>	
</Composition>

Each factory can get one or more implementations which must implement the interface FactoryObjectImplementation and a special interface defined in the corresponding component, e.g., ModelFactoryObject for the model factory. Additionally, each implementation can get several parameter, e.g. the path of the model file.

Of course, the composition manager should be called before anything else to build the system. A typical code fragment to build the system look like this:

if (CompositionManager.isSystemBuild() == false) {
CompositionManager cm = new CompositionManager();
cm.setConfigurationFile("/etc/composition.xml");
cm.build();
}