Bug 6897: Adding getSubstatementValidator() method to AbstractStatementSupport
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / AnyxmlSchemaLocationStatementImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.yang.parser.stmt.rfc6020;
9
10 import com.google.common.annotations.Beta;
11 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
12 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
13 import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement;
14 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
19 import org.opendaylight.yangtools.yang.parser.spi.source.AnyxmlSchemaLocationNamespace;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AnyxmlSchemaLocationEffectiveStatementImpl;
21
22 @Beta
23 public final class AnyxmlSchemaLocationStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements
24         UnknownStatement<SchemaNodeIdentifier> {
25     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
26             SupportedExtensionsMapping.ANYXML_SCHEMA_LOCATION).build();
27
28     AnyxmlSchemaLocationStatementImpl(
29             final StmtContext<SchemaNodeIdentifier, UnknownStatement<SchemaNodeIdentifier>, ?> context) {
30         super(context);
31     }
32
33     public static class AnyxmlSchemaLocationSupport
34             extends
35             AbstractStatementSupport<SchemaNodeIdentifier, UnknownStatement<SchemaNodeIdentifier>, EffectiveStatement<SchemaNodeIdentifier, UnknownStatement<SchemaNodeIdentifier>>> {
36
37         public AnyxmlSchemaLocationSupport() {
38             super(SupportedExtensionsMapping.ANYXML_SCHEMA_LOCATION);
39         }
40
41         @Override
42         public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
43             return Utils.nodeIdentifierFromPath(ctx, value);
44         }
45
46         @Override
47         public void onFullDefinitionDeclared(
48                 final Mutable<SchemaNodeIdentifier, UnknownStatement<SchemaNodeIdentifier>, EffectiveStatement<SchemaNodeIdentifier, UnknownStatement<SchemaNodeIdentifier>>> stmt) {
49             getSubstatementValidator().validate(stmt);
50             stmt.getParentContext().addToNs(AnyxmlSchemaLocationNamespace.class,
51                     SupportedExtensionsMapping.ANYXML_SCHEMA_LOCATION, stmt);
52         }
53
54         @Override
55         public UnknownStatement<SchemaNodeIdentifier> createDeclared(
56                 final StmtContext<SchemaNodeIdentifier, UnknownStatement<SchemaNodeIdentifier>, ?> ctx) {
57             return new AnyxmlSchemaLocationStatementImpl(ctx);
58         }
59
60         @Override
61         public EffectiveStatement<SchemaNodeIdentifier, UnknownStatement<SchemaNodeIdentifier>> createEffective(
62                 final StmtContext<SchemaNodeIdentifier, UnknownStatement<SchemaNodeIdentifier>, EffectiveStatement<SchemaNodeIdentifier, UnknownStatement<SchemaNodeIdentifier>>> ctx) {
63             return new AnyxmlSchemaLocationEffectiveStatementImpl(ctx);
64         }
65
66         @Override
67         protected SubstatementValidator getSubstatementValidator() {
68             return SUBSTATEMENT_VALIDATOR;
69         }
70     }
71
72     @Override
73     public SchemaNodeIdentifier getArgument() {
74         return argument();
75     }
76 }