Reformulate StatementContextFactory.createEffective()
[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.EffectiveStmtCtx.Current;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
25
26 public final class AnyxmlSchemaLocationStatementSupport
27         extends BaseStatementSupport<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
28             AnyxmlSchemaLocationEffectiveStatement> {
29     private static final AnyxmlSchemaLocationStatementSupport INSTANCE =
30             new AnyxmlSchemaLocationStatementSupport(ANYXML_SCHEMA_LOCATION);
31
32     private final SubstatementValidator validator;
33
34     private AnyxmlSchemaLocationStatementSupport(final StatementDefinition definition) {
35         super(definition);
36         validator = SubstatementValidator.builder(definition).build();
37     }
38
39     public static AnyxmlSchemaLocationStatementSupport getInstance() {
40         return INSTANCE;
41     }
42
43     @Override
44     public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
45         return ArgumentUtils.nodeIdentifierFromPath(ctx, value);
46     }
47
48     @Override
49     public void onFullDefinitionDeclared(final Mutable<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
50             AnyxmlSchemaLocationEffectiveStatement> stmt) {
51         super.onFullDefinitionDeclared(stmt);
52         stmt.coerceParentContext().addToNs(AnyxmlSchemaLocationNamespace.class, ANYXML_SCHEMA_LOCATION, stmt);
53     }
54
55     @Override
56     protected SubstatementValidator getSubstatementValidator() {
57         return validator;
58     }
59
60     @Override
61     protected AnyxmlSchemaLocationStatement createDeclared(
62             final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement, ?> ctx,
63             final ImmutableList<? extends DeclaredStatement<?>> substatements) {
64         return new AnyxmlSchemaLocationStatementImpl(ctx.coerceRawStatementArgument(), ctx.coerceStatementArgument(),
65             substatements);
66     }
67
68     @Override
69     protected AnyxmlSchemaLocationStatement createEmptyDeclared(
70             final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement, ?> ctx) {
71         return createDeclared(ctx, ImmutableList.of());
72     }
73
74     @Override
75     protected AnyxmlSchemaLocationEffectiveStatement createEffective(
76             final Current<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement> stmt,
77             final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
78         return new AnyxmlSchemaLocationEffectiveStatementImpl(stmt, substatements);
79     }
80 }