YANGTOOLS-706: split out rfc8040-model-api
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / anyxmlschema / AnyxmlSchemaLocationSupport.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.yang.parser.stmt.anyxmlschema;
9
10 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
11 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
12 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
13 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
16 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.SupportedExtensionsMapping;
17 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
18
19 public final class AnyxmlSchemaLocationSupport
20         extends AbstractStatementSupport<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
21             EffectiveStatement<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement>> {
22     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
23         SupportedExtensionsMapping.ANYXML_SCHEMA_LOCATION).build();
24     private static final AnyxmlSchemaLocationSupport INSTANCE = new AnyxmlSchemaLocationSupport();
25
26     private AnyxmlSchemaLocationSupport() {
27         super(SupportedExtensionsMapping.ANYXML_SCHEMA_LOCATION);
28     }
29
30     public static AnyxmlSchemaLocationSupport getInstance() {
31         return INSTANCE;
32     }
33
34     @Override
35     public SchemaNodeIdentifier parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
36         return Utils.nodeIdentifierFromPath(ctx, value);
37     }
38
39     @Override
40     public void onFullDefinitionDeclared(final Mutable<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
41             EffectiveStatement<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement>> stmt) {
42         super.onFullDefinitionDeclared(stmt);
43         stmt.getParentContext().addToNs(AnyxmlSchemaLocationNamespace.class,
44                 SupportedExtensionsMapping.ANYXML_SCHEMA_LOCATION, stmt);
45     }
46
47     @Override
48     public AnyxmlSchemaLocationStatement createDeclared(
49             final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement, ?> ctx) {
50         return new AnyxmlSchemaLocationStatementImpl(ctx);
51     }
52
53     @Override
54     public EffectiveStatement<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement> createEffective(
55             final StmtContext<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement,
56             EffectiveStatement<SchemaNodeIdentifier, AnyxmlSchemaLocationStatement>> ctx) {
57         return new AnyxmlSchemaLocationEffectiveStatementImpl(ctx);
58     }
59
60     @Override
61     protected SubstatementValidator getSubstatementValidator() {
62         return SUBSTATEMENT_VALIDATOR;
63     }
64 }