for (final CaseSchemaNode caze : schema.getCases()) {
final CaseEnforcer enforcer = CaseEnforcer.forTree(caze, treeConfig);
if (enforcer != null) {
- for (final Entry<NodeIdentifier, DataSchemaNode> e : enforcer.getChildEntries()) {
- childBuilder.put(e.getKey(), SchemaAwareApplyOperation.from(e.getValue(), treeConfig));
- enforcerBuilder.put(e.getKey(), enforcer);
+ for (final Entry<NodeIdentifier, DataSchemaNode> entry : enforcer.getChildEntries()) {
+ final ModificationApplyOperation childOper;
+ try {
+ childOper = SchemaAwareApplyOperation.from(entry.getValue(), treeConfig);
+ } catch (ExcludedDataSchemaNodeException e) {
+ // This should never happen as enforcer performs filtering
+ throw new IllegalStateException("Enforcer references out-of-tree child " + entry, e);
+ }
+
+ childBuilder.put(entry.getKey(), childOper);
+ enforcerBuilder.put(entry.getKey(), enforcer);
}
for (final Entry<AugmentationIdentifier, AugmentationSchemaNode> e
: enforcer.getAugmentationEntries()) {
try {
return SchemaAwareApplyOperation.from(child.get(), treeConfig);
- } catch (IllegalArgumentException e) {
+ } catch (ExcludedDataSchemaNodeException e) {
LOG.trace("Failed to instantiate child {} in container schema {} children {}", identifier, this,
schema.getChildNodes(), e);
return null;
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+
+/**
+ * A mouthful of an exception, reported when the requested schema node does exist in the schema tree, but is filtered
+ * from the current data tree. This can occur when a {@code config=false} node is referenced in the operational data
+ * tree.
+ */
+final class ExcludedDataSchemaNodeException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ ExcludedDataSchemaNodeException(final String message) {
+ super(message);
+ }
+}
}
}
- return SchemaAwareApplyOperation.from(rootSchemaNode, treeConfig);
+ try {
+ return SchemaAwareApplyOperation.from(rootSchemaNode, treeConfig);
+ } catch (ExcludedDataSchemaNodeException e) {
+ throw new IllegalArgumentException("Root node does not belong current data tree", e);
+ }
}
@Deprecated
abstract class SchemaAwareApplyOperation<T extends WithStatus> extends ModificationApplyOperation {
private static final Logger LOG = LoggerFactory.getLogger(SchemaAwareApplyOperation.class);
- public static ModificationApplyOperation from(final DataSchemaNode schemaNode,
- final DataTreeConfiguration treeConfig) {
- if (treeConfig.getTreeType() == TreeType.CONFIGURATION) {
- checkArgument(schemaNode.isConfiguration(), "Supplied %s does not belongs to configuration tree.",
- schemaNode);
+ static ModificationApplyOperation from(final DataSchemaNode schemaNode,
+ final DataTreeConfiguration treeConfig) throws ExcludedDataSchemaNodeException {
+ if (!belongsToTree(treeConfig.getTreeType(), schemaNode)) {
+ throw new ExcludedDataSchemaNodeException(schemaNode + " does not belong to configuration tree");
}
if (schemaNode instanceof ContainerSchemaNode) {
return ContainerModificationStrategy.of((ContainerSchemaNode) schemaNode, treeConfig);
return new ValueNodeModificationStrategy<>(AnydataNode.class, (AnydataSchemaNode) schemaNode);
} else if (schemaNode instanceof AnyxmlSchemaNode) {
return new ValueNodeModificationStrategy<>(AnyxmlNode.class, (AnyxmlSchemaNode) schemaNode);
+ } else {
+ throw new IllegalStateException("Unsupported schema " + schemaNode);
}
- throw new IllegalArgumentException("Not supported schema node type for " + schemaNode.getClass());
}
- public static AugmentationModificationStrategy from(final DataNodeContainer resolvedTree,
+ static AugmentationModificationStrategy from(final DataNodeContainer resolvedTree,
final AugmentationTarget augSchemas, final AugmentationIdentifier identifier,
final DataTreeConfiguration treeConfig) {
for (final AugmentationSchemaNode potential : augSchemas.getAvailableAugmentations()) {
private RootApplyStrategy rootOper;
@Before
- public void prepare() {
+ public void prepare() throws ExcludedDataSchemaNodeException {
rootOper = RootApplyStrategy.from(SchemaAwareApplyOperation.from(SCHEMA_CONTEXT,
DataTreeConfiguration.DEFAULT_OPERATIONAL));
}
private RootApplyStrategy rootOper;
@Before
- public void prepare() {
+ public void prepare() throws ExcludedDataSchemaNodeException {
rootOper = RootApplyStrategy.from(SchemaAwareApplyOperation.from(SCHEMA_CONTEXT,
DataTreeConfiguration.DEFAULT_OPERATIONAL));
}