|
|
![]() |
|
|||||
|
|||||||
|
|
|||||||
| Proposal
for Revised Syntax for <peers>
Send comments to Cara Struble (cara@harmonia.com)
Why Is a Revision Needed? There are several deficiencies in past UIML2 DTDs, up to UIML2_0d.dtd:
There are two styles of events used by platforms:
Method 2 is used in Java 1.1 and later. We adopt the Java model of requiring a Listener entity that defines how events are handled on behalf of a <part>. (If there exists a target language for UIML that uses Method 2 and also uses a concept entirely different than listeners, then UIML will need modification.) In this case, a Listener class defines how events are handled. In UIML, the association between the event mouseClicked and the actions to perform in response is made by a <rule>. The UIML user is not aware of the Listener or Event classes involved. Thus UIML must contain a rich enough syntax to define the following:
New <d-…> Syntax Earlier we referred to the <mparam> tag as having a strange name. What should we call it? Also, earlier we said that <attribute> was a silly tag because it defined a property (and could be confused for an attribute of a markup language tag). What should it be renamed? The proposed answer is to use these names: <d-property> Now once we have introduced "d-", it makes sense to ask whether it should be used in any construct that is declaring or defining something used elsewhere. This leads us to changing <component> to <d-component> (since the element makes a component declaration). We also propose changing <method> to <d-method>, since the body is giving the declaration of a method prototype. And of course we’ll use <d-class> (to define a class) instead of using <class>. Every class attribute that appears in any UIML element is defined by a <d-class> element. We also stated that there must be a construct in UIML to associate listeners with components for event method 2 above. Hence we propose adding to UIML a new tag, <listener>. Summary of Syntax to Define Events and Listeners For HTML: Shown below is a skeleton of a <presentation> element for mapping UIML to HTML: <presentation name="HTML">
<d-class name="OnClick" used-in-tag="event" .../>
<d-class name="Button" used-in-tag="part" .../>
<event name="OnClick">
</d-class>
</presentation>
The above UIML says
that one of the events in HTML is OnClick, and that a <part>
whose class is Button can receive an OnClick event. For Java/Swing: Shown below is a skeleton of a <presentation> element for mapping UIML to Java AWT/Swing: <presentation name="AWT-Swing">
<d-class name="ActionEvent" used-in-tag="event" ...>
<d-method name="actionCommand" ...>
</d-class>
<d-class name="ActionListener" used-in-tag="listener" ...>
<d-method name="actionPerformed" ...>
<d-param type="ActionEvent"/>
</d-method>
</d-class>
<d-class name="JButton" used-in-tag="part" .../>
<listener class="ActionListener" ...>
</d-class>
</presentation>
The above UIML says that one of the events in Java AWT/Swing is ActionEvent, one of the listeners is ActionListener, ActionListener has a method named actionPerformed that processes ActionEvents, and that events for a <part> whose class is JButton are handled by a listener named ActionListener. Detailed Example for HTML <presentation> Shown below is a fragment of a <presentation> element for mapping UIML to HTML. The single HTML tag <presentation name="HTML"> <!-- ========== Define event classes ==================== --> <d-class name="onClick" used-in-tag="event"
maps-type="attribute"
maps-to="onClick"/>
<!-- ========== Define part classes ===================== --> <d-class name="Button" used-in-tag="part"
maps-type="tag"
maps-to="html:INPUT">
<!-- ======== Define properties of part class Button == --> <d-property name="type" maps-type="attribute" maps-to="NAME">
<d-param type="String">BUTTON</d-param>
</d-property>
<d-property name="value" maps-type="attribute" maps-to="VALUE"> <d-param type="String"/> </d-property> <!-- ======== List which events are valid for part class JButton --> <event class="onClick"/> </d-class> </presentation> The above fragment illustrates that for each element in the target platform that should be a UIML class, you need to specify four things:
When writing rules, the class attribute of an event element in a condition can be any of the names listed in an <event> element that is associated with the <part> in the <presentation> section. In the above example, a Button's events include OnClick. This is illustrated by the following example:
Shown below is a fragment of a <presentation> element for mapping UIML to Java. A Swing JButton is considered. <presentation name="AWT-Swing"> <!-- ==================== Define event classes ==================== --> <d-class name="MouseEvent" used-in-tag="event"
maps-type="class"
maps-to="java.awt.event.MouseEvent">
<d-method name="source" maps-to="getSource"
return-type="java.lang.Object"/>
<d-method name="id" maps-to="getId"
return-type="int"/>
<d-method name="clickCount" maps-to="getClickCount"
return-type="int"/>
<d-method name="point" maps-to="getPoint"
return-type="java.awt.Point"/>
<d-method name="X" maps-to="getX"
return-type="int"/>
<d-method name="Y" maps-to="getY"
return-type="int"/>
<d-method name="isPopupTrigger" maps-to="getIsPopupTrigger"
return-type="boolean"/>
</d-class>
... <!-- ==================== Define event listener classes ============ --> <d-class name="MouseListener" used-in-tag="listener"
maps-type="class"
maps-to="java.awt.event.MouseListener">
<d-class name="JButton" used-in-tag="part"
maps-type="class"
maps-to="javax.swing.JButton">
<!-- =========== Define properties of part class JButton == = --> <d-property name="text" maps-type="setMethod"
maps-to="setText">
<d-param type="java.lang.String"/>
</d-property>
<d-property name="text" return-type="java.lang.String"
maps-type="getMethod"
maps-to="getText"/>
</d-property>
<d-property name="size" maps-type="setMethod"
maps-to="setSize">
<d-param name="width" type="int"/>
<d-param name="height" type="int"/>
</d-property>
... <!-- ====== List which events are valid for part class JButton === --> <listener class="ActionListener" attacher="addActionListener"/>
<listener class="AncestorListener" attacher="addAncestorListener"/>
<listener class="ChangeListener" attacher="addChangeListener" />
<listener class="ComponentListener" attacher="addComponentListener"/>
<listener class="ContainerListener" attacher="addContainerListener"/>
<listener class="FocusListener" attacher="addFocusListener" />
<listener class="HierarchyListener" attacher="addHeirarchyListener"/>
<listener class="HierarchyBoundsListener" attacher="addHeirarchyBoundsListener"/>
<listener class="InputMethodListener" attacher="addInputMethodListener"/>
<listener class="ItemListener" attacher="addItemListener"/>
<listener class="KeyListener" attacher="addKeyListener"/>
<listener class="MouseListener" attacher="addMouseListener"/>
<listener class="MouseMotionListener" attacher="addMouseMotionListener"/>
</d-class> </presentation> Comparing the above fragment to the HTML example, there are these differences:
When writing rules, the class attribute of an event element in a condition uses a dotted notation consisting of the form <listener class name>.<method class name>. The <listener class name> is a class name defined by a <d-class used-in-tag="listener"> element, such as MouseListener in the UIML example above. The <method class name> is a method name defined in a <d-method> element that is a child of the <d-class used-in-tag="listener"> element, such as mouseClicked in the UIML above. This is illustrated by the following example:
So far, we’ve discussed the <presentation> element. We’ve proposed changes such as renaming <component> to <d-component>. Here is an example, from examples\EventsAndCalls\EventCounter2.uiml in the UIML Java Renderer distribution uiml2jr-0.4a.zip posted on www.harmonia.com. <logic>
The fragment above says that there is
an external object reached by name com.universalit.example.Counter2. This
object is given the name Counter in the UIML document. The components
has two methods, named count and reset in the UIML document.
These map, respectively, to count and setCount in com.universalit.example.Counter2.
Each returns a value of type int, where the meaning of int
is whatever meaning ascribed by the language in which com.universalit.example.Counter2
is implemented. Finally, count takes no arguments when called,
and setCount takes one argument, an int. Summary of Proposed Changes
Following is the proposal for the revised DTD. <?xml version="1.0" encoding="ISO-8859-1"?> <!-- ==================== Content Models ======================= --> <!-- 'uiml' is the root element of a UIML document. --> <!ELEMENT uiml (head?, template*, interface?, peers?)> <!-- The 'head' element is meant to contain metadata about the UIML document. You can specify metadata using the meta tag, this is similar to the head/meta from HTML. --> <!ELEMENT head (meta)*> <!ELEMENT meta EMPTY> <!ATTLIST meta name NMTOKEN #REQUIRED content CDATA #REQUIRED> <!-- The 'peers' element contains information that defines how a UIML interface component is mapped to the target platform's rendering technology and to the backend logic. --> <!ELEMENT peers (presentation|logic)*> <!ATTLIST peers name NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional"> <!-- The 'interface' element describes a user interface in terms of presentation widgets, component structure and behavior specifications. --> <!ELEMENT interface (structure|style|content|behavior)*> <!ATTLIST interface name NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional"> <!-- The 'template' element enables reuse of UIML elements. When an element appears inside a template element it can sourced by another element with the same tag. --> <!ELEMENT template (behavior|constant|content|d-class|d-component|interface |logic|part|peers|presentation|property|rule |script|structure|style)> <!ATTLIST template name NMTOKEN #IMPLIED> <!-- Peer related elements --> <!-- The 'presentation' element specifies the mapping between abstract interface parts and platform dependent widgets. --> <!ELEMENT presentation (d-class|d-component)*> <!ATTLIST presentation name NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional"> <!-- The 'logic' element specifies the connection between the interface and the backend application, including support for scripting. --> <!ELEMENT logic (d-component*)> <!ATTLIST logic name NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional"> <!-- The 'd-component' element declares the interface to logic components in the backend (e.g., a class in an object oriented language or a function in a scripting langauge) --> <!ELEMENT d-component (d-method)*> <!ATTLIST d-component name NMTOKEN #REQUIRED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional" maps-to CDATA #REQUIRED location CDATA #IMPLIED> <!--
The 'd-class' element declares any name used in the "class"
attribute of any element in UIML.
-->
<!ELEMENT d-class (d-method*, d-property*, event*, listener*)>
<!ATTLIST d-class
name NMTOKEN #REQUIRED
source CDATA #IMPLIED
how (append|cascade|replace) "replace"
export (hidden|optional|required) "optional"
used-in-tag (event|listener|part) #REQUIRED
maps-type (tag|class) #REQUIRED
maps-to CDATA #REQUIRED>
<!-- The 'd-property' element associates a specific property with the methods that set and get its value. --> <!ELEMENT d-property (d-method*, d-param*)> <!ATTLIST d-property name NMTOKEN #REQUIRED maps-type (attribute|getMethod|setMethod) #REQUIRED maps-to CDATA #REQUIRED return-type CDATA #IMPLIED> <!-- The 'method' element describes a routine that forms part of a component's callable interface (i.e., the component's "API"). --> <!ELEMENT d-method (d-param*, script?)> <!ATTLIST d-method name NMTOKEN #REQUIRED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional" maps-to CDATA #REQUIRED return-type CDATA #IMPLIED> <!-- 'd-param' denotes either a single formal parameter to a callable routine or attribute in a markup language --> <!ELEMENT d-param (CDATA)?> <!ATTLIST d-param name NMTOKEN #IMPLIED type CDATA #IMPLIED> <!-- The 'script' element contains data passed to an embedded scripting engine. The type specifies the scripting language (see HTML4.0) --> <!ELEMENT script (#PCDATA)> <!ATTLIST script name NMTOKEN #IMPLIED type NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional"> <!-- Interface related elements --> <!-- The 'structure' element describes the initial logical relationships between the components (i.e., the "part"s) that comprise the user interface. --> <!ELEMENT structure (part*)> <!ATTLIST structure name NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional"> <!-- A 'part' element describes a conceptually complete component of the user interface. --> <!ELEMENT part (style?, content?, behavior?, part*)> <!ATTLIST part name NMTOKEN #IMPLIED class NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional"> <!-- A 'style' element is composed of one or more 'property' elements, each of which specifies how a particular aspect of an interface component's presentation is to be presented. --> <!ELEMENT style (property*)> <!ATTLIST style name NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional"> <!-- A 'property' element is typically used to set a specified property for some interface component (or alternatively, a class of interface components), using the element's character data content as the value. If the 'operation' attribute is given as "get", the element is equivalent to a property-get operation, the value of which may be "returned" as the content for an enclosing 'property' element. --> <!ELEMENT property (#PCDATA|constant|property|reference|call)*> <!ATTLIST property name NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional" part-name NMTOKEN #IMPLIED part-class NMTOKEN #IMPLIED event-name NMTOKEN #IMPLIED event-class NMTOKEN #IMPLIED call-name NMTOKEN #IMPLIED call-class NMTOKEN #IMPLIED> <!-- A 'reference' may be thought of as a property-get operation, where the "property" to be read is a 'constant' element defined in the UIML document's 'content' section. --> <!ELEMENT reference EMPTY> <!ATTLIST reference constant-name NMTOKEN #REQUIRED> <!-- The 'content' element is composed of one or more 'constant' elements, each of which specifies some fixed value. --> <!ELEMENT content (constant*)> <!ATTLIST content name NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional"> <!-- 'constant' elements may be hierarchically structured. --> <!ELEMENT constant (constant*)> <!ATTLIST constant name NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional" model CDATA #IMPLIED value CDATA #IMPLIED> <!-- The 'behavior' element gives one or more "rule"s that specifies what 'action' is to be taken whenever an associated 'condition' becomes TRUE. --> <!ELEMENT behavior (rule*)> <!ATTLIST behavior name NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional"> <!ELEMENT rule (condition,action)?> <!ATTLIST rule name NMTOKEN #IMPLIED source CDATA #IMPLIED how (append|cascade|replace) "replace" export (hidden|optional|required) "optional"> <!-- At the moment, "rule"s may be associated with two types of conditions: (1) whenever some expression is equal to some other expression; and (2) whenever some event is triggered and caught. --> <!ELEMENT condition (equal|event)> <!ELEMENT equal (event,(constant|property|reference))> <!ELEMENT action ((property|call)*, event?)> <!ELEMENT call (param*)> <!ATTLIST call name NMTOKEN #IMPLIED class NMTOKEN #IMPLIED> <!-- 'event' denotes one of two things: (1) Inside <condition>, denotes that when the named event is fired, the condition should be evaluated. (2) Inside <d-class>, denotes that the named event can occur for the part class named by the <d-class>. --> <!ELEMENT event EMPTY> <!ATTLIST event name NMTOKEN #IMPLIED class NMTOKEN #IMPLIED part-name NMTOKEN #IMPLIED part-class NMTOKEN #IMPLIED> <!-- 'param' denotes a single actual parameter to a call-able routine. --> <!ELEMENT param (#PCDATA|property|reference|call)*> <!ATTLIST param name NMTOKEN #IMPLIED> <!-- 'listener' denotes that a name defined with d-class <!ELEMENT listener EMPTY> <!ATTLIST listener class NMTOKEN #IMPLIED attacher CDATA #IMPLIED> © 1999-2000 UIML.org (all rights reserved) |