// Connect to the MCS device repository.
try {
String repositoryType =
Environment.getParameter(config, "repository-type");
LocalRepository repository;
DeviceRepositoryLocation location;
// NOTE: this configuration mirrored the "old" way of configuring
// local repositories, presumably it should be updated to
// mirror the new way?
if (repositoryType != null && repositoryType.equals("xml")) {
XMLRepositoryFactory factory =
XMLRepositoryFactory.getDefaultInstance();
repository = factory.createXMLRepository(null);
location = REPOSITORY_LOCATION_FACTORY.createDeviceRepositoryLocation(
Environment.getParameter(config, "file"));
} else {
// Default to JDBC.
JDBCRepositoryFactory factory =
JDBCRepositoryFactory.getDefaultInstance();
MCSDriverConfiguration driverConfiguration =
factory.createMCSDriverConfiguration();
driverConfiguration.setSource(
Environment.getParameter(config, "odbc-source"));
String vendor = Environment.getParameter(config, "odbc-vendor");
JDBCRepositoryType jdbcRepositoryType =
JDBCRepositoryType.getTypeForVendor(vendor);
if (jdbcRepositoryType != null) {
driverConfiguration.setDriverVendor(
jdbcRepositoryType.getVendor());
}
driverConfiguration.setHost(Environment.getParameter(config,
"odbc-host"));
String port = Environment.getParameter(config, "odbc-port");
if (port != null) {
driverConfiguration.setPort(Integer.parseInt(port));
}
DataSource dataSource = factory.createMCSDriverDataSource(
driverConfiguration);
JDBCRepositoryConfiguration configuration =
factory.createJDBCRepositoryConfiguration();
configuration.setDataSource(dataSource);
configuration.setUsername(Environment.getParameter(config,
"odbc-user"));
configuration.setPassword(Environment.getParameter(config,
"odbc-password"));
repository = factory.createJDBCRepository(configuration);
location = REPOSITORY_LOCATION_FACTORY.createDeviceRepositoryLocation(
Environment.getParameter(config, "project"));
}
accessor =
REPOSITORY_ACCESSOR_FACTORY.createDeviceRepositoryAccessor(
repository, location, null);
connection = repository.connect();
// NOTE: we may need to enable caching for performance.
// I'm not sure if we need to because the implementation of the
// device heirarchy is just about to completely change... so
// I'll leave this like so for now and we'll add caching if we
// have to later.