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.Nullable;
13 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
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.SubstatementValidator;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.RevisionEffectiveStatementImpl;
26 public class RevisionStatementImpl extends AbstractDeclaredStatement<Date>
27 implements RevisionStatement {
28 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
29 Rfc6020Mapping.REVISION)
30 .add(Rfc6020Mapping.DESCRIPTION, 0, 1).add(Rfc6020Mapping.REFERENCE, 0, 1).build();
32 protected RevisionStatementImpl(final StmtContext<Date, RevisionStatement, ?> context) {
36 public static class Definition
38 AbstractStatementSupport<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> {
41 super(Rfc6020Mapping.REVISION);
45 public Date parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
47 return SimpleDateFormatUtil.getRevisionFormat().parse(value);
48 } catch (ParseException e) {
49 throw new SourceException(ctx.getStatementSourceReference(), e,
50 "Revision value %s is not in required format yyyy-MM-dd", value);
55 public RevisionStatement createDeclared(final StmtContext<Date, RevisionStatement, ?> ctx) {
56 return new RevisionStatementImpl(ctx);
60 public EffectiveStatement<Date, RevisionStatement> createEffective(
61 final StmtContext<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> ctx) {
62 return new RevisionEffectiveStatementImpl(ctx);
66 public void onFullDefinitionDeclared(
67 final StmtContext.Mutable<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> stmt) {
68 super.onFullDefinitionDeclared(stmt);
69 SUBSTATEMENT_VALIDATOR.validate(stmt);
74 public Date getDate() {
80 public DescriptionStatement getDescription() {
81 return firstDeclared(DescriptionStatement.class);
86 public ReferenceStatement getReference() {
87 return firstDeclared(ReferenceStatement.class);