-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicky Bloor
committed
Aug 13, 2017
1 parent
09dbd89
commit d680249
Showing
3 changed files
with
355 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package nb.deser.support; | ||
|
||
import java.util.ArrayList; | ||
|
||
/*********************************************************** | ||
* Support class for serialization data parsing that holds | ||
* class data details that are required to enable object | ||
* properties and array elements to be read from the | ||
* stream. | ||
* | ||
* Written by Nicky Bloor (@NickstaDB). | ||
**********************************************************/ | ||
public class ClassDataDesc { | ||
/******************* | ||
* Properties | ||
******************/ | ||
private final ArrayList<ClassDetails> _classDetails; //List of all classes making up this class data description (i.e. class, super class, etc) | ||
|
||
/******************* | ||
* Construct the class data description object. | ||
******************/ | ||
public ClassDataDesc() { | ||
this._classDetails = new ArrayList<ClassDetails>(); | ||
} | ||
|
||
/******************* | ||
* Private constructor which creates a new ClassDataDesc and initialises it | ||
* with a subset of the ClassDetails objects from another. | ||
* | ||
* @param cd The list of ClassDetails objects for the new ClassDataDesc. | ||
******************/ | ||
private ClassDataDesc(ArrayList<ClassDetails> cd) { | ||
this._classDetails = cd; | ||
} | ||
|
||
/******************* | ||
* Build a new ClassDataDesc object from the given class index. | ||
* | ||
* This is used to enable classdata to be read from the stream in the case | ||
* where a classDesc element references a super class of another classDesc. | ||
* | ||
* @param index The index to start the new ClassDataDesc from. | ||
* @return A ClassDataDesc describing the classes from the given index. | ||
******************/ | ||
public ClassDataDesc buildClassDataDescFromIndex(int index) { | ||
ArrayList<ClassDetails> cd; | ||
|
||
//Build a list of the ClassDetails objects for the new ClassDataDesc | ||
cd = new ArrayList<ClassDetails>(); | ||
for(int i = index; i < this._classDetails.size(); ++i) { | ||
cd.add(this._classDetails.get(i)); | ||
} | ||
|
||
//Return a new ClassDataDesc describing this subset of classes | ||
return new ClassDataDesc(cd); | ||
} | ||
|
||
/******************* | ||
* Add a super class data description to this ClassDataDesc by copying the | ||
* class details across to this one. | ||
* | ||
* @param scdd The ClassDataDesc object describing the super class. | ||
******************/ | ||
public void addSuperClassDesc(ClassDataDesc scdd) { | ||
//Copy the ClassDetails elements to this ClassDataDesc object | ||
if(scdd != null) { | ||
for(int i = 0; i < scdd.getClassCount(); ++i) { | ||
this._classDetails.add(scdd.getClassDetails(i)); | ||
} | ||
} | ||
} | ||
|
||
/******************* | ||
* Add a class to the ClassDataDesc by name. | ||
* | ||
* @param className The name of the class to add. | ||
******************/ | ||
public void addClass(String className) { | ||
this._classDetails.add(new ClassDetails(className)); | ||
} | ||
|
||
/******************* | ||
* Set the reference handle of the last class to be added to the | ||
* ClassDataDesc. | ||
* | ||
* @param handle The handle value. | ||
******************/ | ||
public void setLastClassHandle(int handle) { | ||
this._classDetails.get(this._classDetails.size() - 1).setHandle(handle); | ||
} | ||
|
||
/******************* | ||
* Set the classDescFlags of the last class to be added to the | ||
* ClassDataDesc. | ||
* | ||
* @param classDescFlags The classDescFlags value. | ||
******************/ | ||
public void setLastClassDescFlags(byte classDescFlags) { | ||
this._classDetails.get(this._classDetails.size() - 1).setClassDescFlags(classDescFlags); | ||
} | ||
|
||
/******************* | ||
* Add a field with the given type code to the last class to be added to | ||
* the ClassDataDesc. | ||
* | ||
* @param typeCode The field type code. | ||
******************/ | ||
public void addFieldToLastClass(byte typeCode) { | ||
this._classDetails.get(this._classDetails.size() - 1).addField(new ClassField(typeCode)); | ||
} | ||
|
||
/******************* | ||
* Set the name of the last field that was added to the last class to be | ||
* added to the ClassDataDesc. | ||
* | ||
* @param name The field name. | ||
******************/ | ||
public void setLastFieldName(String name) { | ||
this._classDetails.get(this._classDetails.size() - 1).setLastFieldName(name); | ||
} | ||
|
||
/******************* | ||
* Set the className1 of the last field that was added to the last class to | ||
* be added to the ClassDataDesc. | ||
* | ||
* @param cn1 The className1 value. | ||
******************/ | ||
public void setLastFieldClassName1(String cn1) { | ||
this._classDetails.get(this._classDetails.size() -1).setLastFieldClassName1(cn1); | ||
} | ||
|
||
/******************* | ||
* Get the details of a class by index. | ||
* | ||
* @param index The index of the class to retrieve details of. | ||
* @return The requested ClassDetails object. | ||
******************/ | ||
public ClassDetails getClassDetails(int index) { | ||
return this._classDetails.get(index); | ||
} | ||
|
||
/******************* | ||
* Get the number of classes making up this class data description. | ||
* | ||
* @return The number of classes making up this class data description. | ||
******************/ | ||
public int getClassCount() { | ||
return this._classDetails.size(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package nb.deser.support; | ||
|
||
import java.util.ArrayList; | ||
|
||
/*********************************************************** | ||
* Support class for serialization data parsing that holds | ||
* details of a single class to enable class data for that | ||
* class to be read (classDescFlags, field descriptions). | ||
* | ||
* Written by Nicky Bloor (@NickstaDB). | ||
**********************************************************/ | ||
public class ClassDetails { | ||
/******************* | ||
* Properties | ||
******************/ | ||
private final String _className; //The name of the class | ||
private int _refHandle; //The reference handle for the class | ||
private byte _classDescFlags; //The classDescFlags value for the class | ||
private final ArrayList<ClassField> _fieldDescriptions; //The class field descriptions | ||
|
||
/******************* | ||
* Construct the ClassDetails object. | ||
* | ||
* @param className The name of the class. | ||
******************/ | ||
public ClassDetails(String className) { | ||
this._className = className; | ||
this._refHandle = -1; | ||
this._classDescFlags = 0; | ||
this._fieldDescriptions = new ArrayList<ClassField>(); | ||
} | ||
|
||
/******************* | ||
* Get the class name. | ||
* | ||
* @return The class name. | ||
******************/ | ||
public String getClassName() { | ||
return this._className; | ||
} | ||
|
||
/******************* | ||
* Set the reference handle of the class. | ||
* | ||
* @param handle The reference handle value. | ||
******************/ | ||
public void setHandle(int handle) { | ||
this._refHandle = handle; | ||
} | ||
|
||
/******************* | ||
* Get the reference handle. | ||
* | ||
* @return The reference handle value for this class. | ||
******************/ | ||
public int getHandle() { | ||
return this._refHandle; | ||
} | ||
|
||
/******************* | ||
* Set the classDescFlags property. | ||
* | ||
* @param classDescFlags The classDescFlags value. | ||
******************/ | ||
public void setClassDescFlags(byte classDescFlags) { | ||
this._classDescFlags = classDescFlags; | ||
} | ||
|
||
/******************* | ||
* Check whether the class is SC_SERIALIZABLE. | ||
* | ||
* @return True if the classDescFlags includes SC_SERIALIZABLE. | ||
******************/ | ||
public boolean isSC_SERIALIZABLE() { | ||
return (this._classDescFlags & 0x02) == 0x02; | ||
} | ||
|
||
/******************* | ||
* Check whether the class is SC_EXTERNALIZABLE. | ||
* | ||
* @return True if the classDescFlags includes SC_EXTERNALIZABLE. | ||
******************/ | ||
public boolean isSC_EXTERNALIZABLE() { | ||
return (this._classDescFlags & 0x04) == 0x04; | ||
} | ||
|
||
/******************* | ||
* Check whether the class is SC_WRITE_METHOD. | ||
* | ||
* @return True if the classDescFlags includes SC_WRITE_METHOD. | ||
******************/ | ||
public boolean isSC_WRITE_METHOD() { | ||
return (this._classDescFlags & 0x01) == 0x01; | ||
} | ||
|
||
/******************* | ||
* Check whether the class is SC_BLOCKDATA. | ||
* | ||
* @return True if the classDescFlags includes SC_BLOCKDATA. | ||
******************/ | ||
public boolean isSC_BLOCKDATA() { | ||
return (this._classDescFlags & 0x08) == 0x08; | ||
} | ||
|
||
/******************* | ||
* Add a field description to the class details object. | ||
* | ||
* @param cf The ClassField object describing the field. | ||
******************/ | ||
public void addField(ClassField cf) { | ||
this._fieldDescriptions.add(cf); | ||
} | ||
|
||
/******************* | ||
* Get the class field descriptions. | ||
* | ||
* @return An array of field descriptions for the class. | ||
******************/ | ||
public ArrayList<ClassField> getFields() { | ||
return this._fieldDescriptions; | ||
} | ||
|
||
/******************* | ||
* Set the name of the last field to be added to the ClassDetails object. | ||
* | ||
* @param name The field name. | ||
******************/ | ||
public void setLastFieldName(String name) { | ||
this._fieldDescriptions.get(this._fieldDescriptions.size() - 1).setName(name); | ||
} | ||
|
||
/******************* | ||
* Set the className1 of the last field to be added to the ClassDetails | ||
* object. | ||
* | ||
* @param cn1 The className1 value. | ||
******************/ | ||
public void setLastFieldClassName1(String cn1) { | ||
this._fieldDescriptions.get(this._fieldDescriptions.size() - 1).setClassName1(cn1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package nb.deser.support; | ||
|
||
/*********************************************************** | ||
* Support class for serialization data parsing that holds | ||
* details of a class field to enable the field value to | ||
* be read from the stream. | ||
* | ||
* Written by Nicky Bloor (@NickstaDB). | ||
**********************************************************/ | ||
public class ClassField { | ||
/******************* | ||
* Properties | ||
******************/ | ||
private final byte _typeCode; //The field type code | ||
private String _name; //The field name | ||
private String _className1; //The className1 property (object and array type fields) | ||
|
||
/******************* | ||
* Construct the ClassField object. | ||
* | ||
* @param typeCode The field type code. | ||
******************/ | ||
public ClassField(byte typeCode) { | ||
this._typeCode = typeCode; | ||
this._name = ""; | ||
this._className1 = ""; | ||
} | ||
|
||
/******************* | ||
* Get the field type code. | ||
* | ||
* @return The field type code. | ||
******************/ | ||
public byte getTypeCode() { | ||
return this._typeCode; | ||
} | ||
|
||
/******************* | ||
* Set the field name. | ||
* | ||
* @param name The field name. | ||
******************/ | ||
public void setName(String name) { | ||
this._name = name; | ||
} | ||
|
||
/******************* | ||
* Get the field name. | ||
* | ||
* @return The field name. | ||
******************/ | ||
public String getName() { | ||
return this._name; | ||
} | ||
|
||
/******************* | ||
* Set the className1 property of the field. | ||
* | ||
* @param cn1 The className1 value. | ||
******************/ | ||
public void setClassName1(String cn1) { | ||
this._className1 = cn1; | ||
} | ||
} |