X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/e3240965ccd65c0d123d05e13d04e7820fe01f85..22ac94a93b53f98b115b3edd4f23ce611b91c4cf:/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/CdmDataTransfer.java
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/CdmDataTransfer.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/CdmDataTransfer.java
index 62038000a..801a7021b 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/CdmDataTransfer.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/CdmDataTransfer.java
@@ -1,8 +1,8 @@
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
@@ -34,18 +34,18 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
*
* @author n.hoffmann
* @created Jun 18, 2010
- * @version 1.0
*/
public class CdmDataTransfer extends ByteArrayTransfer {
- private static final Logger logger = Logger
- .getLogger(CdmDataTransfer.class);
+
+ @SuppressWarnings("unused")
+ private static final Logger logger = Logger.getLogger(CdmDataTransfer.class);
private static int SEPARATOR = -10;
private static int EOF = -20;
- private static final String TYPE_NAME = "cdmdata-transfer-format";
- private static final int TYPE_ID = registerType (TYPE_NAME);
+ private static final String TYPE_NAME = "cdmdata-transfer-format"; //$NON-NLS-1$
+ private static final int TYPE_ID = registerType (TYPE_NAME);
private static final CdmDataTransfer instance = new CdmDataTransfer();
-
+
/**
*
Getter for the field instance
.
*
@@ -56,36 +56,25 @@ public class CdmDataTransfer extends ByteArrayTransfer {
}
private ICdmBase cdmBase;
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.dnd.Transfer#getTypeIds()
- */
- /** {@inheritDoc} */
+
@Override
protected int[] getTypeIds() {
- return new int[] { TYPE_ID };
+ return new int[] { TYPE_ID };
}
- /* (non-Javadoc)
- * @see org.eclipse.swt.dnd.Transfer#getTypeNames()
- */
- /** {@inheritDoc} */
@Override
protected String[] getTypeNames() {
return new String[]{ TYPE_NAME };
}
- /** {@inheritDoc} */
@Override
protected void javaToNative(Object object, TransferData transferData) {
byte[] bytes = toByteArray((ICdmBase[]) object);
- if (bytes != null)
- super.javaToNative(bytes, transferData);
+ if (bytes != null) {
+ super.javaToNative(bytes, transferData);
+ }
}
-
-
- /** {@inheritDoc} */
@Override
protected Object nativeToJava(TransferData transferData) {
byte[] bytes = (byte[]) super.nativeToJava(transferData);
@@ -105,7 +94,7 @@ public class CdmDataTransfer extends ByteArrayTransfer {
byte[] bytes = null;
try {
-
+
for(ICdmBase cdmBaseObject : cdmBaseObjects){
writeCdmBaseObject(cdmBaseObject, out);
}
@@ -116,14 +105,14 @@ public class CdmDataTransfer extends ByteArrayTransfer {
}
return bytes;
}
-
-
+
+
private ICdmBase[] fromByteArray(byte[] bytes) {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
-
+
try {
List cdmBaseObjects = new ArrayList();
-
+
try{
while(true){
cdmBaseObjects.add(readCdmBaseObject(in));
@@ -135,36 +124,36 @@ public class CdmDataTransfer extends ByteArrayTransfer {
return null;
}
}
-
+
private ICdmBase readCdmBaseObject(DataInputStream in) throws IOException{
String className = in.readUTF();
in.readInt();
String idString = in.readUTF();
in.readInt();
-
+
if(className.equals(Synonym.class.getName()) || className.equals(Taxon.class.getName())){
ICdmBase object = CdmStore.getService(ITaxonService.class).load(UUID.fromString(idString));
-
+
if(object == null){
return cdmBase;
}
-
+
return object;
}
-
+
return null;
}
-
+
private void writeCdmBaseObject(ICdmBase cdmBase, DataOutputStream out) throws IOException{
/**
* CdmBase object serialization:
- *
+ *
*/
out.writeUTF(cdmBase.getClass().getName());
out.writeInt(SEPARATOR);
out.writeUTF(cdmBase.getUuid().toString());
out.writeInt(EOF);
-
+
if(cdmBase.getId() == 0){
// fallback for unsaved instances
this.cdmBase = cdmBase;