/* * Copyright 2003 Federal Chancellery Austria * MOA-SPSS has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package at.gv.egovernment.moa.spss.server.iaik.config; import java.sql.Driver; import java.sql.DriverManager; import java.util.Enumeration; import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; import iaik.pki.store.revocation.archive.ArchiveConfiguration; import iaik.pki.store.revocation.archive.ArchiveParameters; import iaik.pki.store.revocation.archive.ArchiveTypes; /** * An implementation of the ArchiveConfiguration interface using * configuration data provided by the MOA configuration file. * * @see iaik.pki.store.revocation.archive.ArchiveConfiguration * @author Patrick Peck * @version $Id$ */ public class ArchiveConfigurationImpl extends AbstractObservableConfiguration implements ArchiveConfiguration { /** The configuration parameters of the archive. */ private final ArchiveParameters archiveParameters; /** * Create a new ArchiveConfigurationImpl. * * @param config The MOA configuration from which the configuration data is * being read. */ public ArchiveConfigurationImpl(ConfigurationProvider config) { final String jdbcUrl = config.getRevocationArchiveJDBCURL(); this.archiveParameters = new DataBaseArchiveParameterImpl(jdbcUrl); // Register JDBC driver class if (jdbcUrl != null) { final String jdbcDriverClass = config.getRevocationArchiveJDBCDriverClass(); try { Class.forName(jdbcDriverClass); } catch (final ClassNotFoundException e) { // TODO 20030709 GK Improve exception handling throw new RuntimeException("JDBC driver class \"" + jdbcDriverClass + " could not be found."); } final Enumeration regDrivers = DriverManager.getDrivers(); boolean isRegistered = false; while (regDrivers.hasMoreElements()) { final Object currentDriver = regDrivers.nextElement(); if (jdbcDriverClass.equals(currentDriver.getClass().getName())) { isRegistered = true; } } if (!isRegistered) { // Workaround for a driver which does not register itselve at invocation of // Class.forName(drvname) try { DriverManager.registerDriver((Driver) Class.forName(jdbcDriverClass).newInstance()); } catch (final Exception e) { // TODO 20030709 GK Improve exception handling throw new RuntimeException("Registering JDBC driver \"" + jdbcDriverClass + " failed."); } } } } /** * Return the type of archive. * * This will always return ArchiveTypes.DATABASE. * * @return ArchiveTypes.DATABASE. * @see iaik.pki.store.revocation.archive.ArchiveConfiguration#getType() */ @Override public String getType() { return ArchiveTypes.DATABASE; } /** * Return the ArchiveParameters describing this * ArchiveConfiguration. * * @return The archive parameters. * @see iaik.pki.store.revocation.archive.ArchiveConfiguration#getArchiveParameters() */ @Override public ArchiveParameters getArchiveParameters() { return archiveParameters; } }