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; ...@@ -23,31 +23,37 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.slf4j.Logger; 23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory; 24 import org.slf4j.LoggerFactory;
25 25
26 -import java.io.InputStream;
27 -
28 /** 26 /**
29 - * Bootstrap for built in drivers. 27 + * Abstract boot-strapper for loading and registering driver definitions.
30 */ 28 */
31 @Component 29 @Component
32 public abstract class AbstractDriverLoader { 30 public abstract class AbstractDriverLoader {
33 31
34 private final Logger log = LoggerFactory.getLogger(getClass()); 32 private final Logger log = LoggerFactory.getLogger(getClass());
35 33
36 - //private static final String DRIVERS_XML = "/onos-drivers.xml";
37 -
38 private DriverProvider provider; 34 private DriverProvider provider;
35 + private final String path;
39 36
40 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 37 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
41 protected DriverAdminService driverAdminService; 38 protected DriverAdminService driverAdminService;
42 39
40 + /**
41 + * Creates a new loader for resource with the specified path.
42 + *
43 + * @param path drivers definition XML resource path
44 + */
45 + protected AbstractDriverLoader(String path) {
46 + this.path = path;
47 + }
48 +
43 @Activate 49 @Activate
44 protected void activate() { 50 protected void activate() {
45 try { 51 try {
46 - provider = new XmlDriverLoader(getClassLoaderInstance()) 52 + provider = new XmlDriverLoader(getClass().getClassLoader())
47 - .loadDrivers(loadXmlDriversStream(), driverAdminService); 53 + .loadDrivers(getClass().getResourceAsStream(path), driverAdminService);
48 driverAdminService.registerProvider(provider); 54 driverAdminService.registerProvider(provider);
49 } catch (Exception e) { 55 } catch (Exception e) {
50 - log.error("Unable to load default drivers", e); 56 + log.error("Unable to load {} driver definitions", path, e);
51 } 57 }
52 log.info("Started"); 58 log.info("Started");
53 } 59 }
...@@ -58,8 +64,4 @@ public abstract class AbstractDriverLoader { ...@@ -58,8 +64,4 @@ public abstract class AbstractDriverLoader {
58 log.info("Stopped"); 64 log.info("Stopped");
59 } 65 }
60 66
61 - protected abstract InputStream loadXmlDriversStream();
62 -
63 - protected abstract ClassLoader getClassLoaderInstance();
64 -
65 } 67 }
......
...@@ -19,23 +19,12 @@ package org.onosproject.drivers.ciena; ...@@ -19,23 +19,12 @@ package org.onosproject.drivers.ciena;
19 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
20 import org.onosproject.net.driver.AbstractDriverLoader; 20 import org.onosproject.net.driver.AbstractDriverLoader;
21 21
22 -import java.io.InputStream;
23 -
24 /** 22 /**
25 - * Loader for Ciena device drivers from specific xml. 23 + * Loader for Ciena device drivers.
26 */ 24 */
27 @Component(immediate = true) 25 @Component(immediate = true)
28 public class CienaDriversLoader extends AbstractDriverLoader { 26 public class CienaDriversLoader extends AbstractDriverLoader {
29 - 27 + public CienaDriversLoader() {
30 - private static final String DRIVERS_XML = "/ciena-drivers.xml"; 28 + super("/ciena-drivers.xml");
31 -
32 - @Override
33 - protected InputStream loadXmlDriversStream() {
34 - return getClassLoaderInstance().getResourceAsStream(DRIVERS_XML);
35 - }
36 -
37 - @Override
38 - protected ClassLoader getClassLoaderInstance() {
39 - return getClass().getClassLoader();
40 } 29 }
41 } 30 }
......
...@@ -21,24 +21,13 @@ import org.apache.felix.scr.annotations.Service; ...@@ -21,24 +21,13 @@ import org.apache.felix.scr.annotations.Service;
21 import org.onosproject.net.driver.AbstractDriverLoader; 21 import org.onosproject.net.driver.AbstractDriverLoader;
22 import org.onosproject.net.driver.DefaultDriverProviderService; 22 import org.onosproject.net.driver.DefaultDriverProviderService;
23 23
24 -import java.io.InputStream;
25 -
26 /** 24 /**
27 - * Loader for default device drivers from specific xml. 25 + * Loader for default device drivers.
28 */ 26 */
29 @Service 27 @Service
30 @Component(immediate = true) 28 @Component(immediate = true)
31 public class DefaultDriversLoader extends AbstractDriverLoader implements DefaultDriverProviderService { 29 public class DefaultDriversLoader extends AbstractDriverLoader implements DefaultDriverProviderService {
32 - 30 + public DefaultDriversLoader() {
33 - private static final String DRIVERS_XML = "/onos-drivers.xml"; 31 + super("/onos-drivers.xml");
34 -
35 - @Override
36 - protected InputStream loadXmlDriversStream() {
37 - return getClassLoaderInstance().getResourceAsStream(DRIVERS_XML);
38 - }
39 -
40 - @Override
41 - protected ClassLoader getClassLoaderInstance() {
42 - return getClass().getClassLoader();
43 } 32 }
44 } 33 }
......
...@@ -19,23 +19,12 @@ package org.onosproject.drivers.fujitsu; ...@@ -19,23 +19,12 @@ package org.onosproject.drivers.fujitsu;
19 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
20 import org.onosproject.net.driver.AbstractDriverLoader; 20 import org.onosproject.net.driver.AbstractDriverLoader;
21 21
22 -import java.io.InputStream;
23 -
24 /** 22 /**
25 - * Loader for Fujitsu device drivers from specific xml. 23 + * Loader for Fujitsu device drivers.
26 */ 24 */
27 @Component(immediate = true) 25 @Component(immediate = true)
28 public class FujitsuDriversLoader extends AbstractDriverLoader { 26 public class FujitsuDriversLoader extends AbstractDriverLoader {
29 - 27 + public FujitsuDriversLoader() {
30 - private static final String DRIVERS_XML = "/fujitsu-drivers.xml"; 28 + super("/fujitsu-drivers.xml");
31 -
32 - @Override
33 - protected InputStream loadXmlDriversStream() {
34 - return getClassLoaderInstance().getResourceAsStream(DRIVERS_XML);
35 - }
36 -
37 - @Override
38 - protected ClassLoader getClassLoaderInstance() {
39 - return getClass().getClassLoader();
40 } 29 }
41 } 30 }
......
...@@ -19,23 +19,12 @@ package org.onosproject.drivers.netconf; ...@@ -19,23 +19,12 @@ package org.onosproject.drivers.netconf;
19 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
20 import org.onosproject.net.driver.AbstractDriverLoader; 20 import org.onosproject.net.driver.AbstractDriverLoader;
21 21
22 -import java.io.InputStream;
23 -
24 /** 22 /**
25 - * Loader for NETCONF device drivers from specific xml. 23 + * Loader for NETCONF device drivers.
26 */ 24 */
27 @Component(immediate = true) 25 @Component(immediate = true)
28 public class NetconfDriversLoader extends AbstractDriverLoader { 26 public class NetconfDriversLoader extends AbstractDriverLoader {
29 - 27 + public NetconfDriversLoader() {
30 - private static final String DRIVERS_XML = "/netconf-drivers.xml"; 28 + super("/netconf-drivers.xml");
31 -
32 - @Override
33 - protected InputStream loadXmlDriversStream() {
34 - return getClassLoaderInstance().getResourceAsStream(DRIVERS_XML);
35 - }
36 -
37 - @Override
38 - protected ClassLoader getClassLoaderInstance() {
39 - return getClass().getClassLoader();
40 } 29 }
41 } 30 }
......
...@@ -19,23 +19,12 @@ package org.onosproject.drivers.ovsdb; ...@@ -19,23 +19,12 @@ package org.onosproject.drivers.ovsdb;
19 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
20 import org.onosproject.net.driver.AbstractDriverLoader; 20 import org.onosproject.net.driver.AbstractDriverLoader;
21 21
22 -import java.io.InputStream;
23 -
24 /** 22 /**
25 - * Loader for OVSDB device drivers from specific xml. 23 + * Loader for OVSDB device drivers.
26 */ 24 */
27 @Component(immediate = true) 25 @Component(immediate = true)
28 public class OvsdbDriversLoader extends AbstractDriverLoader { 26 public class OvsdbDriversLoader extends AbstractDriverLoader {
29 - 27 + public OvsdbDriversLoader() {
30 - private static final String DRIVERS_XML = "/ovsdb-drivers.xml"; 28 + super("/ovsdb-drivers.xml");
31 -
32 - @Override
33 - protected InputStream loadXmlDriversStream() {
34 - return getClassLoaderInstance().getResourceAsStream(DRIVERS_XML);
35 - }
36 -
37 - @Override
38 - protected ClassLoader getClassLoaderInstance() {
39 - return getClass().getClassLoader();
40 } 29 }
41 } 30 }
......