UIEvolutin Inc.
UJML Language Reference
Including Files

UJML can include other files in the current file during compilation.

UJML provides two ways to include files in the current file during compilation. You can create entity include files and include them using the XML include syntax. See Entity Include Files. Also UJML provides the include element, which copies state machines from partition files into the current file. See State Machines, include

Both methods allow you to create chunks of reusable code which you can easily include in your applications. In the first case, you can declare entities which contain constants, fragments of UJML code, and even entire function or event declarations. This is all done using the standard XML entity syntax and is limited to the things XML allows you to do. 

The second kind of include is provided by the UJML language and consists of copying entire state machines into the current file at the place where the include element is located.

Includes occur at compile time

Unlike running or linking to compiled files, including files occurs at compile time. See Running Files, Linking Files. This means that the included code is included in the byte code for the current file. See Byte Code Files. Neither include method will bring everything from the include file into the compiled file, instead only those things in the include file which the compiled file references are actually compiled into byte code.

Using includes

You can reduce the amount of coding needed for a new application by putting commonly used functionality into appropriate include files. Entity include files are good for small scraps and fragments of UJML code and literal values, while state machines are good for creating a package of related variables, functions, and state transitions. 

In both cases, careful construction of the include files allows you to switch between different, but similar, include files at compile time in order to change the look, feel, and even behavior in your application without changing the application code. So long as the different sets of include files provide similarly named elements and entities with similar functionality, the process will be transparent.

The following example shows how to copy an entity include file. It is part of the padbuttons.ujms sample.

<!DOCTYPE ujml PUBLIC "-//UIEVOLUTION//DTD UJML 2.0//EN"
"http://www.uievolution.com/dtd/ujml-2.0.dtd" [
    <!ENTITY % include SYSTEM "uicinclude.ent">
    %include;
    <!ENTITY PAD_BUTTON_COUNT "12">
    <!ENTITY BUTTON_UP "0">
    <!ENTITY BUTTON_DOWN "1">
]>

 

The following example is an entity declaration for some related variables. It is part of the venclude.ent sample.

 <!ENTITY RECTANGLE '
    <!-- Rectangle declaration. -->
    <var name="mRectX" type="int"/>
    <var name="mRectY" type="int"/>
    <var name="mRectWidth" type="int"/>
    <var name="mRectHeight" type="int"/>
'>

 

The following example shows how to include two state machines from different partition files. It is part of the visualelements.ujml sample.

<state-machines>
    <include file="/../components/background.ujms" state-machine="Background" />
    <include file="/../components/scrollmenu.ujms" state-machine="ScrollingMenu" />
</state-machines>
Copyright (c) 2000-2007 UIEvolution, Inc. All rights reserved.
What do you think about this topic? Send feedback!