diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/data/type/TypeInformationSerializer.java')
-rw-r--r-- | src/de/lmu/ifi/dbs/elki/data/type/TypeInformationSerializer.java | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/data/type/TypeInformationSerializer.java b/src/de/lmu/ifi/dbs/elki/data/type/TypeInformationSerializer.java index ac3fd164..e38a55e6 100644 --- a/src/de/lmu/ifi/dbs/elki/data/type/TypeInformationSerializer.java +++ b/src/de/lmu/ifi/dbs/elki/data/type/TypeInformationSerializer.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.data.type; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -28,10 +28,10 @@ import java.nio.ByteBuffer; import de.lmu.ifi.dbs.elki.data.DoubleVector; import de.lmu.ifi.dbs.elki.data.NumberVector; -import de.lmu.ifi.dbs.elki.persistent.ByteArrayUtil; -import de.lmu.ifi.dbs.elki.persistent.ByteBufferSerializer; import de.lmu.ifi.dbs.elki.utilities.ClassGenericsUtil; import de.lmu.ifi.dbs.elki.utilities.exceptions.UnableToComplyException; +import de.lmu.ifi.dbs.elki.utilities.io.ByteArrayUtil; +import de.lmu.ifi.dbs.elki.utilities.io.ByteBufferSerializer; /** * Class to handle the serialization and deserialization of type information. @@ -232,20 +232,22 @@ public class TypeInformationSerializer implements ByteBufferSerializer<TypeInfor @Override public VectorTypeInformation<?> fromByteBuffer(ByteBuffer buffer) throws IOException, UnsupportedOperationException { try { + // Factory type! String typename = ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer); - Class<DoubleVector> clz = (Class<DoubleVector>) Class.forName(typename); + NumberVector.Factory<DoubleVector> factory = (NumberVector.Factory<DoubleVector>) ClassGenericsUtil.instantiate(NumberVector.Factory.class, typename); String label = ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer); label = ("".equals(label)) ? null : label; String sername = ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer); ByteBufferSerializer<DoubleVector> serializer = (ByteBufferSerializer<DoubleVector>) Class.forName(sername).newInstance(); int mindim = ByteArrayUtil.readSignedVarint(buffer); int maxdim = ByteArrayUtil.readSignedVarint(buffer); - return new VectorTypeInformation<>(clz, serializer, mindim, maxdim); + // FIXME: should/must provide a factory now! + return new VectorTypeInformation<>(factory, serializer, mindim, maxdim); + } catch (UnableToComplyException e) { + throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate factory: "+e, e); } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Cannot deserialize - class not found: "+e, e); - } catch (InstantiationException e) { - throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate serializer: "+e.getMessage(), e); - } catch (IllegalAccessException e) { + } catch (InstantiationException | IllegalAccessException e) { throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate serializer: "+e.getMessage(), e); } } @@ -265,8 +267,8 @@ public class TypeInformationSerializer implements ByteBufferSerializer<TypeInfor } catch (SecurityException e) { throw new UnsupportedOperationException("Serialization not possible.", e); } - // Type class - ByteArrayUtil.writeString(buffer, object.getRestrictionClass().getName()); + // Use *factory* class! + ByteArrayUtil.writeString(buffer, object.getFactory().getClass().getName()); // Name, or an empty string. ByteArrayUtil.writeString(buffer, object.getLabel()); // Serializer class @@ -320,7 +322,7 @@ public class TypeInformationSerializer implements ByteBufferSerializer<TypeInfor try { // Factory type! String typename = ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer); - NumberVector.Factory<DoubleVector, ?> factory = (NumberVector.Factory<DoubleVector, ?>) ClassGenericsUtil.instantiate(NumberVector.Factory.class, typename); + NumberVector.Factory<DoubleVector> factory = (NumberVector.Factory<DoubleVector>) ClassGenericsUtil.instantiate(NumberVector.Factory.class, typename); // Relation label String label = ByteArrayUtil.STRING_SERIALIZER.fromByteBuffer(buffer); label = ("".equals(label)) ? null : label; @@ -346,9 +348,7 @@ public class TypeInformationSerializer implements ByteBufferSerializer<TypeInfor throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate factory: "+e, e); } catch (ClassNotFoundException e) { throw new UnsupportedOperationException("Cannot deserialize - class not found: "+e, e); - } catch (InstantiationException e) { - throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate serializer: "+e.getMessage(), e); - } catch (IllegalAccessException e) { + } catch (InstantiationException | IllegalAccessException e) { throw new UnsupportedOperationException("Cannot deserialize - cannot instantiate serializer: "+e.getMessage(), e); } } |