Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -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.rest.impl; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import com.google.common.collect.Maps; |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Service; |
| 24 | import org.onosproject.rest.ApiDocProvider; |
| 25 | import org.onosproject.rest.ApiDocService; |
| 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
| 29 | import java.util.Map; |
| 30 | import java.util.Set; |
| 31 | |
| 32 | /** |
| 33 | * Implementation of the REST API documentation tracker. |
| 34 | */ |
| 35 | @Component(immediate = true) |
| 36 | @Service |
| 37 | public class ApiDocManager implements ApiDocService { |
| 38 | |
| 39 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 40 | |
| 41 | // Set of doc providers |
| 42 | private final Map<String, ApiDocProvider> providers = Maps.newConcurrentMap(); |
| 43 | |
| 44 | @Activate |
| 45 | public void activate() { |
| 46 | log.info("Started"); |
| 47 | } |
| 48 | |
| 49 | @Deactivate |
| 50 | public void deactivate() { |
| 51 | log.info("Stopped"); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void register(ApiDocProvider provider) { |
| 56 | providers.put(provider.key(), provider); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void unregister(ApiDocProvider provider) { |
| 61 | providers.remove(provider.name()); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public Set<ApiDocProvider> getDocProviders() { |
| 66 | return ImmutableSet.copyOf(providers.values()); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public ApiDocProvider getDocProvider(String key) { |
| 71 | return providers.get(key); |
| 72 | } |
| 73 | } |