2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
10 import java.text.ParseException;
11 import java.util.Date;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
15 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
20 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
24 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.RevisionEffectiveStatementImpl;
27 public class RevisionStatementImpl extends AbstractDeclaredStatement<Date>
28 implements RevisionStatement {
29 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
30 YangStmtMapping.REVISION)
31 .addOptional(YangStmtMapping.DESCRIPTION)
32 .addOptional(YangStmtMapping.REFERENCE)
35 protected RevisionStatementImpl(final StmtContext<Date, RevisionStatement, ?> context) {
39 public static class Definition
41 AbstractStatementSupport<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> {
44 super(YangStmtMapping.REVISION);
48 public Date parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
50 return SimpleDateFormatUtil.getRevisionFormat().parse(value);
51 } catch (ParseException e) {
52 throw new SourceException(ctx.getStatementSourceReference(), e,
53 "Revision value %s is not in required format yyyy-MM-dd", value);
58 public RevisionStatement createDeclared(final StmtContext<Date, RevisionStatement, ?> ctx) {
59 return new RevisionStatementImpl(ctx);
63 public EffectiveStatement<Date, RevisionStatement> createEffective(
64 final StmtContext<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> ctx) {
65 return new RevisionEffectiveStatementImpl(ctx);
69 public void onFullDefinitionDeclared(
70 final StmtContext.Mutable<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> stmt) {
71 super.onFullDefinitionDeclared(stmt);
72 SUBSTATEMENT_VALIDATOR.validate(stmt);
78 public Date getDate() {
84 public DescriptionStatement getDescription() {
85 return firstDeclared(DescriptionStatement.class);
90 public ReferenceStatement getReference() {
91 return firstDeclared(ReferenceStatement.class);