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 / WhenStatementImpl.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 org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
11 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
12 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
13 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
16 import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
21
22 import javax.annotation.Nonnull;
23 import javax.annotation.Nullable;
24
25 public class WhenStatementImpl extends AbstractDeclaredStatement<RevisionAwareXPath> implements
26         WhenStatement {
27
28     protected WhenStatementImpl(
29             StmtContext<RevisionAwareXPath, WhenStatement, ?> context) {
30         super(context);
31     }
32
33     public static class Definition extends AbstractStatementSupport<RevisionAwareXPath,WhenStatement,EffectiveStatement<RevisionAwareXPath,WhenStatement>> {
34
35         public Definition() {
36             super(Rfc6020Mapping.WHEN);
37         }
38
39         @Override public RevisionAwareXPath parseArgumentValue(
40                 StmtContext<?, ?, ?> ctx, String value) throws SourceException {
41             return new RevisionAwareXPathImpl(value, false);
42         }
43
44         @Override public WhenStatement createDeclared(
45                 StmtContext<RevisionAwareXPath, WhenStatement, ?> ctx) {
46             return new WhenStatementImpl(ctx);
47         }
48
49         @Override public EffectiveStatement<RevisionAwareXPath, WhenStatement> createEffective(
50                 StmtContext<RevisionAwareXPath, WhenStatement, EffectiveStatement<RevisionAwareXPath, WhenStatement>> ctx) {
51             throw new UnsupportedOperationException();
52         }
53     }
54
55     @Nonnull @Override
56     public RevisionAwareXPath getCondition() {
57         return argument();
58     }
59
60     @Nullable @Override
61     public DescriptionStatement getDescription() {
62         return firstDeclared(DescriptionStatement.class);
63     }
64
65     @Nullable @Override
66     public ReferenceStatement getReference() {
67         return firstDeclared(ReferenceStatement.class);
68     }
69 }