throw new OpenEJBException(e);
}
}
private synchronized void saveDeployment(final File file, boolean add) {
final Deployments deps = new Deployments();
if (file.isDirectory()) {
deps.setDir(file.getAbsolutePath());
} else {
deps.setJar(file.getAbsolutePath());
}
File config;
try {
config = SystemInstance.get().getBase().getFile(ADDITIONAL_DEPLOYMENTS, false);
} catch (IOException e) {
config = null;
}
if (config == null || !config.getParentFile().exists()) {
LOGGER.error("can't save the added app because the conf folder doesn't exist, it will not be present next time you'll start");
return;
}
// dump it
OutputStream os = null;
try {
final AdditionalDeployments additionalDeployments;
if (config.exists() && config.length() > 0) {
final InputStream fis = IO.read(config);
try {
additionalDeployments = JaxbOpenejb.unmarshal(AdditionalDeployments.class, fis);
} finally {
IO.close(fis);
}
} else {
additionalDeployments = new AdditionalDeployments();
}
if (add) {
additionalDeployments.getDeployments().add(deps);
} else {
Iterator<Deployments> it = additionalDeployments.getDeployments().iterator();
while (it.hasNext()) {
final Deployments current = it.next();
if (deps.getDir() != null && deps.getDir().equals(current.getDir())) {
it.remove();
break;
} else if (deps.getJar() != null && deps.getJar().equals(current.getJar())) {
it.remove();
break;
}
}
}