2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.rfc7950.stmt.revision_date;
10 import com.google.common.collect.ImmutableList;
11 import java.time.format.DateTimeParseException;
12 import org.opendaylight.yangtools.yang.common.Revision;
13 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateStatement;
18 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;
21 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
23 public final class RevisionDateStatementSupport
24 extends BaseStatementSupport<Revision, RevisionDateStatement, RevisionDateEffectiveStatement> {
25 private static final SubstatementValidator SUBSTATEMENT_VALIDATOR =
26 SubstatementValidator.builder(YangStmtMapping.REVISION_DATE).build();
27 private static final RevisionDateStatementSupport INSTANCE = new RevisionDateStatementSupport();
29 private RevisionDateStatementSupport() {
30 super(YangStmtMapping.REVISION_DATE, CopyPolicy.CONTEXT_INDEPENDENT);
33 public static RevisionDateStatementSupport getInstance() {
38 public Revision parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
40 return Revision.of(value);
41 } catch (DateTimeParseException e) {
42 throw new SourceException(ctx.getStatementSourceReference(), e,
43 "Revision value %s is not in required format yyyy-MM-dd", value);
48 protected SubstatementValidator getSubstatementValidator() {
49 return SUBSTATEMENT_VALIDATOR;
53 protected RevisionDateStatement createDeclared(final StmtContext<Revision, RevisionDateStatement, ?> ctx,
54 final ImmutableList<? extends DeclaredStatement<?>> substatements) {
55 return new RegularRevisionDateStatement(ctx, substatements);
59 protected RevisionDateStatement createEmptyDeclared(final StmtContext<Revision, RevisionDateStatement, ?> ctx) {
60 return new EmptyRevisionDateStatement(ctx);
64 protected RevisionDateEffectiveStatement createEffective(
65 final StmtContext<Revision, RevisionDateStatement, RevisionDateEffectiveStatement> ctx,
66 final RevisionDateStatement declared,
67 final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
68 return new RegularRevisionDateEffectiveStatement(declared, substatements);
72 protected RevisionDateEffectiveStatement createEmptyEffective(
73 final StmtContext<Revision, RevisionDateStatement, RevisionDateEffectiveStatement> ctx,
74 final RevisionDateStatement declared) {
75 return new EmptyRevisionDateEffectiveStatement(declared);