Bug 2366 - new parser API - implementation of declared statements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / RefineStatementImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  * <p/>
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 org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
11 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
12 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
13 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.RefineStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
20
21 import javax.annotation.Nullable;
22
23 public class RefineStatementImpl extends AbstractDeclaredStatement<SchemaNodeIdentifier> implements RefineStatement {
24
25     protected RefineStatementImpl(
26             StmtContext<SchemaNodeIdentifier, RefineStatement, ?> context) {
27         super(context);
28     }
29
30     public static class Definition extends
31             AbstractStatementSupport<SchemaNodeIdentifier, RefineStatement, EffectiveStatement<SchemaNodeIdentifier, RefineStatement>> {
32
33         public Definition() {
34             super(Rfc6020Mapping.REFINE);
35         }
36
37         @Override
38         public SchemaNodeIdentifier parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
39             return SchemaNodeIdentifier.create(Utils.parseXPath(ctx, value), Utils.isXPathAbsolute(value));
40         }
41
42         @Override
43         public RefineStatement createDeclared(StmtContext<SchemaNodeIdentifier, RefineStatement, ?> ctx) {
44             return new RefineStatementImpl(ctx);
45         }
46
47         @Override
48         public EffectiveStatement<SchemaNodeIdentifier, RefineStatement> createEffective(StmtContext<SchemaNodeIdentifier, RefineStatement, EffectiveStatement<SchemaNodeIdentifier, RefineStatement>> ctx) {
49             throw new UnsupportedOperationException();
50         }
51     }
52
53     @Override
54     public String getTargetNode() {
55         return rawArgument();
56     }
57
58     @Nullable
59     @Override
60     public DescriptionStatement getDescription() {
61         return firstDeclared(DescriptionStatement.class);
62     }
63
64     @Nullable
65     @Override
66     public ReferenceStatement getReference() {
67         return firstDeclared(ReferenceStatement.class);
68     }
69 }