Require XPath parser implementation in RFC7950 reactors
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / impl / OSGiYangParserFactory.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.parser.impl;
9
10 import com.google.common.annotations.Beta;
11 import java.util.Collection;
12 import org.opendaylight.yangtools.yang.model.parser.api.YangParser;
13 import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
14 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
15 import org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory;
16 import org.osgi.service.component.annotations.Activate;
17 import org.osgi.service.component.annotations.Component;
18 import org.osgi.service.component.annotations.Deactivate;
19 import org.osgi.service.component.annotations.Reference;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 @Beta
24 @Component(immediate = true)
25 // FIXME: merge this with YangParserFactoryImpl once we have OSGi R7, which we really want because field injection is
26 //        a static analysis pain. It also results in not-obvious classes like this one.
27 public final class OSGiYangParserFactory implements YangParserFactory {
28     private static final Logger LOG = LoggerFactory.getLogger(OSGiYangParserFactory.class);
29
30     @Reference
31     YangXPathParserFactory xpathFactory = null;
32
33     private YangParserFactory delegate = null;
34
35     @Activate
36     void activate() {
37         delegate = new YangParserFactoryImpl(xpathFactory);
38         LOG.info("YANG Parser activated");
39     }
40
41     @Deactivate
42     void deactivate() {
43         LOG.info("YANG Parser deactivated");
44         delegate = null;
45     }
46
47     @Override
48     public Collection<StatementParserMode> supportedParserModes() {
49         return delegate.supportedParserModes();
50     }
51
52     @Override
53     public YangParser createParser(final StatementParserMode parserMode) {
54         return delegate.createParser(parserMode);
55     }
56 }