Bug 2366 - Effective statments impl merge, retest & bugfix
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / PositionStatementImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
9
10 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.PositionEffectiveStatementImpl;
11
12 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.stmt.PositionStatement;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18
19 public class PositionStatementImpl extends AbstractDeclaredStatement<Long>
20         implements PositionStatement {
21
22     protected PositionStatementImpl(
23             StmtContext<Long, PositionStatement, ?> context) {
24         super(context);
25     }
26
27     public static class Definition
28             extends
29             AbstractStatementSupport<Long, PositionStatement, EffectiveStatement<Long, PositionStatement>> {
30
31         public Definition() {
32             super(Rfc6020Mapping.POSITION);
33         }
34
35         @Override
36         public Long parseArgumentValue(StmtContext<?, ?, ?> ctx, String value) {
37             try {
38                 return Long.parseLong(value);
39             } catch (NumberFormatException e) {
40                 throw new IllegalArgumentException(String.format("Position value %s is not valid integer", value), e);
41             }
42         }
43
44         @Override
45         public PositionStatement createDeclared(
46                 StmtContext<Long, PositionStatement, ?> ctx) {
47             return new PositionStatementImpl(ctx);
48         }
49
50         @Override
51         public EffectiveStatement<Long, PositionStatement> createEffective(
52                 StmtContext<Long, PositionStatement, EffectiveStatement<Long, PositionStatement>> ctx) {
53             return new PositionEffectiveStatementImpl(ctx);
54         }
55
56     }
57
58     @Override
59     public Long getValue() {
60         return argument();
61     }
62
63 }