JICE Examples

1. Hello World
2. Hello World 2
3. Hello World 3
4. Printing a message to System.out
5. Formatting a Date with a DateFormat
6. Using attributes class and parameters
7. Referencing objects through id
8. Accessing external parameters
9. Creating a JFrame
10. Creating a JFrame 2
11. How to create primitives
12. How to create primitives 2
13. Creating an int[]-array
14. Creating a java.lang.String[]-array
15. Creating a List manually
16. Using the list type

Example 1: Hello World

Hello World Creates a String-object with the value 'Hello World', and returns the String - the value of the top-most element will always be returned.

<?xml version="1.0" encoding="UTF-8"?>
<message xmlns="http://www.jicengine.org/jic/1.0"  instance="'Hello World!'"/>

Example 2: Hello World 2

Hello World 2 Again, creates a String-object with the value 'Hello World'. This time the String-value is specified in the CDATA-section of the element. it is referenced in the attribute 'instance' with the name 'CDATA'.

The String-object is returned againg.

<?xml version="1.0" encoding="UTF-8"?>
<message xmlns="http://www.jicengine.org/jic/1.0"  instance="CDATA">Hello World!</message>

Example 3: Hello World 3

Hello World 3 Same as previous, except that there is no 'instance'-attribute. it isn't needed because the elements with CDATA have a default 'instance'-attribute.

<?xml version="1.0" encoding="UTF-8"?>
<message xmlns="http://www.jicengine.org/jic/1.0">Hello World!</message>

Example 4: Printing a message to System.out

Printing a message to System.out this example prints a message to the System.out. it returns nothing (actually null), because the top-most element has an action that "consumes" the value.

<?xml version="1.0" encoding="UTF-8"?>
<print-message xmlns="http://www.jicengine.org/jic/1.0"  action="out.println(message)">
  <message>Hello World!</message>
  <out  instance="java.lang.System.out"/>
</print-message>

Example 5: Formatting a Date with a DateFormat

Formatting a Date with a DateFormat Creates a DateFormat with a pattern and a locale and formats the current date into a string.

the formatted Date-string is returned, as it is the value of the top-most element.

<?xml version="1.0" encoding="UTF-8"?>
<formattedDate xmlns="http://www.jicengine.org/jic/1.0"  instance="dateFormat.format(date)">
  <dateFormat  instance="new java.text.SimpleDateFormat(pattern,locale)">
    <pattern>dd.MM.yyyy HH:mm:ss z</pattern>
    <locale  instance="new java.util.Locale(language,country)">
      <language>fi</language>
      <country>FI</country>
    </locale>
  </dateFormat>
  <date  instance="new java.util.Date()"/>
</formattedDate>

Example 6: Using attributes class and parameters

Using attributes class and parameters Functionally same as previous, except that 'class' and 'parameters' attributes are used instead of 'instance'.

the value of the 'instance' attribute is derived from the 'class' and 'parameters' attributes.

the code is more declarative this way, although longer.

<?xml version="1.0" encoding="UTF-8"?>
<formattedDate xmlns="http://www.jicengine.org/jic/1.0"  instance="dateFormat.format(date)">
  <dateFormat  class="java.text.SimpleDateFormat"  parameters="pattern,locale">
    <pattern>dd.MM.yyyy HH:mm:ss z</pattern>
    <locale  class="java.util.Locale"  parameters="language,country">
      <language>fi</language>
      <country>FI</country>
    </locale>
  </dateFormat>
  <date  class="java.util.Date"/>
</formattedDate>

Example 7: Referencing objects through id

Referencing objects through id Functionally same as the two previous examples, but this time the 'id'-attribute is used.

The DateFormat and Date objects are tagged with an id.

formattedDate-element uses these ids for referencing the DateFormat and Date. the elements don't have to be inside the formattedDate-element.

<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://www.jicengine.org/jic/1.0"  type="block"  instance="formattedDate">
  <dateFormat  class="java.text.SimpleDateFormat"  parameters="pattern,locale"  id="dateFormat">
    <pattern>dd.MM.yyyy HH:mm:ss z</pattern>
    <locale  class="java.util.Locale"  parameters="language,country">
      <language>fi</language>
      <country>FI</country>
    </locale>
  </dateFormat>
  <date  class="java.util.Date"  id="timestamp"/>
  <formattedDate  instance="dateFormat.format(timestamp)"/>
</container>

Example 8: Accessing external parameters

Accessing external parameters Demonstrates how to access external parameters that are given to the JICE-builder when the file is processed.

The snippet prints a message to System.out. However, the message is declared to be overridable by a parameter named 'message'. If the parameter isn't available, the default message inside the element is used. Otherwise, the value of the parameter is outputted to System.out.

<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://www.jicengine.org/jic/1.0"  action="out.println(message)">
  <message  overridable-by="message">Default message</message>
  <out  instance="java.lang.System.out"/>
</container>

Example 9: Creating a JFrame

Creating a JFrame creates and displays a JFrame. The JFrame has a title, one label, background and a size.

<?xml version="1.0" encoding="UTF-8"?>
<jframe xmlns="http://www.jicengine.org/jic/1.0"  action="this.show()"  instance="new javax.swing.JFrame('This is a JFrame')">
  <contentPane  instance="PARENT.getContentPane()">
    <label  action="PARENT.add(this)"  instance="new javax.swing.JLabel('This is a JLabel')"/>
    <opaque  action="PARENT.setOpaque(true)"/>
    <background  action="PARENT.setBackground(this)"  instance="new java.awt.Color(200,90,90)"/>
  </contentPane>
  <size  action="PARENT.setSize(this)"  instance="new java.awt.Dimension(300,300)"/>
</jframe>

Example 10: Creating a JFrame 2

Creating a JFrame 2 functionally same as 'JFrame1'. this time all the "shortcuts" available in JICE are used: attributes 'action' and 'instance' aren't used that much any more, and more data is in cdata. elements opaque, background and size don't use the 'action'-attribute anymore, because the names of these elements imply the setXXX()-methods to be used.

<?xml version="1.0" encoding="UTF-8"?>
<jframe xmlns="http://www.jicengine.org/jic/1.0"  action="this.show()"  class="javax.swing.JFrame"  parameters="title">
  <title>This is a JFrame</title>
  <contentPane  instance="PARENT.getContentPane()">
    <label  action="add(this)"  class="javax.swing.JLabel"  parameters="text">
      <text>This is a JLabel</text>
      <opaque  type="boolean">false</opaque>
    </label>
    <opaque  type="boolean">true</opaque>
    <background  type="color">200,90,90</background>
  </contentPane>
  <size  class="java.awt.Dimension"  parameters="w,h">
    <w  type="int">300</w>
    <h  type="int">300</h>
  </size>
</jframe>

Example 11: How to create primitives

How to create primitives

<?xml version="1.0" encoding="UTF-8"?>
<primitives xmlns="http://www.jicengine.org/jic/1.0"  type="block"  instance="message">
  <message>This demonstrates the use of primitives in expressions.</message>
  <int  instance="1234"/>
  <double  instance="12.34"/>
  <double2  instance="12.34D"/>
  <boolean  instance="true"/>
  <string  instance="'a string'"/>
  <long  instance="1234L"/>
  <float  instance="12.34F"/>
  <char>char type not yet available</char>
</primitives>

Example 12: How to create primitives 2

How to create primitives 2

<?xml version="1.0" encoding="UTF-8"?>
<primitives xmlns="http://www.jicengine.org/jic/1.0"  type="block"  instance="message">
  <message>This demonstrates how to create primitives with types.</message>
  <int  type="int">1234</int>
  <double  type="double">12.34</double>
  <boolean  type="boolean">true</boolean>
  <string>a string</string>
  <long>long type not yet available</long>
  <float>float type not yet available</float>
</primitives>

Example 13: Creating an int[]-array

Creating an int[]-array

<?xml version="1.0" encoding="UTF-8"?>
<array xmlns="http://www.jicengine.org/jic/1.0"  class="int[]"  type="array">
  <e  type="int">1</e>
  <e  type="int">2</e>
  <e  type="int">3</e>
  <e  type="int">4</e>
</array>

Example 14: Creating a java.lang.String[]-array

Creating a java.lang.String[]-array

<?xml version="1.0" encoding="UTF-8"?>
<array xmlns="http://www.jicengine.org/jic/1.0"  class="java.lang.String[]"  type="array">
  <e>Element 1</e>
  <e>Element 2</e>
  <e>Element 3</e>
  <e>Element 4</e>
</array>

Example 15: Creating a List manually

Creating a List manually ints are actually handled as java.lang.Integers, so we can add them into the list. they are converted back to ints if necessary.

<?xml version="1.0" encoding="UTF-8"?>
<list xmlns="http://www.jicengine.org/jic/1.0"  instance="new java.util.ArrayList()">
  <e  action="PARENT.add(this)"  instance="1"/>
  <e  action="PARENT.add(this)"  instance="2"/>
  <e  action="PARENT.add(this)"  instance="3"/>
  <e  action="PARENT.add(this)"  instance="4"/>
</list>

Example 16: Using the list type

Using the list type Creating a List by using type "list". ints are actually handled as java.lang.Integers, so we can add them into the list.

<?xml version="1.0" encoding="UTF-8"?>
<list xmlns="http://www.jicengine.org/jic/1.0"  class="java.util.ArrayList"  type="list">
  <e  instance="1"/>
  <e  instance="2"/>
  <e  instance="3"/>
  <e  instance="4"/>
</list>