Project

General

Profile

« Previous | Next » 

Revision baafe6d6

Added by Patrick Plitzner over 5 years ago

code cleanup

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/CdmObjectTransfer.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
30 30
 * @version 1.0
31 31
 */
32 32
public abstract class CdmObjectTransfer<T extends ICdmBase> extends ByteArrayTransfer {
33
	
34
	/* (non-Javadoc)
35
	 * @see org.eclipse.swt.dnd.ByteArrayTransfer#javaToNative(java.lang.Object, org.eclipse.swt.dnd.TransferData)
36
	 */
33

  
37 34
	@Override
38 35
	protected void javaToNative(Object object, TransferData transferData) {
39 36
		if (object != null){
40 37
			byte[] bytes = toByteArray((T[]) object);
41
			if (bytes != null)
42
				super.javaToNative(bytes, transferData);
38
			if (bytes != null) {
39
                super.javaToNative(bytes, transferData);
40
            }
43 41
		}
44 42
	}
45
	
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.swt.dnd.ByteArrayTransfer#nativeToJava(org.eclipse.swt.dnd.TransferData)
48
	 */
43

  
49 44
	@Override
50 45
	protected Object nativeToJava(TransferData transferData) {
51 46
		byte[] bytes = (byte[]) super.nativeToJava(transferData);
......
54 49
		}
55 50
		return null;
56 51
	}
57
		
58
	
52

  
53

  
59 54
	protected byte[] toByteArray(T[] elements) {
60 55
		ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
61 56
		DataOutputStream out = new DataOutputStream(byteOut);
......
63 58
		byte[] bytes = null;
64 59

  
65 60
		try {
66
			
61

  
67 62
			for(T element : elements){
68 63
				writeElementUuid(element, out);
69 64
			}
......
74 69
		}
75 70
		return bytes;
76 71
	}
77
	
72

  
78 73
	private void writeElementUuid(T element, DataOutputStream out) throws IOException {
79
		out.writeUTF(element.getUuid().toString());		
74
		out.writeUTF(element.getUuid().toString());
80 75
	}
81 76

  
82 77
	protected Object fromByteArray(byte[] bytes) {
......
85 80

  
86 81
		try {
87 82
			List<T> elements = new ArrayList<T>();
88
			
83

  
89 84
			try{
90 85
				while(true){
91 86
					UUID uuid = readElementUuid(in);
......
100 95
	}
101 96

  
102 97
	public abstract T loadElement(UUID uuid);
103
	
104
	/**
105
	 * @param in
106
	 * @return
107
	 * @throws IOException 
108
	 */
98

  
109 99
	public UUID readElementUuid(DataInputStream in) throws IOException{
110 100
		return UUID.fromString(in.readUTF());
111 101
	}

Also available in: Unified diff