*/
package org.opendaylight.yangtools.yang.data.util;
-import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
-import javax.annotation.Nullable;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.Identifiable;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.concepts.AbstractIdentifiable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.AnydataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
-import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
/**
* Schema derived data providing necessary information for mapping between
*
* @param <T> Path Argument type
*/
-public abstract class DataSchemaContextNode<T extends PathArgument> implements Identifiable<T> {
+public abstract class DataSchemaContextNode<T extends PathArgument> extends AbstractIdentifiable<T> {
private final DataSchemaNode dataSchemaNode;
- private final T identifier;
protected DataSchemaContextNode(final T identifier, final SchemaNode schema) {
- this.identifier = identifier;
+ super(identifier);
if (schema instanceof DataSchemaNode) {
this.dataSchemaNode = (DataSchemaNode) schema;
} else {
}
}
- @Override
- public T getIdentifier() {
- return identifier;
- }
-
public boolean isMixin() {
return false;
}
public abstract boolean isLeaf();
protected Set<QName> getQNameIdentifiers() {
- return ImmutableSet.of(identifier.getNodeType());
+ return ImmutableSet.of(getIdentifier().getNodeType());
}
/**
* @param child Child path argument
* @return A child node, or null if not found
*/
- @Nullable public abstract DataSchemaContextNode<?> getChild(PathArgument child);
+ public abstract @Nullable DataSchemaContextNode<?> getChild(PathArgument child);
- @Nullable public abstract DataSchemaContextNode<?> getChild(QName child);
+ public abstract @Nullable DataSchemaContextNode<?> getChild(QName child);
- @Nullable public DataSchemaNode getDataSchemaNode() {
+ public @Nullable DataSchemaNode getDataSchemaNode() {
return dataSchemaNode;
}
}
static DataSchemaNode findChildSchemaNode(final DataNodeContainer parent, final QName child) {
- DataSchemaNode potential = parent.getDataChildByName(child);
- if (potential == null) {
- Iterable<ChoiceSchemaNode> choices = FluentIterable.from(
- parent.getChildNodes()).filter(ChoiceSchemaNode.class);
- potential = findChoice(choices, child);
- }
- return potential;
+ final DataSchemaNode potential = parent.getDataChildByName(child);
+ return potential == null ? findChoice(Iterables.filter(parent.getChildNodes(), ChoiceSchemaNode.class), child)
+ : potential;
}
static DataSchemaContextNode<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) {
- DataSchemaNode result = findChildSchemaNode(schema, child);
+ final DataSchemaNode result = findChildSchemaNode(schema, child);
// We try to look up if this node was added by augmentation
if (result != null && schema instanceof DataSchemaNode && result.isAugmenting()) {
return fromAugmentation(schema, (AugmentationTarget) schema, result);
private static ChoiceSchemaNode findChoice(final Iterable<ChoiceSchemaNode> choices, final QName child) {
for (ChoiceSchemaNode choice : choices) {
// FIXME: this looks weird: what are we looking for again?
- for (CaseSchemaNode caze : choice.getCases().values()) {
+ for (CaseSchemaNode caze : choice.getCases()) {
if (findChildSchemaNode(caze, child) != null) {
return choice;
}
.collect(Collectors.toSet()));
}
- /**
- * Returns an AugmentationSchemaNode as effective in a parent node.
- *
- * @param schema Augmentation schema
- * @param parent Parent schema
- * @return Adjusted Augmentation schema
- * @throws NullPointerException if any of the arguments is null
- * @deprecated Use {@link EffectiveAugmentationSchema#create(AugmentationSchemaNode, DataNodeContainer)} instead.
- */
- @Deprecated
- public static AugmentationSchemaNode augmentationProxy(final AugmentationSchemaNode schema,
- final DataNodeContainer parent) {
- return EffectiveAugmentationSchema.create(schema, parent);
- }
-
/**
* Returns a DataContextNodeOperation for provided child node
*
* DataContextNodeOperation for child as call for
* {@link #fromDataSchemaNode(DataSchemaNode)}.
*/
- @Nullable static DataSchemaContextNode<?> fromAugmentation(final DataNodeContainer parent,
+ static @Nullable DataSchemaContextNode<?> fromAugmentation(final DataNodeContainer parent,
final AugmentationTarget parentAug, final DataSchemaNode child) {
- AugmentationSchemaNode augmentation = null;
for (AugmentationSchemaNode aug : parentAug.getAvailableAugmentations()) {
- DataSchemaNode potential = aug.getDataChildByName(child.getQName());
- if (potential != null) {
- augmentation = aug;
- break;
+ if (aug.findDataChildByName(child.getQName()).isPresent()) {
+ return new AugmentationContextNode(aug, parent);
}
}
- if (augmentation != null) {
- return new AugmentationContextNode(augmentation, parent);
- }
return fromDataSchemaNode(child);
}
- @Nullable public static DataSchemaContextNode<?> fromDataSchemaNode(final DataSchemaNode potential) {
+ public static @Nullable DataSchemaContextNode<?> fromDataSchemaNode(final DataSchemaNode potential) {
if (potential instanceof ContainerSchemaNode) {
return new ContainerContextNode((ContainerSchemaNode) potential);
} else if (potential instanceof ListSchemaNode) {
return new ChoiceNodeContextNode((ChoiceSchemaNode) potential);
} else if (potential instanceof LeafListSchemaNode) {
return fromLeafListSchemaNode((LeafListSchemaNode) potential);
- } else if (potential instanceof AnyXmlSchemaNode) {
- return new AnyXmlContextNode((AnyXmlSchemaNode) potential);
+ } else if (potential instanceof AnydataSchemaNode) {
+ return new AnydataContextNode((AnydataSchemaNode) potential);
+ } else if (potential instanceof AnyxmlSchemaNode) {
+ return new AnyXmlContextNode((AnyxmlSchemaNode) potential);
}
return null;
}
return new UnorderedLeafListMixinContextNode(potential);
}
- public static DataSchemaContextNode<?> from(final SchemaContext ctx) {
+ public static DataSchemaContextNode<?> from(final EffectiveModelContext ctx) {
return new ContainerContextNode(ctx);
}
}