summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2001-11-26 20:21:07 +0000
committerMark Spruiell <mes@zeroc.com>2001-11-26 20:21:07 +0000
commit28c0d67a22626705416b0d68b6bb0d3f725d9efb (patch)
treedf23a6789c4666bdfe8f86fcd2c479f180c4eab3 /java/src
parentFix IceStorm project. (diff)
downloadice-28c0d67a22626705416b0d68b6bb0d3f725d9efb.tar.bz2
ice-28c0d67a22626705416b0d68b6bb0d3f725d9efb.tar.xz
ice-28c0d67a22626705416b0d68b6bb0d3f725d9efb.zip
completing initial stream impl
Diffstat (limited to 'java/src')
-rw-r--r--java/src/IceInternal/BasicStream.java144
-rw-r--r--java/src/IceInternal/Buffer.java16
2 files changed, 155 insertions, 5 deletions
diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java
index bfc4a6fd509..8086ef10b20 100644
--- a/java/src/IceInternal/BasicStream.java
+++ b/java/src/IceInternal/BasicStream.java
@@ -46,7 +46,12 @@ public class BasicStream
swap(BasicStream other)
{
assert(_instance == other._instance);
- // TODO
+
+ _buf.swap(other._buf);
+
+ java.util.LinkedList tmpStack = other._encapsStack;
+ other._encapsStack = _encapsStack;
+ _encapsStack = tmpStack;
}
private static final int MAX = 1024 * 1024; // TODO: Configurable
@@ -843,13 +848,142 @@ public class BasicStream
public void
writeObject(Ice.Object v)
{
- // TODO
+ Encaps enc = (Encaps)_encapsStack.getLast();
+ Integer pos = null;
+ if (enc.objectsWritten != null) // Lazy creation
+ {
+ pos = enc.objectsWritten.get(v);
+ }
+ if (pos != null)
+ {
+ writeInt(pos.intValue());
+ }
+ else
+ {
+ writeInt(-1);
+
+ if (v != null)
+ {
+ if (enc.objectsWritten == null)
+ {
+ enc.objectsWritten = new java.util.HashMap();
+ }
+ int num = enc.objectsWritten.size();
+ enc.objectsWritten.put(v, new Integer(num));
+ writeString(v.__getClassIds()[0]);
+ v.__write(this);
+ }
+ else
+ {
+ writeString("");
+ }
+ }
+ }
+
+ //
+ // TODO: Can we eliminate the need for a Holder?
+ //
+ public boolean
+ readObject(String signatureType, Ice.ObjectHolder v)
+ {
+ final int pos = readInt();
+
+ if (pos >= 0)
+ {
+ Encaps enc = (Encaps)_encapsStack.getLast();
+ if (enc.objectsRead == null || // Lazy creation
+ pos >= enc.objectsRead.size())
+ {
+ throw new Ice.IllegalIndirectionException();
+ }
+ v.value = (Ice.Object)enc.objectsRead.get(pos);
+ return true;
+ }
+ else
+ {
+ String id = readString();
+
+ if (id.length() == 0)
+ {
+ v.value = null;
+ return true;
+ }
+ else
+ {
+ Encaps enc = (Encaps)_encapsStack.getLast();
+ if (enc.objectsRead == null)
+ {
+ enc.objectsRead = new java.util.ArrayList(10);
+ }
+
+ Ice.ObjectFactory factory =
+ _instance.servantFactoryManager().find(id);
+ if (factory != null)
+ {
+ v.value = factory.create(id);
+ if (v.value != null)
+ {
+ enc.objectsRead.add(v.value);
+ v.value.__read(this);
+ return true;
+ }
+ }
+
+ if (id.equals(signatureType))
+ {
+ enc.objectsRead.add(v.value);
+ return false;
+ }
+
+ throw new Ice.NoObjectFactoryException();
+ }
+ }
+ }
+
+ public void
+ writeUserException(Ice.UserException v)
+ {
+ write(v.__getExceptionIds()[0]);
+ v.__write(this);
}
- public Ice.Object
- readObject()
+ public int
+ throwException(String[] ids)
+ throws Ice.UserException
{
- // TODO
+ String id = readString();
+ Ice.UserExceptionFactory factory =
+ _instance.userExceptionFactoryManager().find(id);
+
+ if (factory != null)
+ {
+ try
+ {
+ factory.createAndThrow(id);
+ }
+ catch (Ice.UserException ex)
+ {
+ String[] arr = ex.__getExceptionIds();
+ for (int i = 0; !arr[i].equals("::Ice::UserException"); i++)
+ {
+ if (java.util.Arrays.binarySearch(ids, arr[i]) >= 0)
+ {
+ ex.__read(this);
+ throw ex;
+ }
+ }
+
+ throw new Ice.UnknownUserException();
+ }
+ }
+
+ int pos = java.util.Arrays.binarySearch(ids, id);
+ if (pos >= 0)
+ {
+ return pos;
+ }
+
+ throw new Ice.NoUserExceptionFactoryException();
}
private IceInternal.Instance _instance;
diff --git a/java/src/IceInternal/Buffer.java b/java/src/IceInternal/Buffer.java
index de08e52f393..39c23b36453 100644
--- a/java/src/IceInternal/Buffer.java
+++ b/java/src/IceInternal/Buffer.java
@@ -45,6 +45,22 @@ public class Buffer
}
}
+ public void
+ swap(Buffer r)
+ {
+ byte[] tmpdata = r.data;
+ r.data = data;
+ data = tmpdata;
+
+ int tmppos = r.pos;
+ r.pos = pos;
+ pos = tmppos;
+
+ int tmplen = r.len;
+ r.len = len;
+ len = tmplen;
+ }
+
public byte[] data;
public int pos;
public int len;