Primitive Values
Primitives, Complex-types, and Arrays

The DPML Metro platform provides support for primitive (e.g. int, long, short, float, boolean, etc.), and complex object return types, arrays, maps, and usage of default arguments within a Context interface.

Component Example


Demo.java A component that demonstrates the a broad spectrum of context types (primitives, arrays and complex types).
DemoTestCase.java The testcase.

The deployment solution for the above component is defined in the following component definition (additional context entry directives are presented in red).

<component xmlns="dpml:metro" class="org.acme.Demo" name="demo">
    <entry key="color" method="RED"/>
    <entry key="anotherColor">
      <param class="int" value="100"/>
      <param class="int" value="200"/>
      <param class="int" value="0"/>
    <entry key="integer" value="42"/>
    <entry key="short" value="19"/>
    <entry key="long" value="1042"/>
    <entry key="byte" value="9"/>
    <entry key="double" value="32"/>
    <entry key="float" value="9.813"/>
    <entry key="char" value="x"/>
    <entry key="boolean" value="true"/>
    <entry key="file" value="${work}"/>
    <entry key="tempFile" value="${temp}"/>
    <entry key="URI" value="${uri}"/>
    <entry key="name" value="${name}"/>
    <entry key="path" value="${path}"/>
    <entry key="names">
      <param value="fred"/>
      <param value="george"/>
      <param value="mary"/>
    <map key="colors">
      <entry key="red" class="java.awt.Color" method="RED"/>
      <entry key="white" class="java.awt.Color" method="WHITE"/>
      <entry key="blue" class="java.awt.Color" method="BLUE"/>
Testing the component

The following testcase log output demonstrates runtime support for primitive types, complex type construction, and arrays.

    [junit] Executing forked test.
    [junit] Running org.acme.test.DemoTestCase
    [junit] [25598] [INFO   ] (demo): color: java.awt.Color[r=255,g=0,b=0]
    [junit] [25598] [INFO   ] (demo): anotherColor: java.awt.Color[r=100,g=200,b=0]
    [junit] [25598] [INFO   ] (demo): integer: 42
    [junit] [25598] [INFO   ] (demo): short: 19
    [junit] [25598] [INFO   ] (demo): long: 1042
    [junit] [25598] [INFO   ] (demo): byte: 9
    [junit] [25598] [INFO   ] (demo): double: 32.0
    [junit] [25598] [INFO   ] (demo): float: 9.813
    [junit] [25598] [INFO   ] (demo): char: x
    [junit] [25598] [INFO   ] (demo): boolean: true
    [junit] [25598] [INFO   ] (demo): file: C:\dev\osm\trunk\tutorial\components\examples
    [junit] [25598] [INFO   ] (demo): temp: C:\DOCUME~1\MCCONN~1\LOCALS~1\Temp
    [junit] [25598] [INFO   ] (demo): uri: component:/demo
    [junit] [25598] [INFO   ] (demo): name: demo
    [junit] [25598] [INFO   ] (demo): path: /demo
    [junit] [25598] [INFO   ] (demo): names: 3
    [junit] [25598] [INFO   ] (demo): optionalColor: java.awt.Color[r=0,g=0,b=255]
    [junit] [25598] [INFO   ] (demo): optionalInteger: 42
    [junit] [25598] [INFO   ] (demo): optionalShort: 9
    [junit] [25598] [INFO   ] (demo): optionalLong: 21
    [junit] [25598] [INFO   ] (demo): optionalByte: 3
    [junit] [25598] [INFO   ] (demo): optionalDouble: 0.0010
    [junit] [25598] [INFO   ] (demo): optionalFloat: 3.142
    [junit] [25598] [INFO   ] (demo): optionalChar: #
    [junit] [25598] [INFO   ] (demo): optionalBoolean: false
    [junit] [25598] [INFO   ] (demo): optionalFile: C:\dev\osm\trunk\tutorial\components\examples
    [junit] [25598] [INFO   ] (demo): optionalURI: file:/C:/dev/osm/trunk/tutorial/components/examples/
    [junit] [18231] [INFO   ] (demo): color (blue): java.awt.Color[r=0,g=0,b=255]
    [junit] [18231] [INFO   ] (demo): color (white): java.awt.Color[r=255,g=255,b=255]
    [junit] [18231] [INFO   ] (demo): color (red): java.awt.Color[r=255,g=0,b=0]
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.937 sec

This tutorial demonstrates the ability with Metro to map string-based arguments (presented in XML attributes) into primitive, arrays, and constructed values within a context directive. The next tutorial will introduce the notion of composition of a component which in-turn introduces the potential for references between nested components.