Thomas Vachuska
Committed by Gerrit Code Review

Simplifying the use-model of AbstractDriverLoader.

Change-Id: Iaf19ce92c7e153b5477340abb8e7650d8434ca86

Simplifying the use-model of AbstractDriverLoader.

Change-Id: Iaf19ce92c7e153b5477340abb8e7650d8434ca86
......@@ -23,31 +23,37 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
/**
* Bootstrap for built in drivers.
* Abstract boot-strapper for loading and registering driver definitions.
*/
@Component
public abstract class AbstractDriverLoader {
private final Logger log = LoggerFactory.getLogger(getClass());
//private static final String DRIVERS_XML = "/onos-drivers.xml";
private DriverProvider provider;
private final String path;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DriverAdminService driverAdminService;
/**
* Creates a new loader for resource with the specified path.
*
* @param path drivers definition XML resource path
*/
protected AbstractDriverLoader(String path) {
this.path = path;
}
@Activate
protected void activate() {
try {
provider = new XmlDriverLoader(getClassLoaderInstance())
.loadDrivers(loadXmlDriversStream(), driverAdminService);
provider = new XmlDriverLoader(getClass().getClassLoader())
.loadDrivers(getClass().getResourceAsStream(path), driverAdminService);
driverAdminService.registerProvider(provider);
} catch (Exception e) {
log.error("Unable to load default drivers", e);
log.error("Unable to load {} driver definitions", path, e);
}
log.info("Started");
}
......@@ -58,8 +64,4 @@ public abstract class AbstractDriverLoader {
log.info("Stopped");
}
protected abstract InputStream loadXmlDriversStream();
protected abstract ClassLoader getClassLoaderInstance();
}
......
......@@ -19,23 +19,12 @@ package org.onosproject.drivers.ciena;
import org.apache.felix.scr.annotations.Component;
import org.onosproject.net.driver.AbstractDriverLoader;
import java.io.InputStream;
/**
* Loader for Ciena device drivers from specific xml.
* Loader for Ciena device drivers.
*/
@Component(immediate = true)
public class CienaDriversLoader extends AbstractDriverLoader {
private static final String DRIVERS_XML = "/ciena-drivers.xml";
@Override
protected InputStream loadXmlDriversStream() {
return getClassLoaderInstance().getResourceAsStream(DRIVERS_XML);
}
@Override
protected ClassLoader getClassLoaderInstance() {
return getClass().getClassLoader();
public CienaDriversLoader() {
super("/ciena-drivers.xml");
}
}
......
......@@ -21,24 +21,13 @@ import org.apache.felix.scr.annotations.Service;
import org.onosproject.net.driver.AbstractDriverLoader;
import org.onosproject.net.driver.DefaultDriverProviderService;
import java.io.InputStream;
/**
* Loader for default device drivers from specific xml.
* Loader for default device drivers.
*/
@Service
@Component(immediate = true)
public class DefaultDriversLoader extends AbstractDriverLoader implements DefaultDriverProviderService {
private static final String DRIVERS_XML = "/onos-drivers.xml";
@Override
protected InputStream loadXmlDriversStream() {
return getClassLoaderInstance().getResourceAsStream(DRIVERS_XML);
}
@Override
protected ClassLoader getClassLoaderInstance() {
return getClass().getClassLoader();
public DefaultDriversLoader() {
super("/onos-drivers.xml");
}
}
......
......@@ -19,23 +19,12 @@ package org.onosproject.drivers.fujitsu;
import org.apache.felix.scr.annotations.Component;
import org.onosproject.net.driver.AbstractDriverLoader;
import java.io.InputStream;
/**
* Loader for Fujitsu device drivers from specific xml.
* Loader for Fujitsu device drivers.
*/
@Component(immediate = true)
public class FujitsuDriversLoader extends AbstractDriverLoader {
private static final String DRIVERS_XML = "/fujitsu-drivers.xml";
@Override
protected InputStream loadXmlDriversStream() {
return getClassLoaderInstance().getResourceAsStream(DRIVERS_XML);
}
@Override
protected ClassLoader getClassLoaderInstance() {
return getClass().getClassLoader();
public FujitsuDriversLoader() {
super("/fujitsu-drivers.xml");
}
}
......
......@@ -19,23 +19,12 @@ package org.onosproject.drivers.netconf;
import org.apache.felix.scr.annotations.Component;
import org.onosproject.net.driver.AbstractDriverLoader;
import java.io.InputStream;
/**
* Loader for NETCONF device drivers from specific xml.
* Loader for NETCONF device drivers.
*/
@Component(immediate = true)
public class NetconfDriversLoader extends AbstractDriverLoader {
private static final String DRIVERS_XML = "/netconf-drivers.xml";
@Override
protected InputStream loadXmlDriversStream() {
return getClassLoaderInstance().getResourceAsStream(DRIVERS_XML);
}
@Override
protected ClassLoader getClassLoaderInstance() {
return getClass().getClassLoader();
public NetconfDriversLoader() {
super("/netconf-drivers.xml");
}
}
......
......@@ -19,23 +19,12 @@ package org.onosproject.drivers.ovsdb;
import org.apache.felix.scr.annotations.Component;
import org.onosproject.net.driver.AbstractDriverLoader;
import java.io.InputStream;
/**
* Loader for OVSDB device drivers from specific xml.
* Loader for OVSDB device drivers.
*/
@Component(immediate = true)
public class OvsdbDriversLoader extends AbstractDriverLoader {
private static final String DRIVERS_XML = "/ovsdb-drivers.xml";
@Override
protected InputStream loadXmlDriversStream() {
return getClassLoaderInstance().getResourceAsStream(DRIVERS_XML);
}
@Override
protected ClassLoader getClassLoaderInstance() {
return getClass().getClassLoader();
public OvsdbDriversLoader() {
super("/ovsdb-drivers.xml");
}
}
......