2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.stmt.meta;
10 import com.google.common.collect.ImmutableList;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.common.XMLNamespace;
13 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement;
18 import org.opendaylight.yangtools.yang.model.ri.stmt.DeclaredStatements;
19 import org.opendaylight.yangtools.yang.model.ri.stmt.EffectiveStatements;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
24 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26 public final class NamespaceStatementSupport
27 extends AbstractStatementSupport<XMLNamespace, NamespaceStatement, NamespaceEffectiveStatement> {
28 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
31 private static final NamespaceStatementSupport INSTANCE = new NamespaceStatementSupport();
33 private NamespaceStatementSupport() {
34 super(YangStmtMapping.NAMESPACE, StatementPolicy.reject());
37 public static NamespaceStatementSupport getInstance() {
42 public XMLNamespace parseArgumentValue(final StmtContext<?, ?,?> ctx, final String value) {
44 return XMLNamespace.of(value).intern();
45 } catch (IllegalArgumentException e) {
46 throw new SourceException(ctx, e, "Invalid namespace \"%s\"", value);
51 protected SubstatementValidator getSubstatementValidator() {
52 return SUBSTATEMENT_VALIDATOR;
56 protected NamespaceStatement createDeclared(@NonNull final StmtContext<XMLNamespace, NamespaceStatement, ?> ctx,
57 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
58 return DeclaredStatements.createNamespace(ctx.getArgument(), substatements);
62 protected NamespaceStatement createEmptyDeclared(final StmtContext<XMLNamespace, NamespaceStatement, ?> ctx) {
63 return DeclaredStatements.createNamespace(ctx.getArgument());
67 protected NamespaceEffectiveStatement createEffective(final Current<XMLNamespace, NamespaceStatement> stmt,
68 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
69 return EffectiveStatements.createNamespace(stmt.declared(), substatements);