3cdbc522ab346a84f221a1dc9d5283ce83cf4297
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / status / StatusStatementSupport.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.rfc7950.stmt.status;
9
10 import org.opendaylight.yangtools.yang.model.api.Status;
11 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
12 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
13 import org.opendaylight.yangtools.yang.model.api.stmt.StatusStatement;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
17 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
18
19 public final class StatusStatementSupport
20         extends AbstractStatementSupport<Status, StatusStatement, EffectiveStatement<Status, StatusStatement>> {
21     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(YangStmtMapping
22         .STATUS)
23         .build();
24
25     public StatusStatementSupport() {
26         super(YangStmtMapping.STATUS);
27     }
28
29     @Override
30     public Status parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
31         switch (value) {
32             case "current":
33                 return Status.CURRENT;
34             case "deprecated":
35                 return Status.DEPRECATED;
36             case "obsolete":
37                 return Status.OBSOLETE;
38             default:
39                 throw new SourceException(ctx.getStatementSourceReference(),
40                     "Invalid status '%s', must be one of 'current', 'deprecated' or 'obsolete'", value);
41         }
42     }
43
44     @Override
45     public StatusStatement createDeclared(
46             final StmtContext<Status, StatusStatement, ?> ctx) {
47         return new StatusStatementImpl(ctx);
48     }
49
50     @Override
51     public EffectiveStatement<Status, StatusStatement> createEffective(
52             final StmtContext<Status, StatusStatement, EffectiveStatement<Status, StatusStatement>> ctx) {
53         return new StatusEffectiveStatementImpl(ctx);
54     }
55
56     @Override
57     public String internArgument(final String rawArgument) {
58         if ("current".equals(rawArgument)) {
59             return "current";
60         } else if ("deprecated".equals(rawArgument)) {
61             return "deprecated";
62         } else if ("obsolete".equals(rawArgument)) {
63             return "obsolete";
64         } else {
65             return rawArgument;
66         }
67     }
68
69     @Override
70     protected SubstatementValidator getSubstatementValidator() {
71         return SUBSTATEMENT_VALIDATOR;
72     }
73 }