home *** CD-ROM | disk | FTP | other *** search
- package netscape.util;
-
- import java.io.IOException;
- import java.io.OutputStream;
-
- public class Archiver implements Encoder {
- Archive archive;
- ArchivingStack stack = new ArchivingStack();
- IdHashtable idHash = new IdHashtable(false);
- Object currentObject;
- ClassTable currentTable;
- int currentId;
- int currentColumnCount;
- int currentRow;
- int currentColumn;
-
- public Archiver(Archive var1) {
- this.archive = var1;
- }
-
- public Archive archive() {
- return this.archive;
- }
-
- public static void writeObject(OutputStream var0, Object var1) throws IOException, CodingException {
- Archive var2 = new Archive();
- Archiver var3 = new Archiver(var2);
- var3.archiveRootObject(var1);
- var2.write(var0);
- }
-
- public void archiveRootObject(Object var1) throws CodingException {
- int var2 = this.identifierForObject(var1);
- this.archive.addRootIdentifier(var2);
- }
-
- private int identifierForObject(Object var1) throws CodingException {
- if (var1 == null) {
- return 0;
- } else {
- int var2 = this.idHash.get(var1);
- if (var2 != 0) {
- return var2;
- } else {
- String var6 = var1.getClass().getName();
- ExternalCoder var5 = this.archive.externalCoderForName(var6);
- ClassTable var3 = this.archive.classTableForName(var6);
- if (var3 == null) {
- ClassInfo var4 = new ClassInfo(var6);
- if (var5 != null) {
- var5.describeClassInfo(var1, var4);
- } else {
- ((Codable)var1).describeClassInfo(var4);
- }
-
- var3 = new ClassTable(this.archive, var4);
- var3.setUniqueStrings(true);
- this.archive.addClassTable(var3);
- }
-
- var2 = var3.newIdentifier();
- this.idHash.putKnownAbsent(var1, var2);
- this.pushArchivingState(var1, var2);
- if (var5 != null) {
- var5.encode(var1, this);
- } else {
- ((Codable)var1).encode(this);
- }
-
- this.popArchivingState();
- return var2;
- }
- }
- }
-
- private void pushArchivingState(Object var1, int var2) {
- this.stack.pushArchiver(this);
- this.currentObject = var1;
- this.currentTable = this.archive.classTableForIdentifier(var2);
- this.currentId = var2;
- this.currentRow = this.archive.rowForIdentifier(var2);
- this.currentColumn = -1;
- this.currentColumnCount = this.currentTable.fieldCount;
- }
-
- private void popArchivingState() {
- this.stack.popArchiver(this);
- }
-
- private void prepareToArchiveField(String var1) throws CodingException {
- int var3 = this.currentColumnCount;
- String[] var4 = this.currentTable.fieldNames;
-
- for(int var2 = this.currentColumn + 1; var2 < var3; ++var2) {
- if (var1 == var4[var2]) {
- this.currentColumn = var2;
- return;
- }
- }
-
- this.currentColumn = this.currentTable.columnForField(var1);
- if (this.currentColumn < 0) {
- throw new CodingException("Unknown field name: " + var1);
- }
- }
-
- public void encodeBoolean(String var1, boolean var2) throws CodingException {
- this.prepareToArchiveField(var1);
- this.currentTable.setBooleanAt(this.currentRow, this.currentColumn, var2);
- }
-
- public void encodeBooleanArray(String var1, boolean[] var2, int var3, int var4) throws CodingException {
- boolean[] var5 = null;
- this.prepareToArchiveField(var1);
- if (var2 != null) {
- var5 = new boolean[var4];
- System.arraycopy(var2, var3, var5, 0, var4);
- }
-
- this.currentTable.setBooleanArrayAt(this.currentRow, this.currentColumn, var5);
- }
-
- public void encodeChar(String var1, char var2) throws CodingException {
- this.prepareToArchiveField(var1);
- this.currentTable.setCharAt(this.currentRow, this.currentColumn, var2);
- }
-
- public void encodeCharArray(String var1, char[] var2, int var3, int var4) throws CodingException {
- char[] var5 = null;
- this.prepareToArchiveField(var1);
- if (var2 != null) {
- var5 = new char[var4];
- System.arraycopy(var2, var3, var5, 0, var4);
- }
-
- this.currentTable.setCharArrayAt(this.currentRow, this.currentColumn, var5);
- }
-
- public void encodeByte(String var1, byte var2) throws CodingException {
- this.prepareToArchiveField(var1);
- this.currentTable.setByteAt(this.currentRow, this.currentColumn, var2);
- }
-
- public void encodeByteArray(String var1, byte[] var2, int var3, int var4) throws CodingException {
- byte[] var5 = null;
- this.prepareToArchiveField(var1);
- if (var2 != null) {
- var5 = new byte[var4];
- System.arraycopy(var2, var3, var5, 0, var4);
- }
-
- this.currentTable.setByteArrayAt(this.currentRow, this.currentColumn, var5);
- }
-
- public void encodeShort(String var1, short var2) throws CodingException {
- this.prepareToArchiveField(var1);
- this.currentTable.setShortAt(this.currentRow, this.currentColumn, var2);
- }
-
- public void encodeShortArray(String var1, short[] var2, int var3, int var4) throws CodingException {
- short[] var5 = null;
- this.prepareToArchiveField(var1);
- if (var2 != null) {
- var5 = new short[var4];
- System.arraycopy(var2, var3, var5, 0, var4);
- }
-
- this.currentTable.setShortArrayAt(this.currentRow, this.currentColumn, var5);
- }
-
- public void encodeInt(String var1, int var2) throws CodingException {
- this.prepareToArchiveField(var1);
- this.currentTable.setIntAt(this.currentRow, this.currentColumn, var2);
- }
-
- public void encodeIntArray(String var1, int[] var2, int var3, int var4) throws CodingException {
- int[] var5 = null;
- this.prepareToArchiveField(var1);
- if (var2 != null) {
- var5 = new int[var4];
- System.arraycopy(var2, var3, var5, 0, var4);
- }
-
- this.currentTable.setIntArrayAt(this.currentRow, this.currentColumn, var5);
- }
-
- public void encodeLong(String var1, long var2) throws CodingException {
- this.prepareToArchiveField(var1);
- this.currentTable.setLongAt(this.currentRow, this.currentColumn, var2);
- }
-
- public void encodeLongArray(String var1, long[] var2, int var3, int var4) throws CodingException {
- long[] var5 = null;
- this.prepareToArchiveField(var1);
- if (var2 != null) {
- var5 = new long[var4];
- System.arraycopy(var2, var3, var5, 0, var4);
- }
-
- this.currentTable.setLongArrayAt(this.currentRow, this.currentColumn, var5);
- }
-
- public void encodeFloat(String var1, float var2) throws CodingException {
- this.prepareToArchiveField(var1);
- this.currentTable.setFloatAt(this.currentRow, this.currentColumn, var2);
- }
-
- public void encodeFloatArray(String var1, float[] var2, int var3, int var4) throws CodingException {
- float[] var5 = null;
- this.prepareToArchiveField(var1);
- if (var2 != null) {
- var5 = new float[var4];
- System.arraycopy(var2, var3, var5, 0, var4);
- }
-
- this.currentTable.setFloatArrayAt(this.currentRow, this.currentColumn, var5);
- }
-
- public void encodeDouble(String var1, double var2) throws CodingException {
- this.prepareToArchiveField(var1);
- this.currentTable.setDoubleAt(this.currentRow, this.currentColumn, var2);
- }
-
- public void encodeDoubleArray(String var1, double[] var2, int var3, int var4) throws CodingException {
- double[] var5 = null;
- this.prepareToArchiveField(var1);
- if (var2 != null) {
- var5 = new double[var4];
- System.arraycopy(var2, var3, var5, 0, var4);
- }
-
- this.currentTable.setDoubleArrayAt(this.currentRow, this.currentColumn, var5);
- }
-
- public void encodeString(String var1, String var2) throws CodingException {
- this.prepareToArchiveField(var1);
- this.currentTable.setStringAt(this.currentRow, this.currentColumn, var2);
- }
-
- public void encodeStringArray(String var1, String[] var2, int var3, int var4) throws CodingException {
- String[] var5 = null;
- this.prepareToArchiveField(var1);
- if (var2 != null) {
- var5 = new String[var4];
- System.arraycopy(var2, var3, var5, 0, var4);
- }
-
- this.currentTable.setStringArrayAt(this.currentRow, this.currentColumn, var5);
- }
-
- public void encodeObject(String var1, Object var2) throws CodingException {
- this.prepareToArchiveField(var1);
- this.currentTable.setIdentifierAt(this.currentRow, this.currentColumn, this.identifierForObject(var2));
- }
-
- public void encodeObjectArray(String var1, Object[] var2, int var3, int var4) throws CodingException {
- this.prepareToArchiveField(var1);
- if (var2 == null) {
- this.currentTable.setIdentifierArrayAt(this.currentRow, this.currentColumn, (int[])null);
- } else {
- int[] var6 = new int[var4];
-
- for(int var5 = var3; var5 < var4; ++var5) {
- var6[var5] = this.identifierForObject(var2[var5]);
- }
-
- this.currentTable.setIdentifierArrayAt(this.currentRow, this.currentColumn, var6);
- }
- }
- }
-