}
public static JdbcResource getJdbcResource(final String fileName,
final String name) throws SyncDatabaseException, IOException {
if (fileName == null || name == null) {
throw new SyncDatabaseException("error.argument");
}
final Digester digester = new Digester();
digester.addObjectCreate("SyncDatabase", JdbcResources.class);
digester.addObjectCreate("SyncDatabase/jdbcResource",
JdbcResource.class);
digester.addSetNext("SyncDatabase/jdbcResource", "addJdbcResources");
digester.addBeanPropertySetter("SyncDatabase/jdbcResource/name");
digester.addBeanPropertySetter("SyncDatabase/jdbcResource/className");
digester.addBeanPropertySetter("SyncDatabase/jdbcResource/url");
digester.addBeanPropertySetter("SyncDatabase/jdbcResource/username");
digester.addBeanPropertySetter("SyncDatabase/jdbcResource/password");
final InputStream is = JdbcResource.class.getClassLoader()
.getResourceAsStream(fileName);
if (is == null) {
throw new SyncDatabaseException("error.resourcefile_notfound",
fileName);
}
JdbcResources resources = null;
try {
resources = (JdbcResources) digester.parse(is);
} catch (final Exception e) {
throw new SyncDatabaseException("error.resourcefile_parse", e
.getMessage());
} finally {
is.close();
}
if (resources == null) {
throw new SyncDatabaseException("error.resource_notfound", name);
}
for (final JdbcResource resource : resources.getJdbcResources()) {
if (resource.getName().equals(name)) {
return resource;
}
}
throw new SyncDatabaseException("error.resource_notfound", name);
}