home *** CD-ROM | disk | FTP | other *** search
- package netscape.util;
-
- import java.io.IOException;
- import java.io.InputStream;
- import netscape.application.AWTCompatibility;
- import netscape.application.FoundationApplet;
-
- public class Unarchiver implements Decoder {
- Archive archive;
- ArchivingStack stack = new ArchivingStack();
- Object[] objectForId;
- boolean[] referenceGivenOut;
- int unarchivedCount;
- Object[] unarchivedObjects;
- ExternalCoder[] unarchivedCoders;
- Object currentObject;
- ClassTable currentTable;
- int currentId;
- int currentColumnCount;
- int currentRow;
- int currentColumn;
- FoundationApplet applet;
- boolean appletInitialized;
-
- public Unarchiver(Archive var1) {
- this.archive = var1;
- }
-
- public Archive archive() {
- return this.archive;
- }
-
- public static Object readObject(InputStream var0) throws IOException, CodingException {
- Archive var1 = new Archive();
- var1.read(var0);
- Unarchiver var2 = new Unarchiver(var1);
- int[] var3 = var1.rootIdentifiers();
- return var3 != null && var3.length != 0 ? var2.unarchiveIdentifier(var3[0]) : null;
- }
-
- public Object unarchiveIdentifier(int var1) throws CodingException {
- if (var1 == 0) {
- return null;
- } else {
- if (this.objectForId == null) {
- this.referenceGivenOut = new boolean[this.archive.identifierCount()];
- this.objectForId = new Object[this.referenceGivenOut.length];
- this.unarchivedObjects = new Object[this.referenceGivenOut.length];
- this.unarchivedCoders = new ExternalCoder[this.referenceGivenOut.length];
- }
-
- this.clearFinishList();
-
- Object var2;
- try {
- var2 = this.objectForIdentifier(var1);
- this.processFinishList();
- } finally {
- this.clearFinishList();
- }
-
- return var2;
- }
- }
-
- protected Class classForName(String var1) throws CodingException {
- Class var2 = null;
- if (!this.appletInitialized) {
- this.applet = (FoundationApplet)AWTCompatibility.awtApplet();
- this.appletInitialized = true;
- }
-
- try {
- if (this.applet != null) {
- var2 = this.applet.classForName(var1);
- } else {
- var2 = Class.forName(var1);
- }
- } catch (ClassNotFoundException var4) {
- this.creationException(((Throwable)var4).toString(), var1);
- } catch (NoSuchMethodError var5) {
- this.creationException(((Throwable)var5).toString(), var1);
- }
-
- return var2;
- }
-
- protected Object newInstance(String var1) throws CodingException {
- Object var3 = null;
- Class var2 = this.classForName(var1);
-
- try {
- var3 = var2.newInstance();
- } catch (InstantiationException var5) {
- this.creationException(((Throwable)var5).toString(), var1);
- } catch (IllegalAccessException var6) {
- this.creationException(((Throwable)var6).toString(), var1);
- } catch (NoSuchMethodError var7) {
- this.creationException(((Throwable)var7).toString(), var1);
- }
-
- return var3;
- }
-
- private void creationException(String var1, String var2) throws CodingException {
- throw new CodingException(var1 + ". Class " + var2 + " must be public and define a constructor taking no arguments.");
- }
-
- private Object objectForIdentifier(int var1) throws CodingException {
- Object var3 = this.objectForId[var1];
- if (var3 != null) {
- this.referenceGivenOut[var1] = true;
- return var3;
- } else if (var1 == 0) {
- return null;
- } else {
- ClassTable var4 = this.archive.classTableForIdentifier(var1);
- String var5 = var4.className();
- ExternalCoder var2 = this.archive.externalCoderForName(var5);
- if (var2 != null) {
- var3 = var2.newInstance(var5);
- } else {
- var3 = this.newInstance(var5);
- }
-
- if (!var4.hasUniqueStrings()) {
- ClassInfo var6 = new ClassInfo(var5);
- if (var2 != null) {
- var2.describeClassInfo(var3, var6);
- } else {
- ((Codable)var3).describeClassInfo(var6);
- }
-
- var4.uniqueStrings(var6);
- }
-
- this.addToFinishList(var2, var3);
- this.objectForId[var1] = var3;
- this.pushUnarchivingState(var3, var1);
- if (var2 != null) {
- var2.decode(var3, this);
- } else {
- ((Codable)var3).decode(this);
- }
-
- this.popUnarchivingState();
- return this.objectForId[var1];
- }
- }
-
- private void pushUnarchivingState(Object var1, int var2) {
- this.stack.pushUnarchiver(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 popUnarchivingState() {
- this.stack.popUnarchiver(this);
- }
-
- private void addToFinishList(ExternalCoder var1, Object var2) {
- this.unarchivedCoders[this.unarchivedCount] = var1;
- this.unarchivedObjects[this.unarchivedCount] = var2;
- ++this.unarchivedCount;
- }
-
- private void processFinishList() throws CodingException {
- int var2 = this.unarchivedCount;
-
- for(int var1 = 0; var1 < var2; ++var1) {
- ExternalCoder var3 = this.unarchivedCoders[var1];
- Object var4 = this.unarchivedObjects[var1];
- if (var3 != null) {
- var3.finishDecoding(var4);
- } else {
- ((Codable)var4).finishDecoding();
- }
-
- this.unarchivedCoders[var1] = null;
- this.unarchivedObjects[var1] = null;
- }
-
- this.unarchivedCount = 0;
- }
-
- private void clearFinishList() {
- int var2 = this.unarchivedCount;
-
- for(int var1 = 0; var1 < var2; ++var1) {
- this.unarchivedCoders[var1] = null;
- this.unarchivedObjects[var1] = null;
- }
-
- this.unarchivedCount = 0;
- }
-
- private void prepareToUnarchiveField(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 int versionForClassName(String var1) throws CodingException {
- return this.currentTable.versionForClassName(var1);
- }
-
- public boolean decodeBoolean(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.booleanAt(this.currentRow, this.currentColumn);
- }
-
- public boolean[] decodeBooleanArray(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.booleanArrayAt(this.currentRow, this.currentColumn);
- }
-
- public char decodeChar(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.charAt(this.currentRow, this.currentColumn);
- }
-
- public char[] decodeCharArray(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.charArrayAt(this.currentRow, this.currentColumn);
- }
-
- public byte decodeByte(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.byteAt(this.currentRow, this.currentColumn);
- }
-
- public byte[] decodeByteArray(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.byteArrayAt(this.currentRow, this.currentColumn);
- }
-
- public short decodeShort(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.shortAt(this.currentRow, this.currentColumn);
- }
-
- public short[] decodeShortArray(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.shortArrayAt(this.currentRow, this.currentColumn);
- }
-
- public int decodeInt(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.intAt(this.currentRow, this.currentColumn);
- }
-
- public int[] decodeIntArray(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.intArrayAt(this.currentRow, this.currentColumn);
- }
-
- public long decodeLong(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.longAt(this.currentRow, this.currentColumn);
- }
-
- public long[] decodeLongArray(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.longArrayAt(this.currentRow, this.currentColumn);
- }
-
- public float decodeFloat(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.floatAt(this.currentRow, this.currentColumn);
- }
-
- public float[] decodeFloatArray(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.floatArrayAt(this.currentRow, this.currentColumn);
- }
-
- public double decodeDouble(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.doubleAt(this.currentRow, this.currentColumn);
- }
-
- public double[] decodeDoubleArray(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.doubleArrayAt(this.currentRow, this.currentColumn);
- }
-
- public String decodeString(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.stringAt(this.currentRow, this.currentColumn);
- }
-
- public String[] decodeStringArray(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.currentTable.stringArrayAt(this.currentRow, this.currentColumn);
- }
-
- public Object decodeObject(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- return this.objectForIdentifier(this.currentTable.identifierAt(this.currentRow, this.currentColumn));
- }
-
- public Object[] decodeObjectArray(String var1) throws CodingException {
- this.prepareToUnarchiveField(var1);
- int[] var3 = this.currentTable.identifierArrayAt(this.currentRow, this.currentColumn);
- if (var3 == null) {
- return null;
- } else {
- Object[] var4 = new Object[var3.length];
-
- for(int var2 = 0; var2 < var3.length; ++var2) {
- var4[var2] = this.objectForIdentifier(var3[var2]);
- }
-
- return var4;
- }
- }
-
- public void replaceObject(Object var1) throws CodingException {
- if (this.referenceGivenOut[this.currentId]) {
- throw new CodingException("Circular replacement exception");
- } else {
- this.objectForId[this.currentId] = var1;
- }
- }
- }
-