title logo

BMdocument syntax basis

A BMdocument describing a hierarchy of Java Beans uses two basic construction:

The creation of a component of class 'X', expressed by:

<bean class="X">
   ... component initialization
</bean>

And the setting of a property 'Y', expressed by:

<property name="Y">
  ... property value
</property>

A basic layout displaying a string in a JTextField Swing component is expressed by:

<!-- construction of a JLabel -->
<bean class="javax.swing.JLabel">
  <!-- setting of the text property
       the construct used is a short way
       to initialize a property            -->
  <property name="text" value="Hello"/>
</bean>

The syntax above has to be compared with the html equivalent:

<p>hello</p>

Three lines of code has to be written where only one line is sufficent in html. At a first glance, this verbosity can appear as a disadvantage. However, this is linked to the expressiveness and the power of the syntax used. All the instructions highlighted above can indeed be freely combined to create complex structures.

As an example, one may want to create a small interface allowing a user to enter its name into a text field. With Java Beans components, the easiest way to proceed is to create a JPanel composed of a JLabel initialized with the prompt "your name:" and a JTextField initialized with a default string. This is expressed by the following XML piece of code:

<!-- construction of the JPanel -->
<bean class="javax.swing.JPanel">
  <!-- construction of the JLabel -->
  <bean class="javax.swing.JLabel" action="add">
    <property name="text" value="your name: "/>
  </bean>
  <!-- construction of the JTextField -->
  <bean class="javax.swing.JTextField" action="add">
    <property name="text" value="your name here"/>
  </bean>
</bean>

The same way that HTML can be constructed from a XML source document using a transformation language like XSLT, the XML representation of components can be the result of a similar transformation. The process is very similar and the amount of work needed is quite comparable. This is illustrated in the example below:

Let's consider the following extremly simple XML document

<?xml version='1.0' encoding='UTF-8'?>
<doc>
  <message>Hello World !!!</message>
</doc>

The content of the 'message' element may be displayed and edited with a graphical bean. The 'JTextField' swing component for example. However, we need a way to indicate that the content of the JTextField component reflects the data specified in the 'message' element of the source XML document. This is expressed with a XSLT script wich generates a bean markup document where updatable fields are extracted from a source document. In our example, the XSLT document may be the following :

<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www-sop.inria.fr/lemme/bo/1.0"
  version="1.0">
<xsl:template match="message">
  <bean class="javax.swing.JTextField">
    <property name="text">
      <string>
        <xsl:value-of select="."/>
      </string>
    </property>
    <listener name="action"/>
  </bean>
</xsl:template
</xsl:stylesheet>

The template which matches the 'message' element of the source document generates the code needed to express the creation of the graphical component. The text property of the JTextField is initialized with the data extracted from the source document by using the special xslt tag 'value-of'.

On the screen, an editable text field initialized with the text "Hello World !!!" is displayed

snapshot of the component

Ketuk keeps the links between beans and source document assuring that every modification of the data made on a bean can be reflected back to its originating location. The beans shall alert the BMProcessor of the changes made by sending modification events. The notification of listener that have to be placed on components is specified by the special tag <listener name="event_name"/> which inform the processor to listen for event of type event_name. In the code specified above, the processor reacts at every action events ; i.e. when a return key is pressed for example.

blank horizontal line
Made with CSS Valid XHTML 1.0! Valid CSS! Copyright © 2000 INRIA, Dyade, Bull
Created by Claude Pasquier