-/**
+/*
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
package org.opendaylight.yangtools.yang.data.impl.leafref;
import com.google.common.collect.ImmutableMap;
-import java.io.IOException;
import java.util.Map;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.AbstractEffectiveModelContextProvider;
-final public class LeafRefContext {
+public final class LeafRefContext extends AbstractEffectiveModelContextProvider {
private final QName currentNodeQName;
private final SchemaPath currentNodePath;
- private final SchemaContext schemaContext;
private final Module module;
private final LeafRefPath leafRefTargetPath;
- private final LeafRefPath absoluteLeafRefTargetPath ;
+ private final LeafRefPath absoluteLeafRefTargetPath;
private final String leafRefTargetPathString;
private final boolean isReferencedBy;
private final boolean isReferencing;
- private final Map<QName, LeafRefContext> referencingChilds;
- private final Map<QName, LeafRefContext> referencedByChilds;
- private final Map<QName, LeafRefContext> referencedByLeafRefCtx;
+ private final ImmutableMap<QName, LeafRefContext> referencingChilds;
+ private final ImmutableMap<QName, LeafRefContext> referencedByChilds;
+ private final ImmutableMap<QName, LeafRefContext> referencedByLeafRefCtx;
+
+ // FIXME: this looks like it's related to absoluteLeafRefTargetPath, but the original use in LeafRefValidation
+ // fast path did not make it clear. Analyze the relationship between this field and
+ // absoluteLeafRefTargetPath.
+ private volatile LeafRefPath leafRefNodePath = null;
LeafRefContext(final LeafRefContextBuilder leafRefContextBuilder) {
+ super(leafRefContextBuilder.getSchemaContext());
this.currentNodeQName = leafRefContextBuilder.getCurrentNodeQName();
this.currentNodePath = leafRefContextBuilder.getCurrentNodePath();
- this.schemaContext = leafRefContextBuilder.getSchemaContext();
this.leafRefTargetPath = leafRefContextBuilder.getLeafRefTargetPath();
- this.absoluteLeafRefTargetPath = leafRefContextBuilder
- .getAbsoluteLeafRefTargetPath();
- this.leafRefTargetPathString = leafRefContextBuilder
- .getLeafRefTargetPathString();
+ this.absoluteLeafRefTargetPath = leafRefContextBuilder.getAbsoluteLeafRefTargetPath();
+ this.leafRefTargetPathString = leafRefContextBuilder.getLeafRefTargetPathString();
this.isReferencedBy = leafRefContextBuilder.isReferencedBy();
this.isReferencing = leafRefContextBuilder.isReferencing();
this.referencingChilds = ImmutableMap.copyOf(leafRefContextBuilder.getReferencingChilds());
this.referencedByChilds = ImmutableMap.copyOf(leafRefContextBuilder.getReferencedByChilds());
- this.referencedByLeafRefCtx = ImmutableMap.copyOf(leafRefContextBuilder
- .getAllReferencedByLeafRefCtxs());
+ this.referencedByLeafRefCtx = ImmutableMap.copyOf(leafRefContextBuilder.getAllReferencedByLeafRefCtxs());
this.module = leafRefContextBuilder.getLeafRefContextModule();
}
- public static final LeafRefContext create(final SchemaContext ctx) {
+ public static LeafRefContext create(final EffectiveModelContext ctx) {
try {
return new LeafRefContextTreeBuilder(ctx).buildLeafRefContextTree();
- } catch (IOException | LeafRefYangSyntaxErrorException e) {
- throw new RuntimeException(e);
+ } catch (LeafRefYangSyntaxErrorException e) {
+ throw new IllegalArgumentException(e);
}
}
return currentNodeQName;
}
- SchemaContext getSchemaContext() {
- return schemaContext;
- }
-
public LeafRefPath getAbsoluteLeafRefTargetPath() {
return absoluteLeafRefTargetPath;
}
return referencedByLeafRefCtx;
}
+ LeafRefPath getLeafRefNodePath() {
+ LeafRefPath ret = leafRefNodePath;
+ if (ret == null) {
+ synchronized (this) {
+ ret = leafRefNodePath;
+ if (ret == null) {
+ ret = leafRefNodePath = LeafRefUtils.schemaPathToLeafRefPath(currentNodePath, module);
+ }
+ }
+ }
+ return ret;
+ }
}