All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.protege.osgi.jdbc.impl.JdbcRegistryImpl Maven / Gradle / Ivy

There is a newer version: 5.2.1.1
Show newest version
package org.protege.osgi.jdbc.impl;

import org.protege.osgi.jdbc.JdbcRegistry;
import org.protege.osgi.jdbc.RegistryException;

import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Driver;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class JdbcRegistryImpl implements JdbcRegistry {

	private List drivers = new ArrayList<>();

	public void addJdbcDriver(String className, URL location)
			throws RegistryException {
		try {
			URLClassLoader classLoader = new URLClassLoader(new URL[] { location }, ClassLoader.getSystemClassLoader());
			Class driverClass = classLoader.loadClass(className);
			Driver driver = (Driver) driverClass.newInstance();
			drivers.add(driver);
		}
		catch (InstantiationException | ClassNotFoundException | IllegalAccessException ie) {
			throw new RegistryException(ie);
		}
    }

    public void removeJdbcDriver(String className) {
		Driver found = null;
		for (Driver driver : drivers) {
			if (driver.getClass().toString().equals(className)) {
				found = driver;
				break;
			}
		}
		if (found != null) {
			drivers.remove(found);
		}
	}

	public List getJdbcDrivers() {
		return Collections.unmodifiableList(drivers);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy