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.rfc7950.stmt.extension;
10 import java.util.Objects;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
15 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
17 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.UnknownEffectiveStatementBase;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
20 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 final class UnrecognizedEffectiveStatementImpl extends UnknownEffectiveStatementBase<String, UnrecognizedStatement>
25 implements UnrecognizedEffectiveStatement {
26 private static final Logger LOG = LoggerFactory.getLogger(UnrecognizedEffectiveStatementImpl.class);
28 private final QName maybeQNameArgument;
29 private final @NonNull SchemaPath path;
31 UnrecognizedEffectiveStatementImpl(final StmtContext<String, UnrecognizedStatement, ?> ctx) {
34 // FIXME: Remove following section after fixing 4380
35 final UnknownSchemaNode original = (UnknownSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective)
37 if (original != null) {
38 this.maybeQNameArgument = original.getQName();
40 QName maybeQNameArgumentInit = null;
42 maybeQNameArgumentInit = StmtContextUtils.qnameFromArgument(ctx, argument());
43 } catch (SourceException e) {
44 LOG.debug("Not constructing QName from {}", argument(), e);
45 maybeQNameArgumentInit = getNodeType();
47 this.maybeQNameArgument = maybeQNameArgumentInit;
52 maybePath = ctx.coerceParentContext().getSchemaPath()
53 .map(parentPath -> parentPath.createChild(maybeQNameArgument)).orElse(null);
54 } catch (IllegalArgumentException | SourceException e) {
55 LOG.debug("Cannot construct path for {}, attempting to recover", ctx, e);
62 public QName getQName() {
63 return maybeQNameArgument;
67 public SchemaPath getPath() {
72 public int hashCode() {
75 result = prime * result + Objects.hashCode(maybeQNameArgument);
76 result = prime * result + Objects.hashCode(path);
77 result = prime * result + Objects.hashCode(getNodeType());
78 result = prime * result + Objects.hashCode(getNodeParameter());
83 public boolean equals(final Object obj) {
87 if (!(obj instanceof UnrecognizedEffectiveStatementImpl)) {
90 UnrecognizedEffectiveStatementImpl other = (UnrecognizedEffectiveStatementImpl) obj;
91 return Objects.equals(maybeQNameArgument, other.maybeQNameArgument) && Objects.equals(path, other.path)
92 && Objects.equals(getNodeType(), other.getNodeType())
93 && Objects.equals(getNodeParameter(), other.getNodeParameter());