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.data.jaxen;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.base.Function;
13 import com.google.common.collect.ImmutableList;
14 import javax.annotation.Nonnull;
15 import javax.annotation.Nullable;
16 import org.jaxen.Context;
17 import org.jaxen.ContextSupport;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 * Context wrapper around a {@link NormalizedNode} for use with Jaxen. It tracks the parent node for purposes of
23 * traversing upwards the NormalizedNode tree.
25 final class NormalizedNodeContext extends Context implements Function<NormalizedNode<?, ?>, NormalizedNodeContext> {
26 private static final long serialVersionUID = 1L;
27 private final NormalizedNodeContext parent;
28 private final NormalizedNode<?, ?> node;
30 NormalizedNodeContext(@Nonnull final ContextSupport contextSupport, @Nonnull final NormalizedNode<?, ?> node,
31 @Nullable final NormalizedNodeContext parent) {
32 super(contextSupport);
33 this.node = requireNonNull(node);
36 setNodeSet(ImmutableList.of(this));
39 @Nonnull NormalizedNode<?, ?> getNode() {
43 @Nullable NormalizedNodeContext getParent() {
47 @Nonnull YangInstanceIdentifier getPath() {
48 return (parent == null ? YangInstanceIdentifier.EMPTY : parent.getPath()).node(node.getIdentifier());
52 public NormalizedNodeContext apply(final NormalizedNode<?, ?> input) {
53 return new NormalizedNodeContext(getContextSupport(), input, this);