BUG-4688: switch revisions from Date to Revision
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / RevisionDateStatementImpl.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.common.Revision;
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.RevisionDateStatement;
14 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.RevisionDateEffectiveStatementImpl;
20
21 public class RevisionDateStatementImpl extends AbstractDeclaredStatement<Revision> implements RevisionDateStatement {
22     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
23             SubstatementValidator.builder(YangStmtMapping.REVISION_DATE).build();
24
25     protected RevisionDateStatementImpl(final StmtContext<Revision, RevisionDateStatement, ?> context) {
26         super(context);
27     }
28
29     public static class Definition extends AbstractStatementSupport<Revision, RevisionDateStatement,
30             EffectiveStatement<Revision, RevisionDateStatement>> {
31
32         public Definition() {
33             super(YangStmtMapping.REVISION_DATE);
34         }
35
36         @Override
37         public Revision parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
38             try {
39                 return Revision.valueOf(value);
40             } catch (IllegalArgumentException e) {
41                 throw new SourceException(ctx.getStatementSourceReference(), e,
42                     "Revision value %s is not in required format yyyy-MM-dd", value);
43             }
44         }
45
46         @Override
47         public RevisionDateStatement createDeclared(final StmtContext<Revision, RevisionDateStatement, ?> ctx) {
48             return new RevisionDateStatementImpl(ctx);
49         }
50
51         @Override
52         public EffectiveStatement<Revision, RevisionDateStatement> createEffective(final StmtContext<Revision,
53                 RevisionDateStatement, EffectiveStatement<Revision, RevisionDateStatement>> ctx) {
54             return new RevisionDateEffectiveStatementImpl(ctx);
55         }
56
57         @Override
58         protected SubstatementValidator getSubstatementValidator() {
59             return SUBSTATEMENT_VALIDATOR;
60         }
61     }
62
63     @Override
64     public Revision getDate() {
65         return argument();
66     }
67 }