FileDocCategorySizeDatePackage
EscherRecord.javaAPI DocApache Poi 3.0.18739Mon Jan 01 12:39:40 GMT 2007org.apache.poi.ddf

EscherRecord

public abstract class EscherRecord extends Object
The base abstract record from which all escher records are defined. Subclasses will need to define methods for serialization/deserialization and for determining the record size.
author
Glen Stampoultzis

Fields Summary
private short
options
private short
recordId
Constructors Summary
public EscherRecord()
Create a new instance

    
Methods Summary
public java.lang.Objectclone()
Escher records may need to be clonable in the future.

        throw new RuntimeException( "The class " + getClass().getName() + " needs to define a clone method" );
    
public voiddisplay(java.io.PrintWriter w, int indent)
The display methods allows escher variables to print the record names according to their hierarchy.

param
w The print writer to output to.
param
indent The current indent level.

        for (int i = 0; i < indent * 4; i++) w.print(' ");
        w.println(getRecordName());
    
protected intfillFields(byte[] data, org.apache.poi.ddf.EscherRecordFactory f)
Delegates to fillFields(byte[], int, EscherRecordFactory)

see
#fillFields(byte[], int, org.apache.poi.ddf.EscherRecordFactory)

        return fillFields( data, 0, f );
    
public abstract intfillFields(byte[] data, int offset, org.apache.poi.ddf.EscherRecordFactory recordFactory)
The contract of this method is to deserialize an escher record including it's children.

param
data The byte array containing the serialized escher records.
param
offset The offset into the byte array.
param
recordFactory A factory for creating new escher records.
return
The number of bytes written.

public org.apache.poi.ddf.EscherRecordgetChild(int index)
Returns the indexed child record.

        return (EscherRecord) getChildRecords().get(index);
    
public java.util.ListgetChildRecords()

return
Returns the children of this record. By default this will be an empty list. EscherCotainerRecord is the only record that may contain children.
see
EscherContainerRecord

 return Collections.EMPTY_LIST; 
public shortgetInstance()
Returns the instance part of the option record.

return
The instance part of the record

        return (short) ( options >> 4 );
    
public shortgetOptions()

return
The options field for this record. All records have one.

        return options;
    
public shortgetRecordId()
Return the current record id.

return
The 16 bit record id.

        return recordId;
    
public abstract java.lang.StringgetRecordName()
Subclasses should return the short name for this escher record.

public abstract intgetRecordSize()
Subclasses should effeciently return the number of bytes required to serialize the record.

return
number of bytes

public booleanisContainerRecord()
Determine whether this is a container record by inspecting the option field.

return
true is this is a container field.

        return (options & (short)0x000f) == (short)0x000f;
    
protected intreadHeader(byte[] data, int offset)
Reads the 8 byte header information and populates the options and recordId records.

param
data the byte array to read from
param
offset the offset to start reading from
return
the number of bytes remaining in this record. This may include the children if this is a container.

        EscherRecordHeader header = EscherRecordHeader.readHeader(data, offset);
        options = header.getOptions();
        recordId = header.getRecordId();
        return header.getRemainingBytes();
    
public abstract intserialize(int offset, byte[] data, org.apache.poi.ddf.EscherSerializationListener listener)
Serializes the record to an existing byte array.

param
offset the offset within the byte array
param
data the data array to serialize to
param
listener a listener for begin and end serialization events. This is useful because the serialization is hierarchical/recursive and sometimes you need to be able break into that.
return
the number of bytes written.

public byte[]serialize()
Serializes to a new byte array. This is done by delegating to serialize(int, byte[]);

return
the serialized record.
see
#serialize(int, byte[])

        byte[] retval = new byte[getRecordSize()];

        serialize( 0, retval );
        return retval;
    
public intserialize(int offset, byte[] data)
Serializes to an existing byte array without serialization listener. This is done by delegating to serialize(int, byte[], EscherSerializationListener).

param
offset the offset within the data byte array.
param
data the data array to serialize to.
return
The number of bytes written.
see
#serialize(int, byte[], org.apache.poi.ddf.EscherSerializationListener)

        return serialize( offset, data, new NullEscherSerializationListener() );
    
public voidsetChildRecords(java.util.List childRecords)
Sets the child records for this record. By default this will throw an exception as only EscherContainerRecords may have children.

param
childRecords Not used in base implementation.

 throw new IllegalArgumentException("This record does not support child records."); 
public voidsetOptions(short options)
Set the options this this record. Container records should have the last nibble set to 0xF.

        this.options = options;
    
public voidsetRecordId(short recordId)
Sets the record id for this record.

        this.recordId = recordId;