Hrrm, very quiet around here at the moment.  Just wanted to let you know
I've also written a test stub generator for records.  It just creates a test
stub for you, you then take that and fill it out to complete your test case.
Also started on a generator for documentation.  Now that I'm getting better
with XSL I can churn these out fairly quickly.

Regards,

Glen Stampoultzis
[EMAIL PROTECTED]
(03) 9753-6850
0402 835 458

----- Original Message -----
From: "Glen Stampoultzis" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, February 04, 2002 10:34 AM
Subject: POI Record Generator


>
>
> Call me pig-headed if you will but I've gone ahead and created the POI
> record generator proof of concept.  This is simply a XSLT with a little
> custom java code.  It will take an XML file describing the record
structure
> and produce a java program.  It currently couldn't be considered complete
> but it's not too far away.  This is the first real thing I've done with
XSLT
> so the code is probably a bit dodgy.  It would probably make more sense to
> have done the Java bits in JavaScript.
>
> The records you have been posted by me over the last few days have been
> written using this utility.
>
> There are three ways we could use this.
>
> The first option is that you simply write the XML, generate the class then
> code the rest by hand and never regenerate.  This advantage of this is
that
> it's low risk and the tool doesn't have to be perfect.  If it makes a
> mistake or can't handle certain situations you fix those bits manually.
>
> The second option is that you keep the XML file as the master copy of what
> the record looks like.  You generate the record and don't change the code
it
> generates.  To provide extra functionality you subclass.  This will
> definitely be necessary for the more complex records.  The advantage here
is
> that: you always have a nice clean XML description of how the record is
> structured; you reduce errors from manually introduced code; and you can
use
> the XML to potentially generate human readable documentation.  The main
> disadvantage is that the generator has to deal with more special cases.
>
> The final option is to use a combination of the previous options.  Manual
> tweaking (or completely manually written records) for tricky records and
> full generation for 'easier' records.  The main issue here is management
of
> what is fully generated and what is not.  That can be overcome however.
>
> What I am **NOT** proposing is that we scrap the existing records.  At
least
> not in the short to medium term.  I would simply like to use this method
for
> the chart records (of which there are a large number).  Potentially a
> similar scheme could be used for the word format (but I haven't looked
into
> that).
>
> So what does it look like?
>
> Here's an example of the Legend record in XML:
>
> <record id="0x1015" name="Legend" package="org.apache.poi.hssf.record">
>     <description>The legend record specifies the location of legend on a
> chart and it's overall size.</description>
>     <author>Glen Stampoultzis (gstamp at iprimus dot com dot au)</author>
>     <fields>
>         <field type="int" size="4" name="x position"/>
>         <field type="int" size="4" name="y position"/>
>         <field type="int" size="4" name="x size"/>
>         <field type="int" size="4" name="y size"/>
>         <field type="int" size="1" name="type">
>             <const name="bottom" value="0"/>
>             <const name="corner" value="1"/>
>             <const name="top" value="2"/>
>             <const name="right" value="3"/>
>             <const name="left" value="4"/>
>             <const name="not docked" value="7"/>
>         </field>
>         <field type="int" size="1" name="spacing">
>             <const name="close" value="0"/>
>             <const name="medium" value="1"/>
>             <const name="open" value="2"/>
>         </field>
>         <field type="int" size="2" name="options">
>             <bit number="0" name="auto position" description="set to true
if
> legend is docked"/>
>             <bit number="1" name="auto series" description="automatic
series
> distribution"/>
>             <bit number="2" name="auto pos x" description="x positioning
is
> done automatically"/>
>             <bit number="3" name="auto pos y" description="y positioning
is
> done automatically"/>
>             <bit number="4" name="vert" description="if true legend is
> vertical (otherwise it's horizonal)"/>
>             <bit number="5" name="contains data table" description="true
if
> the chart contains the data table"/>
>         </field>
>     </fields>
> </record>
>
>
> To bring this to production standard I will probably need to add some more
> fields for providing descriptions.  It directly output's the following
file:
>
> /* ====================================================================
>  * The Apache Software License, Version 1.1
>  *
>  * Copyright (c) 2002 The Apache Software Foundation.  All rights
>  * reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
>  * modification, are permitted provided that the following conditions
>  * are met:
>  *
>  * 1. Redistributions of source code must retain the above copyright
>  *    notice, this list of conditions and the following disclaimer.
>  *
>  * 2. Redistributions in binary form must reproduce the above copyright
>  *    notice, this list of conditions and the following disclaimer in
>  *    the documentation and/or other materials provided with the
>  *    distribution.
>  *
>  * 3. The end-user documentation included with the redistribution,
>  *    if any, must include the following acknowledgment:
>  *       "This product includes software developed by the
>  *        Apache Software Foundation (http://www.apache.org/)."
>  *    Alternately, this acknowledgment may appear in the software itself,
>  *    if and wherever such third-party acknowledgments normally appear.
>  *
>  * 4. The names "Apache" and "Apache Software Foundation" and
>  *    "Apache POI" must not be used to endorse or promote products
>  *    derived from this software without prior written permission. For
>  *    written permission, please contact [EMAIL PROTECTED]
>  *
>  * 5. Products derived from this software may not be called "Apache",
>  *    "Apache POI", nor may "Apache" appear in their name, without
>  *    prior written permission of the Apache Software Foundation.
>  *
>  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
>  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
>  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
>  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
>  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
>  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
>  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
>  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
>  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
>  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
>  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
>  * SUCH DAMAGE.
>  * ====================================================================
>  *
>  * This software consists of voluntary contributions made by many
>  * individuals on behalf of the Apache Software Foundation.  For more
>  * information on the Apache Software Foundation, please see
>  * <http://www.apache.org/>.
>  */
>
>
> package org.apache.poi.hssf.record;
>
>
>
> import org.apache.poi.util.BitField;
> import org.apache.poi.util.LittleEndian;
> import org.apache.poi.util.StringUtil;
>
> /**
>  * The legend record specifies the location of legend on a chart and it's
> overall size.
>  * @author Glen Stampoultzis (gstamp at iprimus dot com dot au)
>  */
> public class LegendRecord
>     extends Record
> {
>     public final static short      sid                             =
0x1015;
>     private  int        field_1_xPosition;
>     private  int        field_2_yPosition;
>     private  int        field_3_xSize;
>     private  int        field_4_ySize;
>     private  byte       field_5_type;
>     public final static byte        TYPE_BOTTOM                    = 0;
>     public final static byte        TYPE_CORNER                    = 1;
>     public final static byte        TYPE_TOP                       = 2;
>     public final static byte        TYPE_RIGHT                     = 3;
>     public final static byte        TYPE_LEFT                      = 4;
>     public final static byte        TYPE_NOT_DOCKED                = 7;
>     private  byte       field_6_spacing;
>     public final static byte        SPACING_CLOSE                  = 0;
>     public final static byte        SPACING_MEDIUM                 = 1;
>     public final static byte        SPACING_OPEN                   = 2;
>     private  short      field_7_options;
>     private BitField   autoPosition                               = new
> BitField(0xfffffffd);
>     private BitField   autoSeries                                 = new
> BitField(0x2);
>     private BitField   autoPosX                                   = new
> BitField(0x3);
>     private BitField   autoPosY                                   = new
> BitField(0x0);
>     private BitField   vert                                       = new
> BitField(0x1);
>     private BitField   containsDataTable                          = new
> BitField(0x6);
>
>
>     public LegendRecord()
>     {
>     }
>
>     /**
>      * Constructs a Legend record and sets its fields appropriately.
>      *
>      * @param short id must be 0x1015 or an exception
>      *              will be throw upon validation
>      * @param short size the size of the data area of the record
>      * @param byte[] data of the record (should not contain sid/len)
>      */
>
>     public LegendRecord(short id, short size, byte [] data)
>     {
>         super(id, size, data);
>     }
>
>     /**
>      * Constructs a Legend record and sets its fields appropriately.
>      *
>      * @param short id must be 0x1015 or an exception
>      *              will be throw upon validation
>      * @param short size the size of the data area of the record
>      * @param byte[] data of the record (should not contain sid/len)
>      * @param offset of the record's data
>      */
>
>     public LegendRecord(short id, short size, byte [] data, int offset)
>     {
>         super(id, size, data, offset);
>     }
>
>     protected void validateSid(short id)
>     {
>         if (id != sid)
>         {
>             throw new RecordFormatException("Not a Legend record");
>         }
>     }
>
>     protected void fillFields(byte [] data, short size, int offset)
>     {
>         field_1_xPosition               = LittleEndian.getInt(data, 0 +
> offset);
>         field_2_yPosition               = LittleEndian.getInt(data, 4 +
> offset);
>         field_3_xSize                   = LittleEndian.getInt(data, 8 +
> offset);
>         field_4_ySize                   = LittleEndian.getInt(data, 12 +
> offset);
>         field_5_type                    = data[ 16 + offset ];
>         field_6_spacing                 = data[ 17 + offset ];
>         field_7_options                 = LittleEndian.getShort(data, 18 +
> offset);
>
>     }
>
>     public String toString()
>     {
>         StringBuffer buffer = new StringBuffer();
>
>         buffer.append("[Legend]\n");
>
>         buffer.append("    .xPosition            = ")
>             .append(Integer.toHexString(getXPosition()))
>             .append(" (").append(getXPosition()).append(" )\n");
>
>         buffer.append("    .yPosition            = ")
>             .append(Integer.toHexString(getYPosition()))
>             .append(" (").append(getYPosition()).append(" )\n");
>
>         buffer.append("    .xSize                = ")
>             .append(Integer.toHexString(getXSize()))
>             .append(" (").append(getXSize()).append(" )\n");
>
>         buffer.append("    .ySize                = ")
>             .append(Integer.toHexString(getYSize()))
>             .append(" (").append(getYSize()).append(" )\n");
>
>         buffer.append("    .type                 = ")
>             .append(Integer.toHexString(getType()))
>             .append(" (").append(getType()).append(" )\n");
>
>         buffer.append("    .spacing              = ")
>             .append(Integer.toHexString(getSpacing()))
>             .append(" (").append(getSpacing()).append(" )\n");
>
>         buffer.append("    .options              = ")
>             .append(Integer.toHexString(getOptions()))
>             .append(" (").append(getOptions()).append(" )\n");
>         buffer.append("         .autoPosition             =
> ").append(isAutoPosition()).append('\n');
>         buffer.append("         .autoSeries               =
> ").append(isAutoSeries()).append('\n');
>         buffer.append("         .autoPosX                 =
> ").append(isAutoPosX()).append('\n');
>         buffer.append("         .autoPosY                 =
> ").append(isAutoPosY()).append('\n');
>         buffer.append("         .vert                     =
> ").append(isVert()).append('\n');
>         buffer.append("         .containsDataTable        =
> ").append(isContainsDataTable()).append('\n');
>
>         buffer.append("[/Legend]\n");
>         return buffer.toString();
>     }
>
>     public int serialize(int offset, byte[] data)
>     {
>         LittleEndian.putShort(data, 0 + offset, sid);
>         LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() -
> 4));
>
>         LittleEndian.putInt(data, 4 + offset, field_1_xPosition);
>         LittleEndian.putInt(data, 8 + offset, field_2_yPosition);
>         LittleEndian.putInt(data, 12 + offset, field_3_xSize);
>         LittleEndian.putInt(data, 16 + offset, field_4_ySize);
>         data[ 20 + offset ] = field_5_type;
>         data[ 21 + offset ] = field_6_spacing;
>         LittleEndian.putShort(data, 22 + offset, field_7_options);
>
>         return getRecordSize();
>     }
>
>     /**
>      * Size of record (exluding 4 byte header)
>      */
>     public int getRecordSize()
>     {
>         return 4 + 4 + 4 + 4 + 1 + 1 + 2;
>     }
>
>     public short getSid()
>     {
>         return this.sid;
>     }
>
>
>     /**
>      * Get the x position field for the Legend record.
>      */
>     public int getXPosition()
>     {
>         return field_1_xPosition;
>     }
>
>     /**
>      * Set the x position field for the Legend record.
>      */
>     public void setXPosition(int field_1_xPosition)
>     {
>         this.field_1_xPosition = field_1_xPosition;
>     }
>
>     /**
>      * Get the y position field for the Legend record.
>      */
>     public int getYPosition()
>     {
>         return field_2_yPosition;
>     }
>
>     /**
>      * Set the y position field for the Legend record.
>      */
>     public void setYPosition(int field_2_yPosition)
>     {
>         this.field_2_yPosition = field_2_yPosition;
>     }
>
>     /**
>      * Get the x size field for the Legend record.
>      */
>     public int getXSize()
>     {
>         return field_3_xSize;
>     }
>
>     /**
>      * Set the x size field for the Legend record.
>      */
>     public void setXSize(int field_3_xSize)
>     {
>         this.field_3_xSize = field_3_xSize;
>     }
>
>     /**
>      * Get the y size field for the Legend record.
>      */
>     public int getYSize()
>     {
>         return field_4_ySize;
>     }
>
>     /**
>      * Set the y size field for the Legend record.
>      */
>     public void setYSize(int field_4_ySize)
>     {
>         this.field_4_ySize = field_4_ySize;
>     }
>
>     /**
>      * Get the type field for the Legend record.
>      *
>      * @return  One of
>      *        TYPE_BOTTOM
>      *        TYPE_CORNER
>      *        TYPE_TOP
>      *        TYPE_RIGHT
>      *        TYPE_LEFT
>      *        TYPE_NOT_DOCKED
>      */
>     public byte getType()
>     {
>         return field_5_type;
>     }
>
>     /**
>      * Set the type field for the Legend record.
>      *
>      * @param field_5_type
>      *        One of
>      *        TYPE_BOTTOM
>      *        TYPE_CORNER
>      *        TYPE_TOP
>      *        TYPE_RIGHT
>      *        TYPE_LEFT
>      *        TYPE_NOT_DOCKED
>      */
>     public void setType(byte field_5_type)
>     {
>         this.field_5_type = field_5_type;
>     }
>
>     /**
>      * Get the spacing field for the Legend record.
>      *
>      * @return  One of
>      *        SPACING_CLOSE
>      *        SPACING_MEDIUM
>      *        SPACING_OPEN
>      */
>     public byte getSpacing()
>     {
>         return field_6_spacing;
>     }
>
>     /**
>      * Set the spacing field for the Legend record.
>      *
>      * @param field_6_spacing
>      *        One of
>      *        SPACING_CLOSE
>      *        SPACING_MEDIUM
>      *        SPACING_OPEN
>      */
>     public void setSpacing(byte field_6_spacing)
>     {
>         this.field_6_spacing = field_6_spacing;
>     }
>
>     /**
>      * Get the options field for the Legend record.
>      */
>     public short getOptions()
>     {
>         return field_7_options;
>     }
>
>     /**
>      * Set the options field for the Legend record.
>      */
>     public void setOptions(short field_7_options)
>     {
>         this.field_7_options = field_7_options;
>     }
>
>     /**
>      * Sets the auto position field value.
>      * set to true if legend is docked
>      */
>     public void setAutoPosition(boolean value)
>     {
>         autoPosition.setBoolean(field_7_options, value);
>     }
>
>     /**
>      * set to true if legend is docked
>      * @return  the auto position field value.
>      */
>     public boolean isAutoPosition()
>     {
>         return autoPosition.isSet(field_7_options);
>     }
>
>     /**
>      * Sets the auto series field value.
>      * automatic series distribution
>      */
>     public void setAutoSeries(boolean value)
>     {
>         autoSeries.setBoolean(field_7_options, value);
>     }
>
>     /**
>      * automatic series distribution
>      * @return  the auto series field value.
>      */
>     public boolean isAutoSeries()
>     {
>         return autoSeries.isSet(field_7_options);
>     }
>
>     /**
>      * Sets the auto pos x field value.
>      * x positioning is done automatically
>      */
>     public void setAutoPosX(boolean value)
>     {
>         autoPosX.setBoolean(field_7_options, value);
>     }
>
>     /**
>      * x positioning is done automatically
>      * @return  the auto pos x field value.
>      */
>     public boolean isAutoPosX()
>     {
>         return autoPosX.isSet(field_7_options);
>     }
>
>     /**
>      * Sets the auto pos y field value.
>      * y positioning is done automatically
>      */
>     public void setAutoPosY(boolean value)
>     {
>         autoPosY.setBoolean(field_7_options, value);
>     }
>
>     /**
>      * y positioning is done automatically
>      * @return  the auto pos y field value.
>      */
>     public boolean isAutoPosY()
>     {
>         return autoPosY.isSet(field_7_options);
>     }
>
>     /**
>      * Sets the vert field value.
>      * if true legend is vertical (otherwise it's horizonal)
>      */
>     public void setVert(boolean value)
>     {
>         vert.setBoolean(field_7_options, value);
>     }
>
>     /**
>      * if true legend is vertical (otherwise it's horizonal)
>      * @return  the vert field value.
>      */
>     public boolean isVert()
>     {
>         return vert.isSet(field_7_options);
>     }
>
>     /**
>      * Sets the contains data table field value.
>      * true if the chart contains the data table
>      */
>     public void setContainsDataTable(boolean value)
>     {
>         containsDataTable.setBoolean(field_7_options, value);
>     }
>
>     /**
>      * true if the chart contains the data table
>      * @return  the contains data table field value.
>      */
>     public boolean isContainsDataTable()
>     {
>         return containsDataTable.isSet(field_7_options);
>     }
>
>
> }  // END OF CLASS
>
>
>
>
>
>
> Here is the XSLT file.  It's pretty yuck as it's my first go at XSLT.
> Sorry.  I haven't included the Java code that comes with this but it's
> really not complex.
>
>
>
>
> <xsl:stylesheet version="1.0"
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>    xmlns:recutil="org.apache.poi.generator.RecordUtil"
>    xmlns:field="org.apache.poi.generator.FieldIterator"
>    xmlns:java="java" >
>
> <xsl:template match="record">
> /* ====================================================================
>  * The Apache Software License, Version 1.1
>  *
>  * Copyright (c) 2002 The Apache Software Foundation.  All rights
>  * reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
>  * modification, are permitted provided that the following conditions
>  * are met:
>  *
>  * 1. Redistributions of source code must retain the above copyright
>  *    notice, this list of conditions and the following disclaimer.
>  *
>  * 2. Redistributions in binary form must reproduce the above copyright
>  *    notice, this list of conditions and the following disclaimer in
>  *    the documentation and/or other materials provided with the
>  *    distribution.
>  *
>  * 3. The end-user documentation included with the redistribution,
>  *    if any, must include the following acknowledgment:
>  *       &quot;This product includes software developed by the
>  *        Apache Software Foundation (http://www.apache.org/).&quot;
>  *    Alternately, this acknowledgment may appear in the software itself,
>  *    if and wherever such third-party acknowledgments normally appear.
>  *
>  * 4. The names &quot;Apache&quot; and &quot;Apache Software
> Foundation&quot; and
>  *    &quot;Apache POI&quot; must not be used to endorse or promote
products
>  *    derived from this software without prior written permission. For
>  *    written permission, please contact [EMAIL PROTECTED]
>  *
>  * 5. Products derived from this software may not be called
> &quot;Apache&quot;,
>  *    &quot;Apache POI&quot;, nor may &quot;Apache&quot; appear in their
> name, without
>  *    prior written permission of the Apache Software Foundation.
>  *
>  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
>  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
>  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
>  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
>  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
>  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
>  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
>  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
>  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
>  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
>  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
>  * SUCH DAMAGE.
>  * ====================================================================
>  *
>  * This software consists of voluntary contributions made by many
>  * individuals on behalf of the Apache Software Foundation.  For more
>  * information on the Apache Software Foundation, please see
>  * &lt;http://www.apache.org/&gt;.
>  */
>
> <xsl:if test="@package">
> package <xsl:value-of select="@package"/>;
> </xsl:if>
>
>
> import org.apache.poi.util.BitField;
> import org.apache.poi.util.LittleEndian;
> import org.apache.poi.util.StringUtil;
>
> /**
>  * <xsl:value-of select="/record/description"/>
> <xsl:apply-templates select="author"/>
>  */
> public class <xsl:value-of select="@name"/>Record
>     extends Record
> {
>     public final static short      sid                             =
> <xsl:value-of select="@id"/>;
> <xsl:for-each select="//fields/field">    private  <xsl:value-of
> select="recutil:getType(@size,@type,10)"/><xsl:text>
> </xsl:text><xsl:value-of
select="recutil:getFieldName(position(),@name,0)"/>
> <xsl:if test="@default"> = <xsl:value-of select="@default"/></xsl:if>;
> <xsl:apply-templates select="./bit|./const"/>
> </xsl:for-each>
>
>     public <xsl:value-of select="@name"/>Record()
>     {
>     }
>
>     /**
>      * Constructs a <xsl:value-of select="@name"/> record and sets its
> fields appropriately.
>      *
>      * @param short id must be <xsl:value-of select="@id"/> or an
exception
>      *              will be throw upon validation
>      * @param short size the size of the data area of the record
>      * @param byte[] data of the record (should not contain sid/len)
>      */
>
>     public <xsl:value-of select="@name"/>Record(short id, short size, byte
> [] data)
>     {
>         super(id, size, data);
>     }
>
>     /**
>      * Constructs a <xsl:value-of select="@name"/> record and sets its
> fields appropriately.
>      *
>      * @param short id must be <xsl:value-of select="@id"/> or an
exception
>      *              will be throw upon validation
>      * @param short size the size of the data area of the record
>      * @param byte[] data of the record (should not contain sid/len)
>      * @param offset of the record's data
>      */
>
>     public <xsl:value-of select="@name"/>Record(short id, short size, byte
> [] data, int offset)
>     {
>         super(id, size, data, offset);
>     }
>
>     protected void validateSid(short id)
>     {
>         if (id != sid)
>         {
>             throw new RecordFormatException(&quot;Not a <xsl:value-of
> select="@name"/> record&quot;);
>         }
>     }
>
>     protected void fillFields(byte [] data, short size, int offset)
>     {
> <xsl:variable name="fieldIterator" select="field:new()"/>
> <xsl:for-each select="//fields/field">
> <xsl:text>        </xsl:text><xsl:value-of
> select="recutil:getFieldName(position(),@name,30)"/>  = <xsl:value-of
> select="field:fillDecoder($fieldIterator,@size,@type)"/>;
> </xsl:for-each>
>     }
>
>     public String toString()
>     {
>         StringBuffer buffer = new StringBuffer();
>
>         buffer.append("[<xsl:value-of select="@name"/>]\n");
> <xsl:apply-templates select="//field" mode="tostring"/>
>         buffer.append("[/<xsl:value-of select="@name"/>]\n");
>         return buffer.toString();
>     }
>
>     public int serialize(int offset, byte[] data)
>     {
>         LittleEndian.putShort(data, 0 + offset, sid);
>         LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() -
> 4));
> <xsl:variable name="fieldIterator" select="field:new()"/>
> <xsl:for-each select="//fields/field"><xsl:text>
>         </xsl:text><xsl:value-of
>
select="field:serialiseEncoder($fieldIterator,position(),@name,@size,@type)"
> />
> </xsl:for-each>
>
>         return getRecordSize();
>     }
>
>     /**
>      * Size of record (exluding 4 byte header)
>      */
>     public int getRecordSize()
>     {
> <xsl:variable name="fieldIterator" select="field:new()"/>
> <xsl:text>        return </xsl:text>
> <xsl:for-each select="//fields/field">
>     <xsl:value-of
> select="field:calcSize($fieldIterator,position(),@name,@size,@type)"/>
> </xsl:for-each>;
>     }
>
>     public short getSid()
>     {
>         return this.sid;
>     }
>
> <xsl:apply-templates select="//field" mode="getset"/>
> <xsl:apply-templates select="//field" mode="bits"/>
>
> }  // END OF CLASS
>
>
>
>
> </xsl:template>
>
> <xsl:template match = "field" mode="bits">
> <xsl:variable name="fieldNum" select="position()"/>
> <xsl:for-each select="bit">
>     /**
>      * Sets the <xsl:value-of select="@name"/> field value.
>      * <xsl:value-of select="@description"/>
>      */
>     public void set<xsl:value-of
> select="recutil:getFieldName1stCap(@name,0)"/>(boolean value)
>     {
>         <xsl:value-of
> select="recutil:getFieldName(@name,0)"/>.set<xsl:value-of
> select="recutil:getType1stCap(@size,@type,0)"/>Boolean(<xsl:value-of
> select="recutil:getFieldName($fieldNum,../@name,0)"/>, value);
>     }
>
>     /**
>      * <xsl:value-of select="@description"/>
>      * @return  the <xsl:value-of select="@name"/> field value.
>      */
>     public boolean is<xsl:value-of
> select="recutil:getFieldName1stCap(@name,0)"/>()
>     {
>         return <xsl:value-of
> select="recutil:getFieldName(@name,0)"/>.isSet(<xsl:value-of
> select="recutil:getFieldName($fieldNum,../@name,0)"/>);
>     }
> </xsl:for-each>
> </xsl:template>
>
> <xsl:template match = "bit" >    private BitField   <xsl:value-of
> select="recutil:getFieldName(@name,42)"/> = new BitField(<xsl:value-of
> select="recutil:getMask(@number)"/>);
> </xsl:template>
> <xsl:template match = "const">    public final static <xsl:value-of
> select="recutil:getType(../@size,../@type,10)"/><xsl:text>
> </xsl:text><xsl:value-of
select="recutil:getConstName(../@name,@name,30)"/>
> = <xsl:value-of select="@value"/>;
> </xsl:template>
>
> <xsl:template match = "const" mode="listconsts">
> <xsl:text>
>      *        </xsl:text>
> <xsl:value-of
> select="recutil:getConstName(../@name,@name,0)"/></xsl:template>
> <xsl:template match="field" mode="getset">
>     /**
>      * Get the <xsl:value-of select="@name"/> field for the <xsl:value-of
> select="../../@name"/> record.<xsl:if test="./const">
>      *
>      * @return  One of <xsl:apply-templates select="./const"
> mode="listconsts"/></xsl:if>
>      */
>     public <xsl:value-of select="recutil:getType(@size,@type,0)"/>
> get<xsl:value-of select="recutil:getFieldName1stCap(@name,0)"/>()
>     {
>         return <xsl:value-of
> select="recutil:getFieldName(position(),@name,0)"/>;
>     }
>
>     /**
>      * Set the <xsl:value-of select="@name"/> field for the <xsl:value-of
> select="../../@name"/> record.<xsl:if test="./const">
>      *
>      * @param <xsl:value-of
> select="recutil:getFieldName(position(),@name,0)"/>
>      *        One of <xsl:apply-templates select="./const"
> mode="listconsts"/></xsl:if>
>      */
>     public void set<xsl:value-of
> select="recutil:getFieldName1stCap(@name,0)"/>(<xsl:value-of
> select="recutil:getType(@size,@type,0)"/><xsl:text>
</xsl:text><xsl:value-of
> select="recutil:getFieldName(position(),@name,0)"/>)
>     {
>         this.<xsl:value-of
> select="recutil:getFieldName(position(),@name,0)"/> = <xsl:value-of
> select="recutil:getFieldName(position(),@name,0)"/>;
>     }
> </xsl:template>
>
> <xsl:template match="field" mode="tostring">
>         buffer.append("    .<xsl:value-of
> select="recutil:getFieldName(@name,20)"/> = ")<xsl:if test="@type !=
> 'string'">
>             .append(Integer.toHexString(get<xsl:value-of
> select="recutil:getFieldName1stCap(@name,0)"/>()))</xsl:if>
>             .append(" (").append(get<xsl:value-of
> select="recutil:getFieldName1stCap(@name,0)"/>()).append(" )\n");
> <xsl:apply-templates select="bit" mode="bittostring"/>
> </xsl:template>
>
> <xsl:template match="bit" mode="bittostring">        buffer.append("
> .<xsl:value-of select="recutil:getFieldName(@name,20)"/>     =
> ").append(is<xsl:value-of
> select="recutil:getFieldName1stCap(@name,20)"/>()).append('\n');
> </xsl:template>
>
> <xsl:template match="author">
>  * @author <xsl:value-of select="."/>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
>
> So please let me know what you think.  I will put it to a vote after
getting
> some feedback.
>
>
>
>
>
> Glen Stampoultzis
> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> Phone: +61 3 9753 6850
> Mobile: 0402 835 458
> ICQ: 62722370  AIM: FubbleWobble
>
>
>

Reply via email to