Deprecate DeclaredStatement constructors utilizing StmtContext
[yangtools.git] / yang / odlext-parser-support / src / main / java / org / opendaylight / yangtools / odlext / parser / AnyxmlSchemaLocationStatementSupport.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, 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.odlext.parser;
9
10 import static org.opendaylight.yangtools.odlext.model.api.OpenDaylightExtensionsStatements.ANYXML_SCHEMA_LOCATION;
11
12 import com.google.common.collect.ImmutableList;
13 import org.opendaylight.yangtools.odlext.model.api.AnyxmlSchemaLocationEffectiveStatement;
14 import org.opendaylight.yangtools.odlext.model.api.AnyxmlSchemaLocationStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
18 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.ArgumentUtils;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
24
25 public final class AnyxmlSchemaLocationStatementSupport
26         extends BaseStatementSupport<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
27             AnyxmlSchemaLocationEffectiveStatement> {
28     private static final AnyxmlSchemaLocationStatementSupport INSTANCE =
29             new AnyxmlSchemaLocationStatementSupport(ANYXML_SCHEMA_LOCATION);
30
31     private final SubstatementValidator validator;
32
33     private AnyxmlSchemaLocationStatementSupport(final StatementDefinition definition) {
34         super(definition);
35         validator = SubstatementValidator.builder(definition).build();
36     }
37
38     public static AnyxmlSchemaLocationStatementSupport getInstance() {
39         return INSTANCE;
40     }
41
42     @Override
43     public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
44         return ArgumentUtils.nodeIdentifierFromPath(ctx, value);
45     }
46
47     @Override
48     public void onFullDefinitionDeclared(final Mutable<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
49             AnyxmlSchemaLocationEffectiveStatement> stmt) {
50         super.onFullDefinitionDeclared(stmt);
51         stmt.coerceParentContext().addToNs(AnyxmlSchemaLocationNamespace.class, ANYXML_SCHEMA_LOCATION, stmt);
52     }
53
54     @Override
55     protected SubstatementValidator getSubstatementValidator() {
56         return validator;
57     }
58
59     @Override
60     protected AnyxmlSchemaLocationStatement createDeclared(
61             final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement, ?> ctx,
62             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
63         return new AnyxmlSchemaLocationStatementImpl(ctx.coerceRawStatementArgument(), ctx.coerceStatementArgument(),
64             substatements);
65     }
66
67     @Override
68     protected AnyxmlSchemaLocationStatement createEmptyDeclared(
69             final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement, ?> ctx) {
70         return createDeclared(ctx, ImmutableList.of());
71     }
72
73     @Override
74     protected AnyxmlSchemaLocationEffectiveStatement createEffective(
75             final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
76                 AnyxmlSchemaLocationEffectiveStatement> ctx, final AnyxmlSchemaLocationStatement declared,
77             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
78         return new AnyxmlSchemaLocationEffectiveStatementImpl(declared, substatements, ctx);
79     }
80
81     @Override
82     protected AnyxmlSchemaLocationEffectiveStatement createEmptyEffective(
83             final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
84                 AnyxmlSchemaLocationEffectiveStatement> ctx, final AnyxmlSchemaLocationStatement declared) {
85         return createEffective(ctx, declared, ImmutableList.of());
86     }
87 }