2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.rfc7950.repo;
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.Futures;
12 import java.io.IOException;
13 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
14 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
15 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
16 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
17 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
18 import org.opendaylight.yangtools.yang.model.repo.util.SchemaSourceTransformer;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * A {@link SchemaSourceTransformer} which handles translation of models from
24 * {@link YangTextSchemaSource} representation into {@link ASTSchemaSource}.
27 public final class TextToASTTransformer extends SchemaSourceTransformer<YangTextSchemaSource, ASTSchemaSource> {
28 private static final Logger LOG = LoggerFactory.getLogger(TextToASTTransformer.class);
30 private TextToASTTransformer(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
31 super(provider, YangTextSchemaSource.class, consumer, ASTSchemaSource.class,
32 input -> Futures.immediateFuture(transformText(input)));
35 public static TextToASTTransformer create(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
36 return new TextToASTTransformer(provider, consumer);
39 public static ASTSchemaSource transformText(final YangTextSchemaSource text) throws SchemaSourceException,
40 IOException, YangSyntaxErrorException {
41 final YangStatementStreamSource src = YangStatementStreamSource.create(text);
42 LOG.debug("Model {} parsed successfully", text);
44 // TODO: missing validation (YangModelBasicValidationListener should be re-implemented to new parser)
46 return ASTSchemaSource.create(text.getIdentifier(), text.getSymbolicName().orElse(null),
47 src.statementContext());