package org.opendaylight.yangtools.yang.data.impl.schema.tree;
import com.google.common.base.Preconditions;
+import org.kohsuke.MetaInfServices;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration.Builder;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeFactory;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
/**
* A factory for creating in-memory data trees.
*/
+@MetaInfServices
public final class InMemoryDataTreeFactory implements DataTreeFactory {
- private static final InMemoryDataTreeFactory INSTANCE = new InMemoryDataTreeFactory();
private static final NormalizedNode<?, ?> ROOT_CONTAINER = ImmutableNodes.containerNode(SchemaContext.NAME);
- private InMemoryDataTreeFactory() {
- // Never instantiated externally
- }
-
- @Deprecated
- @Override
- public TipProducingDataTree create(final TreeType treeType) {
- return create(DataTreeConfiguration.getDefault(treeType));
- }
-
- @Deprecated
- @Override
- public TipProducingDataTree create(final TreeType treeType, final YangInstanceIdentifier rootPath) {
- if (rootPath.isEmpty()) {
- return create(treeType);
- }
-
- final DataTreeConfiguration defConfig = DataTreeConfiguration.getDefault(treeType);
- final DataTreeConfiguration config;
- if (!rootPath.isEmpty()) {
- config = new Builder(treeType).setMandatoryNodesValidation(defConfig.isMandatoryNodesValidationEnabled())
- .setRootPath(rootPath).setUniqueIndexes(defConfig.isUniqueIndexEnabled()).build();
- } else {
- config = defConfig;
- }
-
- return new InMemoryDataTree(TreeNodeFactory.createTreeNode(createRoot(rootPath), Version.initial()), config,
- null);
- }
-
@Override
- public TipProducingDataTree create(final DataTreeConfiguration treeConfig) {
+ public DataTree create(final DataTreeConfiguration treeConfig) {
return new InMemoryDataTree(TreeNodeFactory.createTreeNode(createRoot(treeConfig.getRootPath()),
Version.initial()), treeConfig, null);
}
initialSchemaContext, rootSchemaNode, maskMandatory);
}
+ private static DataSchemaNode getRootSchemaNode(final SchemaContext schemaContext,
+ final YangInstanceIdentifier rootPath) {
+ final DataSchemaContextTree contextTree = DataSchemaContextTree.from(schemaContext);
+ final DataSchemaContextNode<?> rootContextNode = contextTree.getChild(rootPath);
+ Preconditions.checkArgument(rootContextNode != null, "Failed to find root %s in schema context", rootPath);
+
+ final DataSchemaNode rootSchemaNode = rootContextNode.getDataSchemaNode();
+ Preconditions.checkArgument(rootSchemaNode instanceof DataNodeContainer,
+ "Root %s resolves to non-container type %s", rootPath, rootSchemaNode);
+ return rootSchemaNode;
+ }
+
private static NormalizedNode<?, ?> createRoot(final DataNodeContainer schemaNode,
final YangInstanceIdentifier path) {
if (path.isEmpty()) {
}
}
- private static DataSchemaNode getRootSchemaNode(final SchemaContext schemaContext,
- final YangInstanceIdentifier rootPath) {
- final DataSchemaContextTree contextTree = DataSchemaContextTree.from(schemaContext);
- final DataSchemaContextNode<?> rootContextNode = contextTree.getChild(rootPath);
- Preconditions.checkArgument(rootContextNode != null, "Failed to find root %s in schema context", rootPath);
-
- final DataSchemaNode rootSchemaNode = rootContextNode.getDataSchemaNode();
- Preconditions.checkArgument(rootSchemaNode instanceof DataNodeContainer,
- "Root %s resolves to non-container type %s", rootPath, rootSchemaNode);
- return rootSchemaNode;
- }
-
private static NormalizedNode<?, ?> createRoot(final YangInstanceIdentifier path) {
if (path.isEmpty()) {
return ROOT_CONTAINER;
// FIXME: implement augmentations and leaf-lists
throw new IllegalArgumentException("Unsupported root node " + arg);
}
-
- /**
- * Get an instance of this factory. This method cannot fail.
- *
- * @return Data tree factory instance.
- */
- public static InMemoryDataTreeFactory getInstance() {
- return INSTANCE;
- }
}