title logo

Dealing with bean's hierarchy

Additions and Insertions

In a Bean Markup document, the hierarchy of Java Beans is specified by the usage of the tag <add> or by setting the attribute action to the value add in the description of a bean element. These instructions inform the processor that a component must be included into another one but one needs a way to concretly express how the inclusion is performed.

This is expressed by the use of adders. The adders are methods which known how to perform inclusions. They are called when an add instruction is encountered. For example, the addition of an object assignable to the class java.awt.Component into an object from the class java.awt.Container, is described by the following adder:

  /**
   * Adder for an object of class Component into a Container
   *
   *  @param parent    the container of the component
   *  @param comp      the component to add
   **/
  public void add(Container parent, Component comp) {
    parent.add(comp);
  }

While the insertion of an object into a vector will be described by:

  /**
   * Adder for an object at a specified position into a Vector
   *
   *  @param parent           the Vector where to add the object
   *  @param obj              the object to add
   *  @param index            the position where to add the object
   **/
  public void add(Vector parent, Object obj, int index) {
    parent.insertElementAt(obj, index);
  }

The choice of the method depends of the number of parameters and the type of these parameters. This feature, which is not possible with the Java language is handled by the Java Multimethod Framework implementing multi-polymorphism in java.

The class where the adders are defined and the name of the adders must be registered with the following description placed into the configuration file:

<register type="adder"
          method="add"
          class="fr.inria.ketuk.Adders"/>

Deletion and Changes

When the Java Beans hierarchy is first created, the ketuk application must be capable of adding and inserting elements. But, during the edition of the document, deletion and/or replacements may also need to be performed.

This is why Removers and Replacers should be declared. The principle is identical to the Adders. Several methods, each one handling a special case of change or deletion, has to be defined and registered in the XML configuration file. Common remove and replace operations are respectively defined in fr.inria.ketuk.Removers and fr.inria.ketuk.Replacers and registered with the following:.

<register type="remover"
          method="remove"
          class="fr.inria.ketuk.Removers"/>

<register type="replacer"
          method="replace"
          class="fr.inria.ketuk.Replacers"/>
blank horizontal line
Made with CSS Valid XHTML 1.0! Valid CSS! Copyright © 2000 INRIA, Dyade, Bull
Created by Claude Pasquier