blob: b64c08fabc5987c7401c40f9c425c2dacdc1d1ce (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.skynet.core.attribute;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.internal.Activator;
public final class JavaObjectAttribute extends BinaryAttribute<Object> {
@Override
public Object getValue() throws OseeCoreException {
return getObjectFromBytes(getAttributeDataProvider().getValueAsBytes());
}
private Object getObjectFromBytes(ByteBuffer buffer) {
Object obj = null;
InputStream inputStream = null;
ObjectInputStream objectStream = null;
try {
inputStream = Lib.byteBufferToInputStream(buffer);
if (inputStream != null) {
objectStream = new ObjectInputStream(inputStream);
obj = objectStream.readObject();
}
} catch (Exception ex) {
OseeLog.log(Activator.class, Level.SEVERE, ex);
} finally {
try {
if (inputStream != null) {
inputStream.reset();
}
} catch (IOException ex) {
OseeLog.log(Activator.class, Level.SEVERE, ex);
}
try {
if (objectStream != null) {
objectStream.close();
}
} catch (IOException ex) {
OseeLog.log(Activator.class, Level.SEVERE, ex);
}
}
return obj;
}
@Override
public boolean subClassSetValue(Object value) {
try {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream objectStream = new ObjectOutputStream(byteStream);
objectStream.writeObject(value);
objectStream.flush();
objectStream.close();
getAttributeDataProvider().setValue(ByteBuffer.wrap(byteStream.toByteArray()));
getAttributeDataProvider().setDisplayableString(value != null ? value.getClass().getName() : "null");
} catch (Exception ex) {
OseeLog.log(Activator.class, Level.SEVERE, ex);
}
return true;
}
@Override
public Object convertStringToValue(String value) {
if (value == null) {
return null;
}
return getObjectFromBytes(ByteBuffer.wrap(value.getBytes()));
}
}
|