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 SchemaPath path;
35 private String description;
36 private String reference;
37 private Status status = Status.CURRENT;
38 private Integer value;
39 private final QName maybeQNameArgument;
41 public EnumEffectiveStatementImpl(final StmtContext<String, EnumStatement, ?> ctx) {
44 SchemaPath parentPath = ctx.getParentContext().getSchemaPath().get();
45 QNameModule moduleQName = parentPath.getLastComponent().getModule();
46 QName maybeQNameArgumentInit = null;
48 maybeQNameArgumentInit = QName.create(moduleQName, argument());
49 } catch (IllegalArgumentException e) {
50 String localName = Utils.replaceIllegalCharsForQName(argument());
51 LOG.warn("{}. Enum argument '{}' has been replaced by '{}'.", e.getMessage(), argument(), localName, e);
52 maybeQNameArgumentInit = QName.create(moduleQName, localName);
54 this.maybeQNameArgument = maybeQNameArgumentInit;
55 this.path = parentPath.createChild(this.maybeQNameArgument);
57 for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
58 if (effectiveStatement instanceof DescriptionEffectiveStatementImpl) {
59 description = ((DescriptionEffectiveStatementImpl) effectiveStatement).argument();
61 if (effectiveStatement instanceof ReferenceEffectiveStatementImpl) {
62 reference = ((ReferenceEffectiveStatementImpl) effectiveStatement).argument();
64 if (effectiveStatement instanceof StatusEffectiveStatementImpl) {
65 status = ((StatusEffectiveStatementImpl) effectiveStatement).argument();
67 if (effectiveStatement instanceof ValueEffectiveStatementImpl) {
68 value = ((ValueEffectiveStatementImpl) effectiveStatement).argument();
74 public String getName() {
79 public Integer getValue() {
84 public QName getQName() {
85 return maybeQNameArgument;
89 public SchemaPath getPath() {
94 public List<UnknownSchemaNode> getUnknownSchemaNodes() {
95 return Collections.emptyList();
99 public String getDescription() {
104 public String getReference() {
109 public Status getStatus() {