/**
* 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.
*/
*
* @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"; //$NON-NLS-1$
- private static final int TYPE_ID = registerType (TYPE_NAME);
+ private static final int TYPE_ID = registerType (TYPE_NAME);
private static final CdmDataTransfer instance = new CdmDataTransfer();
-
+
/**
* <p>Getter for the field <code>instance</code>.</p>
*
}
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);
byte[] bytes = null;
try {
-
+
for(ICdmBase cdmBaseObject : cdmBaseObjects){
writeCdmBaseObject(cdmBaseObject, out);
}
}
return bytes;
}
-
-
+
+
private ICdmBase[] fromByteArray(byte[] bytes) {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
-
+
try {
List<ICdmBase> cdmBaseObjects = new ArrayList<ICdmBase>();
-
+
try{
while(true){
cdmBaseObjects.add(readCdmBaseObject(in));
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;