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(Rfc6020Mapping
30 .add(Rfc6020Mapping.DESCRIPTION, 0, 1)
31 .add(Rfc6020Mapping.REFERENCE, 0, 1)
34 protected RevisionStatementImpl(
35 StmtContext<Date, RevisionStatement, ?> context) {
39 public static class Definition
41 AbstractStatementSupport<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> {
44 super(Rfc6020Mapping.REVISION);
48 public Date parseArgumentValue(StmtContext<?, ?, ?> ctx, String value)
49 throws SourceException {
52 revision = SimpleDateFormatUtil.getRevisionFormat()
54 } catch (ParseException e) {
55 throw new SourceException(String.format("Revision value %s is not in required format yyyy-MM-dd",
56 value), ctx.getStatementSourceReference(), e);
63 public RevisionStatement createDeclared(
64 StmtContext<Date, RevisionStatement, ?> ctx) {
65 return new RevisionStatementImpl(ctx);
69 public EffectiveStatement<Date, RevisionStatement> createEffective(
70 StmtContext<Date, RevisionStatement, EffectiveStatement<Date, RevisionStatement>> ctx) {
71 return new RevisionEffectiveStatementImpl(ctx);
75 public void onFullDefinitionDeclared(StmtContext.Mutable<Date, RevisionStatement,
76 EffectiveStatement<Date, RevisionStatement>> stmt) throws SourceException {
77 super.onFullDefinitionDeclared(stmt);
78 SUBSTATEMENT_VALIDATOR.validate(stmt);
83 public Date getDate() {
89 public DescriptionStatement getDescription() {
90 return firstDeclared(DescriptionStatement.class);
95 public ReferenceStatement getReference() {
96 return firstDeclared(ReferenceStatement.class);