+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies, 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.osgi;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeFactory;
-import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-
-/**
- * YANG data implementation activator. Publishes a {@link DataTreeFactory} implementation on bundle start.
- *
- * @author Robert Varga
- */
-public final class Activator implements BundleActivator {
- private ServiceRegistration<@NonNull DataTreeFactory> registration;
-
- @Override
- public void start(final BundleContext context) throws Exception {
- registration = context.registerService(DataTreeFactory.class, new InMemoryDataTreeFactory(), null);
- }
-
- @Override
- public void stop(final BundleContext context) throws Exception {
- if (registration != null) {
- registration.unregister();
- registration = null;
- }
- }
-}
import java.util.Optional;
import javax.inject.Singleton;
+import org.eclipse.jdt.annotation.NonNull;
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.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* A factory for creating in-memory data trees.
*/
@MetaInfServices
@Singleton
+@Component(immediate = true)
public final class InMemoryDataTreeFactory implements DataTreeFactory {
+ private static final Logger LOG = LoggerFactory.getLogger(InMemoryDataTreeFactory.class);
// FIXME: YANGTOOLS-1074: we do not want this name
- private static final NormalizedNode<?, ?> ROOT_CONTAINER = ImmutableNodes.containerNode(SchemaContext.NAME);
+ private static final @NonNull NormalizedNode<?, ?> ROOT_CONTAINER =
+ ImmutableNodes.containerNode(SchemaContext.NAME);
@Override
public DataTree create(final DataTreeConfiguration treeConfig) {
@Override
public DataTree create(final DataTreeConfiguration treeConfig, final SchemaContext initialSchemaContext) {
- return create(treeConfig, initialSchemaContext, true);
+ return createDataTree(treeConfig, initialSchemaContext, true);
}
@Override
public DataTree create(final DataTreeConfiguration treeConfig, final SchemaContext initialSchemaContext,
final NormalizedNodeContainer<?, ?, ?> initialRoot) throws DataValidationFailedException {
- final DataTree ret = create(treeConfig, initialSchemaContext, false);
+ final DataTree ret = createDataTree(treeConfig, initialSchemaContext, false);
final DataTreeModification mod = ret.takeSnapshot().newModification();
mod.write(YangInstanceIdentifier.empty(), initialRoot);
return ret;
}
- private static DataTree create(final DataTreeConfiguration treeConfig, final SchemaContext initialSchemaContext,
- final boolean maskMandatory) {
+ @Activate
+ @SuppressWarnings("static-method")
+ void activate() {
+ LOG.info("In-memory Data Tree activated");
+ }
+
+ @Deactivate
+ @SuppressWarnings("static-method")
+ void deactivate() {
+ LOG.info("In-memory Data Tree deactivated");
+ }
+
+ private static @NonNull DataTree createDataTree(final DataTreeConfiguration treeConfig,
+ final SchemaContext initialSchemaContext, final boolean maskMandatory) {
final DataSchemaNode rootSchemaNode = getRootSchemaNode(initialSchemaContext, treeConfig.getRootPath());
final NormalizedNode<?, ?> rootDataNode = createRoot((DataNodeContainer)rootSchemaNode,
treeConfig.getRootPath());
initialSchemaContext, rootSchemaNode, maskMandatory);
}
- private static DataSchemaNode getRootSchemaNode(final SchemaContext schemaContext,
- final YangInstanceIdentifier rootPath) {
- final DataSchemaContextTree contextTree = DataSchemaContextTree.from(schemaContext);
- final Optional<DataSchemaContextNode<?>> rootContextNode = contextTree.findChild(rootPath);
- checkArgument(rootContextNode.isPresent(), "Failed to find root %s in schema context", rootPath);
-
- final DataSchemaNode rootSchemaNode = rootContextNode.get().getDataSchemaNode();
- checkArgument(rootSchemaNode instanceof DataNodeContainer, "Root %s resolves to non-container type %s",
- rootPath, rootSchemaNode);
- return rootSchemaNode;
- }
-
- private static NormalizedNode<?, ?> createRoot(final DataNodeContainer schemaNode,
+ private static @NonNull NormalizedNode<?, ?> createRoot(final DataNodeContainer schemaNode,
final YangInstanceIdentifier path) {
if (path.isEmpty()) {
checkArgument(schemaNode instanceof ContainerSchemaNode,
}
}
- private static NormalizedNode<?, ?> createRoot(final YangInstanceIdentifier path) {
+ private static @NonNull NormalizedNode<?, ?> createRoot(final YangInstanceIdentifier path) {
if (path.isEmpty()) {
return ROOT_CONTAINER;
}
// FIXME: implement augmentations and leaf-lists
throw new IllegalArgumentException("Unsupported root node " + arg);
}
+
+ private static DataSchemaNode getRootSchemaNode(final SchemaContext schemaContext,
+ final YangInstanceIdentifier rootPath) {
+ final DataSchemaContextTree contextTree = DataSchemaContextTree.from(schemaContext);
+ final Optional<DataSchemaContextNode<?>> rootContextNode = contextTree.findChild(rootPath);
+ checkArgument(rootContextNode.isPresent(), "Failed to find root %s in schema context", rootPath);
+
+ final DataSchemaNode rootSchemaNode = rootContextNode.get().getDataSchemaNode();
+ checkArgument(rootSchemaNode instanceof DataNodeContainer, "Root %s resolves to non-container type %s",
+ rootPath, rootSchemaNode);
+ return rootSchemaNode;
+ }
}