Gaurav Agrawal | 8ce6d5c | 2017-05-03 18:23:00 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present 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 | |
| 17 | package org.onosproject.yang; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 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.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
| 26 | import org.onosproject.core.CoreService; |
| 27 | import org.onosproject.yang.compiler.api.YangCompilationParam; |
| 28 | import org.onosproject.yang.compiler.api.YangCompiledOutput; |
| 29 | import org.onosproject.yang.compiler.api.YangCompilerException; |
| 30 | import org.onosproject.yang.compiler.api.YangCompilerService; |
Gaurav Agrawal | ce2686a | 2017-05-13 14:27:40 +0530 | [diff] [blame] | 31 | import org.onosproject.yang.compiler.tool.YangCompilerManager; |
Gaurav Agrawal | 8ce6d5c | 2017-05-03 18:23:00 +0530 | [diff] [blame] | 32 | import org.slf4j.Logger; |
| 33 | import org.slf4j.LoggerFactory; |
| 34 | |
| 35 | import java.io.IOException; |
| 36 | |
| 37 | /** |
| 38 | * Represents implementation of YANG live compiler manager. |
| 39 | */ |
| 40 | @Beta |
| 41 | @Service |
| 42 | @Component(immediate = true) |
| 43 | public class YangLiveCompilerManager implements YangCompilerService { |
| 44 | |
| 45 | private static final String APP_ID = "org.onosproject.yang"; |
| 46 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 47 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 48 | protected CoreService coreService; |
Gaurav Agrawal | 8ce6d5c | 2017-05-03 18:23:00 +0530 | [diff] [blame] | 49 | |
| 50 | @Activate |
| 51 | public void activate() { |
| 52 | coreService.registerApplication(APP_ID); |
Gaurav Agrawal | 8ce6d5c | 2017-05-03 18:23:00 +0530 | [diff] [blame] | 53 | log.info("Started"); |
| 54 | } |
| 55 | |
| 56 | @Deactivate |
| 57 | public void deactivate() { |
| 58 | log.info("Stopped"); |
| 59 | } |
| 60 | |
Gaurav Agrawal | 8ce6d5c | 2017-05-03 18:23:00 +0530 | [diff] [blame] | 61 | @Override |
| 62 | public YangCompiledOutput compileYangFiles(YangCompilationParam param) |
| 63 | throws IOException, YangCompilerException { |
Gaurav Agrawal | ce2686a | 2017-05-13 14:27:40 +0530 | [diff] [blame] | 64 | return new YangCompilerManager().compileYangFiles(param); |
Gaurav Agrawal | 8ce6d5c | 2017-05-03 18:23:00 +0530 | [diff] [blame] | 65 | } |
| 66 | } |