Use ImmutableList for unknown nodes
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / RevisionStatementImpl.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.parser.stmt.rfc6020.effective.RevisionEffectiveStatementImpl;
11 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
12 import java.text.ParseException;
13 import java.util.Date;
14 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
23 import javax.annotation.Nullable;
24
25 public class RevisionStatementImpl extends AbstractDeclaredStatement<Date>
26         implements RevisionStatement {
27
28     protected RevisionStatementImpl(
29             StmtContext<Date, RevisionStatement, ?> context) {
30         super(context);
31     }
32
33     public static class Definition
34             extends
35             AbstractStatementSupport<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> {
36
37         public Definition() {
38             super(Rfc6020Mapping.REVISION);
39         }
40
41         @Override
42         public Date parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
43                 throws SourceException {
44             Date revision;
45             try {
46                 revision = SimpleDateFormatUtil.getRevisionFormat()
47                         .parse(value);
48             } catch (ParseException e) {
49                 throw new SourceException(String.format("Revision value %s is not in required format yyyy-MM-dd",
50                         value), ctx.getStatementSourceReference(), e);
51             }
52
53             return revision;
54         }
55
56         @Override
57         public RevisionStatement createDeclared(
58                 StmtContext<Date, RevisionStatement, ?> ctx) {
59             return new RevisionStatementImpl(ctx);
60         }
61
62         @Override
63         public EffectiveStatement<Date, RevisionStatement> createEffective(
64                 StmtContext<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> ctx) {
65             return new RevisionEffectiveStatementImpl(ctx);
66         }
67     }
68
69     @Override
70     public Date getDate() {
71         return argument();
72     }
73
74     @Nullable
75     @Override
76     public DescriptionStatement getDescription() {
77         return firstDeclared(DescriptionStatement.class);
78     }
79
80     @Nullable
81     @Override
82     public ReferenceStatement getReference() {
83         return firstDeclared(ReferenceStatement.class);
84     }
85 }