use of org.opennms.core.config.api.ConfigurationResourceException in project opennms by OpenNMS.
the class JaxbResourceConfiguration method save.
public void save(final T config) throws ConfigurationResourceException {
final Resource r = getResource();
if (!(r instanceof WritableResource)) {
throw new ConfigurationResourceException("Resource " + r + " is not writable!");
}
final WritableResource resource = (WritableResource) r;
OutputStream os = null;
OutputStreamWriter osw = null;
try {
os = resource.getOutputStream();
osw = new OutputStreamWriter(os);
JaxbUtils.marshal(config, osw);
} catch (final IOException e) {
throw new ConfigurationResourceException("Failed to write to " + r, e);
} catch (final Exception e) {
throw new ConfigurationResourceException("Failed to marshal configuration " + getClassType() + " to resource " + r, e);
} finally {
IOUtils.closeQuietly(osw);
IOUtils.closeQuietly(os);
}
}
use of org.opennms.core.config.api.ConfigurationResourceException in project opennms by OpenNMS.
the class JaxbResourceConfiguration method get.
public T get() throws ConfigurationResourceException {
final Class<T> classType = getClassType();
final Resource resource = getResource();
try {
return JaxbUtils.unmarshal(classType, resource);
} catch (final Exception e) {
throw new ConfigurationResourceException("Failed to unmarshal " + resource + " to class " + classType, e);
}
}
Aggregations