Ask is moving to Stack Overflow and Serverfault.com! Please use the "opendaylight" tag on either of these sites. This site is now in Read-Only mode

molyland's profile - activity

2017-10-03 07:51:43 -0700 answered a question YANG import catch-22???

I've some problem, this is my code :

pom.xml file :

<!-- opendaylight Yangtools -->
<dependency>
    <groupId>org.opendaylight.yangtools</groupId>
    <artifactId>yang-parser-impl</artifactId>
    <version>1.2.0-SNAPSHOT</version>
    <type>jar</type>
</dependency>        
<dependency>
    <groupId>org.opendaylight.yangtools</groupId>
    <artifactId>yang-parser-api</artifactId>
    <version>1.2.0-SNAPSHOT</version>
    <type>jar</type>
</dependency>
<dependency>
    <groupId>org.opendaylight.yangtools</groupId>
    <artifactId>yang-model-api</artifactId>
    <version>1.2.0-SNAPSHOT</version>
    <type>jar</type>
</dependency>

my java YangParser class :

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class YangParser {

    private static final Logger LOGGER = LoggerFactory.getLogger(YangParser.class);

    public YangParser() {    
    }

    public void parseModule(String file) throws IOException, YangSyntaxErrorException {   
        LOGGER.debug("Parse Yang module from file : " + file);

        try {
            File yang_file = new File(file);
            CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();            
            reactor.addSource(YangStatementStreamSource.create(
                YangTextSchemaSource.forFile(yang_file)));

            SchemaContext schemaContext = reactor.buildEffective();            

            Set<Module> modules = schemaContext.getModules();
            for (Module m : modules) {
                LOGGER.debug("Add YANG module : " + m.getName());
                LOGGER.debug("Namespace : " + m.getNamespace().toString());
            }

        }
        catch (ReactorException e) {
            throw new IllegalStateException("Parsing Yang module failed, error : " + e.getMessage());
        }
    }
}

How Can I solve this problem ? Can I configure ignoring import in yang file ? Thanks.