alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.driver.pipeline; |
| 17 | |
| 18 | import org.apache.felix.scr.annotations.Activate; |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Component; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 20 | import org.apache.felix.scr.annotations.Deactivate; |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Service; |
| 22 | import org.onosproject.net.driver.DefaultDriverProviderService; |
| 23 | import org.onosproject.net.driver.Driver; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 24 | import org.onosproject.net.driver.DriverProvider; |
| 25 | import org.onosproject.net.driver.XmlDriverLoader; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
| 29 | import java.io.IOException; |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 30 | import java.io.InputStream; |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 31 | import java.util.Set; |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Bootstrap for built in drivers. |
| 35 | */ |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 36 | @Service |
| 37 | @Component(immediate = false) |
| 38 | public class DefaultDrivers implements DefaultDriverProviderService { |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 39 | |
| 40 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 41 | |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 42 | private static final String DRIVERS_XML = "/onos-drivers.xml"; |
| 43 | |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 44 | private DriverProvider provider; |
| 45 | |
| 46 | @Activate |
| 47 | protected void activate() { |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 48 | ClassLoader classLoader = getClass().getClassLoader(); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 49 | try { |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 50 | InputStream stream = classLoader.getResourceAsStream(DRIVERS_XML); |
| 51 | provider = new XmlDriverLoader(classLoader).loadDrivers(stream); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 52 | } catch (IOException e) { |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 53 | log.error("Unable to load default drivers", e); |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 54 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 55 | log.info("Started"); |
| 56 | } |
| 57 | |
| 58 | @Deactivate |
| 59 | protected void deactivate() { |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 60 | log.info("Stopped"); |
| 61 | } |
| 62 | |
Jonathan Hart | 17d0045 | 2015-04-21 17:10:00 -0700 | [diff] [blame] | 63 | @Override |
| 64 | public Set<Driver> getDrivers() { |
| 65 | return provider.getDrivers(); |
| 66 | } |
alshabib | 77b8848 | 2015-04-07 15:47:50 -0700 | [diff] [blame] | 67 | } |