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 org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
13 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
14 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.RevisionDateEffectiveStatementImpl;
23 public class RevisionDateStatementImpl extends
24 AbstractDeclaredStatement<Date> implements RevisionDateStatement {
25 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
29 protected RevisionDateStatementImpl(
30 StmtContext<Date, RevisionDateStatement, ?> context) {
34 public static class Definition
36 AbstractStatementSupport<Date, RevisionDateStatement, EffectiveStatement<Date, RevisionDateStatement>> {
39 super(Rfc6020Mapping.REVISION_DATE);
43 public Date parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) throws SourceException {
46 revision = SimpleDateFormatUtil.getRevisionFormat()
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);
57 public RevisionDateStatement createDeclared(
58 StmtContext<Date, RevisionDateStatement, ?> ctx) {
59 return new RevisionDateStatementImpl(ctx);
63 public EffectiveStatement<Date, RevisionDateStatement> createEffective(
64 StmtContext<Date, RevisionDateStatement, EffectiveStatement<Date, RevisionDateStatement>> ctx) {
65 return new RevisionDateEffectiveStatementImpl(ctx);
69 public void onFullDefinitionDeclared(StmtContext.Mutable<Date, RevisionDateStatement,
70 EffectiveStatement<Date, RevisionDateStatement>> stmt) throws SourceException {
71 super.onFullDefinitionDeclared(stmt);
72 SUBSTATEMENT_VALIDATOR.validate(stmt);
77 public Date getDate() {