Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 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; |
| 17 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import org.osgi.service.component.annotations.Activate; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 19 | import org.osgi.service.component.annotations.Deactivate; |
| 20 | import org.osgi.service.component.annotations.Reference; |
| 21 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Self-registering REST API provider. |
| 25 | */ |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 26 | public abstract class AbstractApiDocRegistrator { |
| 27 | |
| 28 | protected final ApiDocProvider provider; |
| 29 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 30 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 31 | protected ApiDocService service; |
| 32 | |
| 33 | /** |
| 34 | * Creates registrator for the specified REST API doc provider. |
| 35 | * |
| 36 | * @param provider REST API provider |
| 37 | */ |
| 38 | protected AbstractApiDocRegistrator(ApiDocProvider provider) { |
| 39 | this.provider = provider; |
| 40 | } |
| 41 | |
| 42 | @Activate |
| 43 | protected void activate() { |
| 44 | service.register(provider); |
| 45 | } |
| 46 | |
| 47 | @Deactivate |
| 48 | protected void deactivate() { |
| 49 | service.unregister(provider); |
| 50 | } |
| 51 | } |