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.effective.type;
10 import java.util.Collections;
11 import java.util.List;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.common.QNameModule;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.model.api.Status;
16 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement;
19 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DescriptionEffectiveStatementImpl;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ReferenceEffectiveStatementImpl;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.StatusEffectiveStatementImpl;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ValueEffectiveStatementImpl;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class EnumEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, EnumStatement> implements EnumPair {
32 private static final Logger LOG = LoggerFactory.getLogger(EnumEffectiveStatementImpl.class);
34 private final String name;
35 private final SchemaPath path;
36 private String description;
37 private String reference;
38 private Status status = Status.CURRENT;
39 private Integer value;
40 private final QName maybeQNameArgument;
42 public EnumEffectiveStatementImpl(final StmtContext<String, EnumStatement, ?> ctx) {
45 name = ctx.rawStatementArgument();
46 SchemaPath parentPath = ctx.getParentContext().getSchemaPath().get();
47 QNameModule moduleQName = parentPath.getLastComponent().getModule();
48 QName maybeQNameArgumentInit = null;
50 maybeQNameArgumentInit = QName.create(moduleQName, argument());
51 } catch (IllegalArgumentException e) {
52 String localName = Utils.replaceIllegalCharsForQName(argument());
53 LOG.warn("{}. Enum argument '{}' has been replaced by '{}'.", e.getMessage(), argument(), localName, e);
54 maybeQNameArgumentInit = QName.create(moduleQName, localName);
56 this.maybeQNameArgument = maybeQNameArgumentInit;
57 this.path = parentPath.createChild(this.maybeQNameArgument);
59 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
60 if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
61 description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
63 if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
64 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
66 if (effectiveStatement instanceof StatusEffectiveStatementImpl) {
67 status = ((StatusEffectiveStatementImpl) effectiveStatement).argument();
69 if (effectiveStatement instanceof ValueEffectiveStatementImpl) {
70 value = ((ValueEffectiveStatementImpl) effectiveStatement).argument();
76 public String getName() {
81 public Integer getValue() {
86 public QName getQName() {
87 return maybeQNameArgument;
91 public SchemaPath getPath() {
96 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
97 return Collections.emptyList();
101 public String getDescription() {
106 public String getReference() {
111 public Status getStatus() {