Fix failing unit test in QueuedNotificationManagerTest
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / LengthStatementImpl.java
index faf07270c6c33c3fc12f7655ccc0120d7f8e1fde..a8fc152e543ae28979231b56cdced423a40f6f2e 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
 import java.util.List;
-
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionStatement;
@@ -17,20 +16,27 @@ import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.LengthStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceStatement;
 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LengthEffectiveStatementImpl;
 
 public class LengthStatementImpl extends AbstractDeclaredStatement<List<LengthConstraint>> implements LengthStatement {
+    private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(Rfc6020Mapping
+            .LENGTH)
+            .add(Rfc6020Mapping.DESCRIPTION, 0, 1)
+            .add(Rfc6020Mapping.ERROR_APP_TAG, 0, 1)
+            .add(Rfc6020Mapping.ERROR_MESSAGE, 0, 1)
+            .add(Rfc6020Mapping.REFERENCE, 0, 1)
+            .build();
 
     protected LengthStatementImpl(StmtContext<List<LengthConstraint>, LengthStatement, ?> context) {
         super(context);
     }
 
-    public static class Definition
-            extends
-            AbstractStatementSupport<List<LengthConstraint>, LengthStatement, EffectiveStatement<List<LengthConstraint>, LengthStatement>> {
+    public static class Definition extends AbstractStatementSupport<List<LengthConstraint>, LengthStatement,
+            EffectiveStatement<List<LengthConstraint>, LengthStatement>> {
 
         public Definition() {
             super(Rfc6020Mapping.LENGTH);
@@ -38,7 +44,7 @@ public class LengthStatementImpl extends AbstractDeclaredStatement<List<LengthCo
 
         @Override
         public List<LengthConstraint> parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
-            return TypeUtils.parseLengthListFromString(value);
+            return TypeUtils.parseLengthListFromString(ctx, value);
         }
 
         @Override
@@ -48,9 +54,17 @@ public class LengthStatementImpl extends AbstractDeclaredStatement<List<LengthCo
 
         @Override
         public EffectiveStatement<List<LengthConstraint>, LengthStatement> createEffective(
-                StmtContext<List<LengthConstraint>, LengthStatement, EffectiveStatement<List<LengthConstraint>, LengthStatement>> ctx) {
+                StmtContext<List<LengthConstraint>, LengthStatement, EffectiveStatement<List<LengthConstraint>,
+                        LengthStatement>> ctx) {
             return new LengthEffectiveStatementImpl(ctx);
         }
+
+        @Override
+        public void onFullDefinitionDeclared(StmtContext.Mutable<List<LengthConstraint>,
+                LengthStatement, EffectiveStatement<List<LengthConstraint>, LengthStatement>> stmt) {
+            super.onFullDefinitionDeclared(stmt);
+            SUBSTATEMENT_VALIDATOR.validate(stmt);
+        }
     }
 
     @Override
@@ -77,4 +91,4 @@ public class LengthStatementImpl extends AbstractDeclaredStatement<List<LengthCo
     public List<LengthConstraint> getValue() {
         return argument();
     }
-}
\ No newline at end of file
+}