@@alt@@
Openode Tools

SourceForge Logo

Openode

Xengine

Introduction

Xengine renders TXT files against Java Objects.

I just needed something that would allow me a to send very fast the static style data of the Java Graphical Objects to the OutputStream but with incrusted Java Objects Information...all at runtime...and I insist: very, very fast. Xengine is perhaps one of the simplest and more powerful things I've done. In the beginning I designed(and developed) a fair complex tool that allowed for example Styles Inheritance, Tags referencing...and so on...

I did that this way bacause I was trying to provide inside Xengine too much visual logic possibilities, either from the static definition or the processing point of view...After providing the software to some collegues they told me that defining a style was a quite hard job...yes very powerful but very difficult to use!! Ok lets make that simple then.

An Xengine style consist on plain text, yes, plain text, no XML, why ? basically for two reasons: first I dont need XML to edit HTML or whatever (I need HTML Editors) and secondly I need xengine to be very fast, extremelly fast...

Xengine is a tool that generates bytes to an outputstream from a text but inserting in between information coming from a Java Object, therefore we need a directive to indicate what information to extract from the Object, this is <xen:pd property="name"/>. Whenever xengine finds this directive executes a getName() method call against the Object using reflection, and puts the result in the OutputStream...It is like a Java Bean Property.

But this is not enough, why ? In many ocasions you cannot return the information like this because that means you have to keep it in a variable, and this may not be possible due to performace/resources reasons...imagine a SQL Query for example...So what to do? easy: lets leave the responsability to the Java Object...The <xen:pc name="name"/> will simple call the follwoing XRenderer Interface method passing the name specified in the tag and the OutputStream...then the Object can write there whatever it needs to..:

public interface XRenderer{
void render(String name, OutputStream out);
}

Lets see a Xengine style example:

<INPUT TYPE="TEXT" CLASS ="FieldCaptionFONT" NAME="<xen:pd property="clientObjectName" />" VALUE="<xen:pd property="text" />" SIZE="<xen:pd property="size" />" MAXLENGTH="<xen:pd property="MaxLength" />" <xen:pd property="eventsHandlerCode" />/>

Performance

Xengine has to be very fast, so much that the time of processing the styles is the time the Java Objects take to provide the data plus the time of writing it to the OutputStream...

In order to make xengine fast the styles are kept in memory and parsed only once generating a kind of microcode which is executed in a loop processing three types of instructions: send the bytes to the OutputStream(free style text), call a Java Object Method getXXX and put the result in the OutputStream(<xen:pd..) or call the render method...(<xen:pc..)

Regarding the writing to the OutputStream issue, for example, ASK uses a special implementation of the OutputStream abstract class: org.openode.ask.x.ByteOutputStream. This OutputStream uses a linked list of objects where the bytes are kept, and also has a pool for these lists so that they are reused...this way it is not necessary to create so many objects...This approach was taken to avoid System.arraycopy calls for every write in the OutputStream, instead only at the end the object packs the result creating an array for the total amount of bytes...