- All Known Implementing Classes:
MathTypeHandler
public interface TypeSerializationHandlerInterface
The omix file I/O procedure is able to write and read a comprehensive but limited set of class types like
String
, Integer
, Double
, List
etc.
In order to extend this set with specific class types available in plugin bundles or libraries
this interface can be implemented.
Following example code serializes the class GradientPaint
:
public class MyTypeSerializationHandler implements TypeSerializationHandlerInterface {
public boolean supports(Class<?> type) {
if(type==GradientPaint.class) {
return true;
}
return false;
}
public AbstractSerialization serialize(Object object) {
if(object instanceof GradientPaint) {
GradientPaint paint = (GradientPaint)object;
float x1 = paint.getPoint1().getX();
float y1 = paint.getPoint1().getY();
int color1 = paint.getColor1().getRGB();
float x2 = paint.getPoint2().getX();
float y2 = paint.getPoint2().getY();
int color2 = paint.getColor2().getRGB();
boolean cyclic = paint.isCyclic();
// creating a content array from all components...
return new ComponentArraySerialization(x1, y1, color1, x2, y2, color2, cyclic);
}
return null;
}
public Object deserialize(Class<?> type, AbstractSerialization serialization, VersionNumber version) throws Exception {
if(type==GradientPaint.class) {
if(serialization instanceof ComponentArraySerialization) {
Object[] components = ((ComponentArraySerialization)serialization).components;
if(components.length==7
&& components[0] instanceof Float
&& components[1] instanceof Float
&& components[2] instanceof Integer
&& components[3] instanceof Float
&& components[4] instanceof Float
&& components[5] instanceof Integer
&& components[6] instanceof Boolean) {
float x1 = (Float)components[0];
float y1 = (Float)components[1];
int color1 = (Integer)components[2];
float x2 = (Float)components[3];
float y2 = (Float)components[4];
int color2 = (Integer)components[5];
boolean cyclic = (Boolean)components[6];
return new GradientPaint(x1, y1, color1, x2, y2, color2, cyclic);
} else {
throw new Exception("Cannot deserialize GradientPaint.");
}
} else {
throw new Exception("Cannot deserialize GradientPaint.");
}
}
return null;
}
}
- Since:
- 1.3.11
- Author:
- Dr. Peter Droste, Omix Visualization
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
TypeSerializationHandlerInterface.AbstractSerialization
Supertype for all serialization types.static class
TypeSerializationHandlerInterface.ComponentArraySerialization
An Object is serialized as array of its components.
Here, recursive references are not allowed.static class
TypeSerializationHandlerInterface.ComponentMapSerialization
An Object is serialized as map (String,Object) of its components.
Here, recursive references are not allowed.static class
TypeSerializationHandlerInterface.DoubleSerialization
An Object is serialized asdouble
value.static class
TypeSerializationHandlerInterface.IntSerialization
An Object is serialized asint
value.static class
TypeSerializationHandlerInterface.LongSerialization
An Object is serialized aslong
value.static class
TypeSerializationHandlerInterface.RawDataSerialization
An Object is serialized asbyte[]
value.static class
TypeSerializationHandlerInterface.StringSerialization
An Object is serialized as String. -
Method Summary
Modifier and Type Method Description Object
deserialize(Class<?> type, TypeSerializationHandlerInterface.AbstractSerialization serialization, VersionNumber version)
Deserializes an object of a specific class type according the given instance ofTypeSerializationHandlerInterface.AbstractSerialization
.
Omix iterates the list of installed TypeSerializationHandlers ordered by time of installation.TypeSerializationHandlerInterface.AbstractSerialization
serialize(Object object)
Serializes an object of a specific class type.
Omix iterates the list of installed TypeSerializationHandlers ordered by time of installation.boolean
supports(Class<?> type)
Determines if TypeSerializationHandler supports specified class type.static <T> Collection<T>
toCollection(Collection<?> list, Class<T> type)
static <T> Collection<T>
toCollection(Collection<?> list, Class<T> type, Supplier<? extends Collection<T>> listSupplier)
static <T> Deque<T>
toCollection(Deque<?> list, Class<T> type)
static <T> Deque<T>
toCollection(Deque<?> list, Class<T> type, Supplier<? extends Deque<T>> listSupplier)
static <T> List<T>
toCollection(List<?> list, Class<T> type)
static <T> List<T>
toCollection(List<?> list, Class<T> type, Supplier<? extends List<T>> listSupplier)
static <T> NavigableSet<T>
toCollection(NavigableSet<?> list, Class<T> type)
static <T> NavigableSet<T>
toCollection(NavigableSet<?> list, Class<T> type, Supplier<? extends NavigableSet<T>> listSupplier)
static <T> Queue<T>
toCollection(Queue<?> list, Class<T> type)
static <T> Queue<T>
toCollection(Queue<?> list, Class<T> type, Supplier<? extends Queue<T>> listSupplier)
static <T> Set<T>
toCollection(Set<?> list, Class<T> type)
static <T> Set<T>
toCollection(Set<?> list, Class<T> type, Supplier<? extends Set<T>> listSupplier)
static <T> SortedSet<T>
toCollection(SortedSet<?> list, Class<T> type)
static <T> SortedSet<T>
toCollection(SortedSet<?> list, Class<T> type, Supplier<? extends SortedSet<T>> listSupplier)
static <K, V> Map<K,V>
toMap(Map<?,?> map, Class<K> keyType, Class<V> valueType)
static <K, V> Map<K,V>
toMap(Map<?,?> map, Class<K> keyType, Class<V> valueType, Supplier<? extends Map<K,V>> mapSupplier)
static <K, V> NavigableMap<K,V>
toMap(NavigableMap<?,?> map, Class<K> keyType, Class<V> valueType)
static <K, V> NavigableMap<K,V>
toMap(NavigableMap<?,?> map, Class<K> keyType, Class<V> valueType, Supplier<? extends NavigableMap<K,V>> mapSupplier)
static <K, V> SortedMap<K,V>
toMap(SortedMap<?,?> map, Class<K> keyType, Class<V> valueType)
static <K, V> SortedMap<K,V>
toMap(SortedMap<?,?> map, Class<K> keyType, Class<V> valueType, Supplier<? extends NavigableMap<K,V>> mapSupplier)
-
Method Details
-
supports
Determines if TypeSerializationHandler supports specified class type.- Parameters:
type
- class type supported by this handler- Returns:
- class type supported
-
serialize
Serializes an object of a specific class type.
Omix iterates the list of installed TypeSerializationHandlers ordered by time of installation. The first handler supporting the specific class is used for value serialization. All other supporting handlers are skipped.- Parameters:
object
- to be serialized- Returns:
- instance of AbstractSerialization
- Throws:
Exception
- can be thrown to declare an internal error.
-
deserialize
Object deserialize(Class<?> type, TypeSerializationHandlerInterface.AbstractSerialization serialization, VersionNumber version) throws ExceptionDeserializes an object of a specific class type according the given instance ofTypeSerializationHandlerInterface.AbstractSerialization
.
Omix iterates the list of installed TypeSerializationHandlers ordered by time of installation. The first handler supporting the specific class is used for value deserialization. All other supporting handlers are skipped.- Parameters:
type
-serialization
- corresponds to the serialization result fromserialize(Object)
.version
- the version number of the plugin installed in Omix when the object was serialized.
In this way, the implementation can change and keep compartibility.- Returns:
- the deserialized object
- Throws:
Exception
- can be thrown to declare an internal error.
-
toCollection
- Since:
- Omix 1.9.30
-
toCollection
static <T> Deque<T> toCollection(Deque<?> list, Class<T> type, Supplier<? extends Deque<T>> listSupplier)- Since:
- Omix 1.9.30
-
toCollection
- Since:
- Omix 1.9.30
-
toCollection
static <T> Queue<T> toCollection(Queue<?> list, Class<T> type, Supplier<? extends Queue<T>> listSupplier)- Since:
- Omix 1.9.30
-
toCollection
- Since:
- Omix 1.9.30
-
toCollection
static <T> Set<T> toCollection(Set<?> list, Class<T> type, Supplier<? extends Set<T>> listSupplier)- Since:
- Omix 1.9.30
-
toCollection
- Since:
- Omix 1.9.30
-
toCollection
static <T> SortedSet<T> toCollection(SortedSet<?> list, Class<T> type, Supplier<? extends SortedSet<T>> listSupplier)- Since:
- Omix 1.9.30
-
toCollection
- Since:
- Omix 1.9.30
-
toCollection
static <T> NavigableSet<T> toCollection(NavigableSet<?> list, Class<T> type, Supplier<? extends NavigableSet<T>> listSupplier)- Since:
- Omix 1.9.30
-
toCollection
- Since:
- Omix 1.9.30
-
toCollection
static <T> List<T> toCollection(List<?> list, Class<T> type, Supplier<? extends List<T>> listSupplier)- Since:
- Omix 1.9.30
-
toCollection
- Since:
- Omix 1.9.30
-
toCollection
static <T> Collection<T> toCollection(Collection<?> list, Class<T> type, Supplier<? extends Collection<T>> listSupplier)- Since:
- Omix 1.9.30
-
toMap
- Since:
- Omix 1.9.30
-
toMap
static <K, V> NavigableMap<K,V> toMap(NavigableMap<?,?> map, Class<K> keyType, Class<V> valueType)- Since:
- Omix 1.9.30
-
toMap
static <K, V> NavigableMap<K,V> toMap(NavigableMap<?,?> map, Class<K> keyType, Class<V> valueType, Supplier<? extends NavigableMap<K,V>> mapSupplier)- Since:
- Omix 1.9.30
-
toMap
- Since:
- Omix 1.9.30
-
toMap
static <K, V> SortedMap<K,V> toMap(SortedMap<?,?> map, Class<K> keyType, Class<V> valueType, Supplier<? extends NavigableMap<K,V>> mapSupplier)- Since:
- Omix 1.9.30
-
toMap
static <K, V> Map<K,V> toMap(Map<?,?> map, Class<K> keyType, Class<V> valueType, Supplier<? extends Map<K,V>> mapSupplier)- Since:
- Omix 1.9.30
-