ObjectOutputStream os;
try {
os = new ObjectOutputStream(outputStream);
}
catch (IOException e) {
throw new TestContainerException("can't write stream headers", e);
}
String id = configOption.getId();
if (id == null) {
throw new TestContainerException("ConfigurationOption id can't be null");
}
try {
os.writeObject(id);
os.writeBoolean(configOption.isCreate());
os.writeBoolean(configOption.isOverride());
os.writeBoolean(configOption.isFactory());
Map<String, ?> properties = configOption.getProperties();
if (properties == null) {
throw new TestContainerException("ConfigurationOption properties can't be null");
}
try {
os.writeObject(new HashMap<String, Object>(properties));
}
catch (NotSerializableException e) {
throw new TestContainerException(
"One of the values of the ConfigurationOption properties are not serializable",
e);
}
os.flush();
os.close();
}
catch (IOException e) {
throw new TestContainerException("Writing object data failed", e);
}
ByteArrayInputStream stream = new ByteArrayInputStream(outputStream.toByteArray());
TinyBundle bundle = TinyBundles.bundle();
bundle.add(ConfigurationOptionConfigurationListener.class);
bundle.add(ConfigurationOptionActivator.class).add("override.obj", stream);