UIEvolutin Inc.
UJML Language Reference
Literals and Constants

Literals are text giving an explicit value of a specific data type.

In UJML literals are text which describes an explicit value. Literals may be assigned to variables, passed to parameters in function calls, or used as values and attributes for UJML tag elements. See Variables, Parameters, XML Tags. Constants are literals specified with an identifier, where the identifier is replaced with the actual literal value at compile time. The data type of a literal is determined by its context and its format. See Data Types. In UJML, there are three types of literals: boolean, integer, and string (detailed below).

UJML is XML

UJML is specified using XML and all the contents of a UJML file, including all literals and constants, must be valid in an XML file. See Anatomy of a UJML Application. All UJML tag elements, attributes and literal values are valid XML by design.

UJML, XML, and Unicode

XML is character set independent and allows you to specify the character set encoding used. In practice this is completely transparent to UJML because conversion to the internal UJML Unicode representation occurs at compile time. Whatever character set issues exist do so because these are issues with XML and are the same for any form of XML file.

UJML constants are XML entities

In many languages, constants are a special case of unchanging variable. Because UJML is specified with XML, constants in UJML are simply XML entities. See XML Entities. UJML provides many predefined entities for various purposes, including constant values. See Entities. You can also specify your own entity constants and use them throughout your UJML application. In cases where you are using the same value in many different places, you would specify the value once when you define the entity and then use the entity instead. Later, if you needed to change the value, you need only change it one time—in the definition. 

XML entities are defined using the 'ENTITY' meta tag. For example, '<!ENTITY SALUTATION "Hello World!">'. XML entities are used by preceding them with an ampersand and following them with a semicolon. For example '<text>&SALUTATION;</text>'. When used in script blocks entity constants should be treated exactly like the text they represent. For example you would put quotes around the entity when assigning it to a string variable like 's = "&SALUTATION;"'. 

Boolean literals 

Boolean literals are of the data type boolean and consist of the values true and false.

Example 
Context 
b = false; 
The boolean variable 'b' is assigned the literal value 'false'. 
showMessage(true, "Hello World!", 10, 50); 
The function 'showMessage' is called, passing the Boolean literal value 'true' and other literal values. 
<transition value="true"> 
A UJML element (a transition element for a state change) that will capture state transitions whenever the associated boolean state variable value changes to 'true'

Reference literals 

Reference literals are of the data type reference. At this time there is only one reference literal, the value null, which means the reference value does not point to any component instance. See reference data type, Interface Types, Components.

Example 
Context 
componentRef = null; 
The reference variable 'componentRef' is assigned the literal value 'null', clearing any current component instance pointer from the variable. 
Integer literals

Integer literals are of the data type int. They are simply numbers without any punctuation, or hexadecimal values using the characters '0x' followed by the hexadecimal number. For example, to set a variable to the maximum int value you could use the statement 'i = 2147483647;' or the statement 'i = 0x7FFFFFFF;'. A negative value is indicated with a leading dash '-'. For example, to set a variable to the value -32, you could use the statement 'i = -32'.

Example 
Context 
i = 128; 
The int variable 'i' is assigned the literal value 128
showMessage(true, "Hello World!", 10, 50); 
The function 'showMessage' is called, passing the integer literal values '10' and '50' and other literal values. 
<transition value="-5"> 
A UJML element (a transition element for a state change) that will capture state transitions whenever the associated int state variable value changes to '-5'
<fg>0xFF3366FF</fg> 
A UJML element (a foreground color property) is given the hexadecimal value '0xFF3366FF', which is the same as the decimal value '4281558783'. 
String literals

String literals are of the data type string. Strings in literals in UJML always consist of Unicode characters with integer code point values from 0x0001 to 0xFFFF. See _getCharacterCode(). String literals in script blocks are surrounded with quotes, which may be either single or double quotes as long as the same quote is used to end the string literal as is used to start it. You cannot embed a quote of the same kind as used to delimit a string in the string so 's = "A and B"' is valid, but 's = "A" and "B"' is not.

Example 
Context 
s = "Foo"; 
The string variable 's' is assigned the literal value 'Foo'. 
showMessage(true, 'Hello World!', 10, 50); 
The function 'showMessage' is called, passing the string literal value 'Hello World!' and other literal values. Note that single quotes are used here instead of double quotes. 
<transition value="Bar"> 
A UJML element (a transition element for a state change) that will capture state transitions whenever the associated string state variable value changes to 'Bar'. 
<text>He said "Hello World!" She said "Don't talk to me."</text> 
A UJML element (a text property) is given a string value. Note that all quotes are simply part of the string in this context because it is not a script block. 
More on quotes in string literals

If you need to use quotes inside a string literal, you have several options. For string literals in XML element tag values, you have no limitations and can mix quotes however you like. This applies to all XML tags, including the XML scripting elements. See XML Scripts

For XML element attributes and string literals in script blocks, you need to use either single or double quotes around your literal value, so you can use one quote style to delimit the string and another as part of the string. See Script Blocks. If your application needs to include text with two different quote styles in the same string value, you can use the _strcat() function to combine different strings. For example, s = _strcat("'this' and", '"that"');'.

The following example shows how to declare a boolean variable. It is part of the assignment.ujml sample.

<var name="mBooleanVar" type="boolean"/>

 

The following example shows how to set the variable declared above to a boolean literal. It is part of the assignment.ujml sample.

mBooleanVar = true;

 

The following example shows how to declare an int variable. It is part of the assignment.ujml sample.

<var name="mIntVar" type="int"/>

 

The following example shows how to set the variable declared above to a numeric literal and then uses it in a mathematical expression. It is part of the assignment.ujml sample.

mIntVar = 512;
mIntVar = 512 * 2;

 

The following example shows how to declare a string variable. It is part of the assignment.ujml sample.

<var name="mStringVar" type="string"/>

 

The following example shows how to set the variable declared above to a string literal. Note that this is not a number because it is surrounded by double quotes. It is part of the assignment.ujml sample.

mStringVar = "-1024";

 

The following example shows how to display an edit box with an x-caption element containing a string literal. Note the use of a predefined XML entity constant in the _getIntProperty() function call. It is part of the edit.ujml sample.

<edit var="mText">
    <width><eval>_getIntProperty(&_PROPERTY_INT_SCREEN_WIDTH;)</eval></width>
    <x-caption>Enter text and press F2.</x-caption>
</edit>
Copyright (c) 2000-2007 UIEvolution, Inc. All rights reserved.
What do you think about this topic? Send feedback!