summaryrefslogtreecommitdiffstats
path: root/jurt/com/sun/star/lib/uno/protocols/urp/Marshal.java
diff options
context:
space:
mode:
Diffstat (limited to 'jurt/com/sun/star/lib/uno/protocols/urp/Marshal.java')
-rw-r--r--jurt/com/sun/star/lib/uno/protocols/urp/Marshal.java352
1 files changed, 162 insertions, 190 deletions
diff --git a/jurt/com/sun/star/lib/uno/protocols/urp/Marshal.java b/jurt/com/sun/star/lib/uno/protocols/urp/Marshal.java
index 55c36cd4b7a7..8a42b4a8e831 100644
--- a/jurt/com/sun/star/lib/uno/protocols/urp/Marshal.java
+++ b/jurt/com/sun/star/lib/uno/protocols/urp/Marshal.java
@@ -26,6 +26,7 @@ import com.sun.star.uno.IFieldDescription;
import com.sun.star.uno.Type;
import com.sun.star.uno.TypeClass;
import com.sun.star.uno.XInterface;
+
import java.io.ByteArrayOutputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
@@ -46,7 +47,7 @@ final class Marshal {
try {
output.writeByte(value);
} catch (IOException e) {
- throw new RuntimeException(e.toString());
+ throw new RuntimeException(e);
}
}
@@ -54,19 +55,23 @@ final class Marshal {
try {
output.writeShort(value);
} catch (IOException e) {
- throw new RuntimeException(e.toString());
+ throw new RuntimeException(e);
}
}
public void writeObjectId(String objectId) {
- if (objectId == null) {
- writeStringValue(null);
- write16Bit(0xFFFF);
- } else {
- boolean[] found = new boolean[1];
- int index = objectIdCache.add(found, objectId);
- writeStringValue(found[0] ? null : objectId);
- write16Bit(index);
+ try {
+ if (objectId == null) {
+ writeStringValue(null);
+ write16Bit(0xFFFF);
+ } else {
+ boolean[] found = new boolean[1];
+ int index = objectIdCache.add(found, objectId);
+ writeStringValue(found[0] ? null : objectId);
+ write16Bit(index);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
}
@@ -75,107 +80,127 @@ final class Marshal {
}
public void writeThreadId(ThreadId threadId) {
- byte[] data = threadId.getBytes();
- boolean[] found = new boolean[1];
- int index = threadIdCache.add(found, data);
- if (found[0]) {
- writeCompressedNumber(0);
- } else {
- writeCompressedNumber(data.length);
- writeBytes(data);
+ try {
+ byte[] data = threadId.getBytes();
+ boolean[] found = new boolean[1];
+ int index = threadIdCache.add(found, data);
+ if (found[0]) {
+ writeCompressedNumber(0);
+ } else {
+ writeCompressedNumber(data.length);
+ writeBytes(data);
+ }
+ write16Bit(index);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
- write16Bit(index);
}
public void writeType(TypeDescription type) {
- TypeClass typeClass = type.getTypeClass();
- if (TypeDescription.isTypeClassSimple(typeClass)) {
- write8Bit(typeClass.getValue());
- } else {
- boolean[] found = new boolean[1];
- int index = typeCache.add(found, type.getTypeName());
- write8Bit(typeClass.getValue() | (found[0] ? 0 : 0x80));
- write16Bit(index);
- if (!found[0]) {
- writeStringValue(type.getTypeName());
+ try {
+ TypeClass typeClass = type.getTypeClass();
+ if (TypeDescription.isTypeClassSimple(typeClass)) {
+ write8Bit(typeClass.getValue());
+ } else {
+ boolean[] found = new boolean[1];
+ int index = typeCache.add(found, type.getTypeName());
+ write8Bit(typeClass.getValue() | (found[0] ? 0 : 0x80));
+ write16Bit(index);
+ if (!found[0]) {
+ writeStringValue(type.getTypeName());
+ }
}
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
}
public void writeValue(TypeDescription type, Object value) {
- switch(type.getTypeClass().getValue()) {
- case TypeClass.VOID_value:
- break;
-
- case TypeClass.BOOLEAN_value:
- writeBooleanValue((Boolean) value);
- break;
-
- case TypeClass.BYTE_value:
- writeByteValue((Byte) value);
- break;
-
- case TypeClass.SHORT_value:
- case TypeClass.UNSIGNED_SHORT_value:
- writeShortValue((Short) value);
- break;
-
- case TypeClass.LONG_value:
- case TypeClass.UNSIGNED_LONG_value:
- writeLongValue((Integer) value);
- break;
-
- case TypeClass.HYPER_value:
- case TypeClass.UNSIGNED_HYPER_value:
- writeHyperValue((Long) value);
- break;
-
- case TypeClass.FLOAT_value:
- writeFloatValue((Float) value);
- break;
-
- case TypeClass.DOUBLE_value:
- writeDoubleValue((Double) value);
- break;
-
- case TypeClass.CHAR_value:
- writeCharValue((Character) value);
- break;
-
- case TypeClass.STRING_value:
- writeStringValue((String) value);
- break;
-
- case TypeClass.TYPE_value:
- writeTypeValue((Type) value);
- break;
-
- case TypeClass.ANY_value:
- writeAnyValue(value);
- break;
-
- case TypeClass.SEQUENCE_value:
- writeSequenceValue(type, value);
- break;
-
- case TypeClass.ENUM_value:
- writeEnumValue(type, (Enum) value);
- break;
-
- case TypeClass.STRUCT_value:
- writeStructValue(type, value);
- break;
-
- case TypeClass.EXCEPTION_value:
- writeExceptionValue(type, (Exception) value);
- break;
-
- case TypeClass.INTERFACE_value:
- writeInterfaceValue(type, (XInterface) value);
- break;
-
- default:
- throw new IllegalArgumentException("Bad type descriptor " + type);
+ try {
+ switch(type.getTypeClass().getValue()) {
+ case TypeClass.VOID_value:
+ break;
+
+ case TypeClass.BOOLEAN_value:
+ writeBooleanValue((Boolean) value);
+ break;
+
+ case TypeClass.BYTE_value:
+ writeByteValue((Byte) value);
+ break;
+
+ case TypeClass.SHORT_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ writeShortValue((Short) value);
+ break;
+
+ case TypeClass.LONG_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ writeLongValue((Integer) value);
+ break;
+
+ case TypeClass.HYPER_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ writeHyperValue((Long) value);
+ break;
+
+ case TypeClass.FLOAT_value:
+ writeFloatValue((Float) value);
+ break;
+
+ case TypeClass.DOUBLE_value:
+ writeDoubleValue((Double) value);
+ break;
+
+ case TypeClass.CHAR_value:
+ writeCharValue((Character) value);
+ break;
+
+ case TypeClass.STRING_value:
+ writeStringValue((String) value);
+ break;
+
+ case TypeClass.TYPE_value:
+ writeTypeValue((Type) value);
+ break;
+
+ case TypeClass.ANY_value:
+ writeAnyValue(value);
+ break;
+
+ case TypeClass.SEQUENCE_value:
+ writeSequenceValue(type, value);
+ break;
+
+ case TypeClass.ENUM_value:
+ writeEnumValue(type, (Enum) value);
+ break;
+
+ case TypeClass.STRUCT_value:
+ writeStructValue(type, value);
+ break;
+
+ case TypeClass.EXCEPTION_value:
+ writeExceptionValue(type, (Exception) value);
+ break;
+
+ case TypeClass.INTERFACE_value:
+ writeInterfaceValue(type, (XInterface) value);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Bad type descriptor " + type);
+ }
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
}
}
@@ -185,12 +210,8 @@ final class Marshal {
return data;
}
- private void writeBooleanValue(Boolean value) {
- try {
- output.writeBoolean(value != null && value.booleanValue());
- } catch (IOException e) {
- throw new RuntimeException(e.toString());
- }
+ private void writeBooleanValue(Boolean value) throws IOException {
+ output.writeBoolean(value != null && value.booleanValue());
}
private void writeByteValue(Byte value) {
@@ -201,78 +222,49 @@ final class Marshal {
write16Bit(value == null ? 0 : value.shortValue());
}
- private void writeLongValue(Integer value) {
+ private void writeLongValue(Integer value) throws IOException {
write32Bit(value == null ? 0 : value.intValue());
}
- private void writeHyperValue(Long value) {
- try {
- output.writeLong(value == null ? 0 : value.longValue());
- } catch (IOException e) {
- throw new RuntimeException(e.toString());
- }
+ private void writeHyperValue(Long value) throws IOException {
+ output.writeLong(value == null ? 0 : value.longValue());
}
- private void writeFloatValue(Float value) {
- try {
- output.writeFloat(value == null ? 0 : value.floatValue());
- } catch (IOException e) {
- throw new RuntimeException(e.toString());
- }
+ private void writeFloatValue(Float value) throws IOException {
+ output.writeFloat(value == null ? 0 : value.floatValue());
}
- private void writeDoubleValue(Double value) {
- try {
- output.writeDouble(value == null ? 0 : value.doubleValue());
- } catch (IOException e) {
- throw new RuntimeException(e.toString());
- }
+ private void writeDoubleValue(Double value) throws IOException {
+ output.writeDouble(value == null ? 0 : value.doubleValue());
}
- private void writeCharValue(Character value) {
- try {
- output.writeChar(value == null ? 0 : value.charValue());
- } catch (IOException e) {
- throw new RuntimeException(e.toString());
- }
+ private void writeCharValue(Character value) throws IOException {
+ output.writeChar(value == null ? 0 : value.charValue());
}
- private void writeStringValue(String value) {
+ private void writeStringValue(String value) throws IOException {
if (value == null) {
writeCompressedNumber(0);
} else {
- byte[] data;
- try {
- data = value.getBytes("UTF8");
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e.toString());
- }
+ byte[] data = value.getBytes("UTF8");
writeCompressedNumber(data.length);
writeBytes(data);
}
}
- private void writeTypeValue(Type value) {
- try {
- writeType(
- TypeDescription.getTypeDescription(
- value == null ? Type.VOID : value));
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e.toString());
- }
+ private void writeTypeValue(Type value) throws ClassNotFoundException {
+ writeType(
+ TypeDescription.getTypeDescription(
+ value == null ? Type.VOID : value));
}
- private void writeAnyValue(Object value) {
+ private void writeAnyValue(Object value) throws ClassNotFoundException {
TypeDescription type;
if (value == null || value instanceof XInterface) {
type = TypeDescription.getTypeDescription(XInterface.class);
} else if (value instanceof Any) {
Any any = (Any) value;
- try {
- type = TypeDescription.getTypeDescription(any.getType());
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e.toString());
- }
+ type = TypeDescription.getTypeDescription(any.getType());
value = any.getObject();
} else if (value.getClass() == Object.class) {
// Avoid StackOverflowError:
@@ -285,7 +277,7 @@ final class Marshal {
writeValue(type, value);
}
- private void writeSequenceValue(TypeDescription type, Object value) {
+ private void writeSequenceValue(TypeDescription type, Object value) throws IOException {
if (value == null) {
writeCompressedNumber(0);
} else {
@@ -304,41 +296,29 @@ final class Marshal {
}
}
- private void writeEnumValue(TypeDescription type, Enum value) {
+ private void writeEnumValue(TypeDescription type, Enum value) throws IllegalAccessException, IOException, InvocationTargetException, NoSuchMethodException {
int n;
if (value == null) {
- try {
- n = ((Enum)
- (type.getZClass().getMethod("getDefault", (Class[]) null).
- invoke(null, (Object[]) null))).
- getValue();
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e.toString());
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e.toString());
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e.toString());
- }
+ n = ((Enum)
+ (type.getZClass().getMethod("getDefault", (Class[]) null).
+ invoke(null, (Object[]) null))).
+ getValue();
} else {
n = value.getValue();
}
write32Bit(n);
}
- private void writeStructValue(TypeDescription type, Object value) {
+ private void writeStructValue(TypeDescription type, Object value) throws IllegalAccessException {
IFieldDescription[] fields = type.getFieldDescriptions();
for (int i = 0; i < fields.length; ++i) {
- try {
- writeValue(
- (TypeDescription) fields[i].getTypeDescription(),
- value == null ? null : fields[i].getField().get(value));
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e.toString());
- }
+ writeValue(
+ (TypeDescription) fields[i].getTypeDescription(),
+ value == null ? null : fields[i].getField().get(value));
}
}
- private void writeExceptionValue(TypeDescription type, Exception value) {
+ private void writeExceptionValue(TypeDescription type, Exception value) throws IllegalAccessException, IOException {
writeStringValue(value == null ? null : value.getMessage());
writeStructValue(type, value);
}
@@ -347,15 +327,11 @@ final class Marshal {
writeInterface(value, new Type(type));
}
- private void write32Bit(int value) {
- try {
- output.writeInt(value);
- } catch (IOException e) {
- throw new RuntimeException(e.toString());
- }
+ private void write32Bit(int value) throws IOException {
+ output.writeInt(value);
}
- private void writeCompressedNumber(int number) {
+ private void writeCompressedNumber(int number) throws IOException {
if (number >= 0 && number < 0xFF) {
write8Bit(number);
} else {
@@ -364,12 +340,8 @@ final class Marshal {
}
}
- private void writeBytes(byte[] data) {
- try {
- output.write(data);
- } catch (IOException e) {
- throw new RuntimeException(e.toString());
- }
+ private void writeBytes(byte[] data) throws IOException {
+ output.write(data);
}
private final ByteArrayOutputStream buffer = new ByteArrayOutputStream();