Allowing driver loaders to refer to classes loaded by others.
Change-Id: Ife4e50758620d4c052a7bb81740d9b9305647317
diff --git a/core/api/src/main/java/org/onosproject/net/driver/AbstractDriverLoader.java b/core/api/src/main/java/org/onosproject/net/driver/AbstractDriverLoader.java
index e35c1b4..e68eb99 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/AbstractDriverLoader.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/AbstractDriverLoader.java
@@ -49,7 +49,7 @@
@Activate
protected void activate() {
try {
- provider = new XmlDriverLoader(getClass().getClassLoader())
+ provider = new XmlDriverLoader(getClass().getClassLoader(), driverAdminService)
.loadDrivers(getClass().getResourceAsStream(path), driverAdminService);
driverAdminService.registerProvider(provider);
} catch (Exception e) {
diff --git a/core/api/src/main/java/org/onosproject/net/driver/BehaviourClassResolver.java b/core/api/src/main/java/org/onosproject/net/driver/BehaviourClassResolver.java
new file mode 100644
index 0000000..a5474f0
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/driver/BehaviourClassResolver.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.driver;
+
+/**
+ * Entity capable of resolving a class using its name.
+ */
+public interface BehaviourClassResolver {
+
+ /**
+ * Returns the class corresponding to the specified class name.
+ * @param className class className
+ * @return
+ */
+ Class<? extends Behaviour> getBehaviourClass(String className);
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/driver/DriverAdminService.java b/core/api/src/main/java/org/onosproject/net/driver/DriverAdminService.java
index ba5bd69..f9f2532 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/DriverAdminService.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/DriverAdminService.java
@@ -20,7 +20,7 @@
/**
* Service for managing drivers and driver behaviour implementations.
*/
-public interface DriverAdminService extends DriverService {
+public interface DriverAdminService extends DriverService, BehaviourClassResolver {
/**
* Returns the set of driver providers currently registered.
diff --git a/core/api/src/main/java/org/onosproject/net/driver/XmlDriverLoader.java b/core/api/src/main/java/org/onosproject/net/driver/XmlDriverLoader.java
index e63e710..30d1875 100644
--- a/core/api/src/main/java/org/onosproject/net/driver/XmlDriverLoader.java
+++ b/core/api/src/main/java/org/onosproject/net/driver/XmlDriverLoader.java
@@ -64,6 +64,7 @@
private static final String IMPL = "[@impl]";
private final ClassLoader classLoader;
+ private final BehaviourClassResolver resolver;
private Map<String, Driver> drivers = Maps.newHashMap();
@@ -72,9 +73,23 @@
* class loader.
*
* @param classLoader class loader to use
+ * @deprecated since 1.7.0 (Hummingbird)
*/
+ @Deprecated
public XmlDriverLoader(ClassLoader classLoader) {
+ this(classLoader, null);
+ }
+
+ /**
+ * Creates a new driver loader capable of loading drivers from the supplied
+ * class loader.
+ *
+ * @param classLoader class loader to use
+ * @param resolver behaviour class resolver
+ */
+ public XmlDriverLoader(ClassLoader classLoader, BehaviourClassResolver resolver) {
this.classLoader = classLoader;
+ this.resolver = resolver;
}
/**
@@ -182,7 +197,13 @@
try {
return (Class<? extends Behaviour>) classLoader.loadClass(className);
} catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("Unable to load class " + className, e);
+ if (resolver != null) {
+ Class<? extends Behaviour> cls = resolver.getBehaviourClass(className);
+ if (cls != null) {
+ return cls;
+ }
+ }
+ throw new IllegalArgumentException("Unable to resolve class " + className, e);
}
}