Thursday, September 17, 2009

Roma Framework and the Virtual Objects

Yesterday night I've committed in the Roma's SVN (revision: 4479) source repository the first version of Virtual Objects. Virtual Objects are like POJO, but built dinamically just using a descriptor, in this case a XML file. The XSD is the same of Roma XML annotations but now allows to specify the field type and in future declaring inheritance and other stuff.

Action implementation can be written using any scripting language is supported by JSR 223, Javascript in primis.

Roma treats Virtual Objects in the same way of POJO, so you can define an Employee at the fly in this way:


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<class xmlns="http://www.romaframework.org/xml/roma" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
xsd:schemaLocation="http://www.romaframework.org/xml/roma http://www.romaframework.org/schema/v2/roma.xsd">
<aspects>
<view>
<form>
<area name="main" type="column">
<area name="fields" size="2" type="grid" />
<area name="actions" type="row" />
</area>
</form>
</view>
</aspects>
<fields>
<field name="id" type="Integer" />
<field name="name" type="String" />
<field name="surname" type="String" />
<field name="born" type="Date" />
<field name="age" type="Integer">
<aspects>
<view enabled="false" />
</aspects>
</field>
<field name="salary" type="Float" />
</fields>
<actions>
<action name="refresh">
<aspects>
<scripting>
org.romaframework.core.Roma.objectChanged(me);
</scripting>
</aspects>
</action>
<action name="print">
<aspects>
<scripting>
print(age);
</scripting>
</aspects>
</action>
<action name="login">
<aspects>
<scripting>
print('Login...');
org.romaframework.frontend.RomaFrontend.flow().forward("ProjectLogin");
</scripting>
</aspects>
</action>
</actions>
<events>
<event name="show">
<aspects>
<scripting>
<![CDATA[
age=32;
Roma.fieldChanged(me, ["age"]);
]]>
</scripting>
</aspects>
</event>
</events>
</class>


And this is the result:
Note that changes to the XML files are loaded in real-time enabling a real productive development (and production why not) environment.

No comments: