Refactor AbstractEffectiveModule
[yangtools.git] / yang / yang-parser-rfc7950 / 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     private static final StatusStatementSupport INSTANCE = new StatusStatementSupport();
25
26     private StatusStatementSupport() {
27         super(YangStmtMapping.STATUS);
28     }
29
30     public static StatusStatementSupport getInstance() {
31         return INSTANCE;
32     }
33
34     @Override
35     public Status parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
36         switch (value) {
37             case "current":
38                 return Status.CURRENT;
39             case "deprecated":
40                 return Status.DEPRECATED;
41             case "obsolete":
42                 return Status.OBSOLETE;
43             default:
44                 throw new SourceException(ctx.getStatementSourceReference(),
45                     "Invalid status '%s', must be one of 'current', 'deprecated' or 'obsolete'", value);
46         }
47     }
48
49     @Override
50     public StatusStatement createDeclared(
51             final StmtContext<Status, StatusStatement, ?> ctx) {
52         return new StatusStatementImpl(ctx);
53     }
54
55     @Override
56     public EffectiveStatement<Status, StatusStatement> createEffective(
57             final StmtContext<Status, StatusStatement, EffectiveStatement<Status, StatusStatement>> ctx) {
58         return new StatusEffectiveStatementImpl(ctx);
59     }
60
61     @Override
62     public String internArgument(final String rawArgument) {
63         if ("current".equals(rawArgument)) {
64             return "current";
65         } else if ("deprecated".equals(rawArgument)) {
66             return "deprecated";
67         } else if ("obsolete".equals(rawArgument)) {
68             return "obsolete";
69         } else {
70             return rawArgument;
71         }
72     }
73
74     @Override
75     protected SubstatementValidator getSubstatementValidator() {
76         return SUBSTATEMENT_VALIDATOR;
77     }
78 }