From 362310157373eef80f49ea6023b1666b3883f4b1 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sun, 3 Nov 2019 16:39:58 +0100 Subject: Implement ZMI serialization --- .../pl/edu/mimuw/cloudatlas/model/Attribute.java | 5 +++++ .../pl/edu/mimuw/cloudatlas/model/ValueBoolean.java | 4 ++++ .../pl/edu/mimuw/cloudatlas/model/ValueContact.java | 7 +++++++ .../pl/edu/mimuw/cloudatlas/model/ValueDouble.java | 4 ++++ .../pl/edu/mimuw/cloudatlas/model/ValueDuration.java | 4 ++++ .../java/pl/edu/mimuw/cloudatlas/model/ValueInt.java | 4 ++++ .../pl/edu/mimuw/cloudatlas/model/ValueList.java | 4 ++++ .../java/pl/edu/mimuw/cloudatlas/model/ValueSet.java | 4 ++++ .../pl/edu/mimuw/cloudatlas/model/ValueSimple.java | 4 ++++ .../pl/edu/mimuw/cloudatlas/model/ValueString.java | 4 ++++ .../pl/edu/mimuw/cloudatlas/model/ValueTime.java | 4 ++++ src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java | 20 ++++++++++++++++++++ 12 files changed, 68 insertions(+) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/Attribute.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/Attribute.java index 46ffab3..aa0cb64 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/Attribute.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/Attribute.java @@ -48,6 +48,11 @@ public class Attribute { this.name = name; } + /* Kryo needs a no-args constructor */ + private Attribute() { + this.name = ""; + } + /** * Indicates whether an attribute represents a query. This is true if and only if the attribute's name starts with an ampersand. * diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueBoolean.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueBoolean.java index 57078c2..6ad3500 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueBoolean.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueBoolean.java @@ -40,6 +40,10 @@ public class ValueBoolean extends ValueSimple { super(value); } + /* Kryo needs a no-args constructor */ + private ValueBoolean() { + } + @Override public Type getType() { return TypePrimitive.BOOLEAN; diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueContact.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueContact.java index 670a025..c554777 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueContact.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueContact.java @@ -25,6 +25,7 @@ package pl.edu.mimuw.cloudatlas.model; import java.net.InetAddress; +import java.net.UnknownHostException; import pl.edu.mimuw.cloudatlas.model.Value; import pl.edu.mimuw.cloudatlas.model.ValueContact; @@ -50,6 +51,12 @@ public class ValueContact extends Value { this.address = address; } + /* Kryo needs a no-args constructor */ + private ValueContact() throws UnknownHostException { + name = new PathName(""); + address = InetAddress.getByAddress(new byte[] {0, 0, 0, 0}); + } + @Override public Value getDefaultValue() { return new ValueContact(null, null); diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueDouble.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueDouble.java index 920a8ef..7d331c9 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueDouble.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueDouble.java @@ -40,6 +40,10 @@ public class ValueDouble extends ValueSimple { super(value); } + /* Kryo needs a no-args constructor */ + private ValueDouble() { + } + @Override public Type getType() { return TypePrimitive.DOUBLE; diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueDuration.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueDuration.java index 444ce78..7022bbd 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueDuration.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueDuration.java @@ -55,6 +55,10 @@ public class ValueDuration extends ValueSimple { super(value); } + /* Kryo needs a no-args constructor */ + private ValueDuration() { + } + @Override public Type getType() { return TypePrimitive.DURATION; diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueInt.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueInt.java index 8811d57..c5aa1c6 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueInt.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueInt.java @@ -41,6 +41,10 @@ public class ValueInt extends ValueSimple { super(value); } + /* Kryo needs a no-args constructor */ + private ValueInt() { + } + @Override public Type getType() { return TypePrimitive.INTEGER; diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueList.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueList.java index 76d59ff..8414cc4 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueList.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueList.java @@ -60,6 +60,10 @@ public class ValueList extends ValueSimple> implements List { setValue(value); } + /* Kryo needs a no-args constructor */ + private ValueList() { + } + /** * Creates an empty list. * diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueSet.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueSet.java index 9843cd4..91524af 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueSet.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueSet.java @@ -59,6 +59,10 @@ public class ValueSet extends ValueSimple> implements Set { setValue(value); } + /* Kryo needs a no-args constructor */ + private ValueSet() { + } + /** * Creates an empty set. * diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueSimple.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueSimple.java index 803510f..a320e43 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueSimple.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueSimple.java @@ -43,6 +43,10 @@ abstract class ValueSimple extends Value { setValue(value); } + /* Kryo needs a no-args constructor */ + protected ValueSimple() { + } + /** * Returns a hash code value for this object. This is a hash code of underlying wrapped object. * diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueString.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueString.java index 314c602..20a083f 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueString.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueString.java @@ -47,6 +47,10 @@ public class ValueString extends ValueSimple { super(value); } + /* Kryo needs a no-args constructor */ + private ValueString() { + } + @Override public Type getType() { return TypePrimitive.STRING; diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueTime.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueTime.java index 8dd04fc..0b9a843 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueTime.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueTime.java @@ -49,6 +49,10 @@ public class ValueTime extends ValueSimple { super(value); } + /* Kryo needs a no-args constructor */ + private ValueTime() { + } + @Override public Type getType() { return TypePrimitive.TIME; diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java index a6b78da..5a560ae 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java @@ -24,12 +24,18 @@ package pl.edu.mimuw.cloudatlas.model; +import java.io.InputStream; +import java.io.OutputStream; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map.Entry; +import com.esotericsoftware.kryo.Kryo; +import com.esotericsoftware.kryo.io.Input; +import com.esotericsoftware.kryo.io.Output; + /** * A zone management information object. This object is a single node in a zone hierarchy. It stores zone attributes as well as * references to its father and sons in the tree. @@ -163,4 +169,18 @@ public class ZMI implements Cloneable { public String toString() { return attributes.toString(); } + + public static ZMI deserialize(InputStream in) { + Kryo kryo = new Kryo(); + Input kryoInput = new Input(in); + ZMI zmi = kryo.readObject(kryoInput, ZMI.class); + return zmi; + } + + public void serialize(OutputStream out) { + Kryo kryo = new Kryo(); + Output kryoOut = new Output(out); + kryo.writeObject(kryoOut, this); + kryoOut.flush(); + } } -- cgit v1.2.3