import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
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.EffectiveModelContextListener;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.slf4j.LoggerFactory;
@Singleton
-public final class ControllerContext implements SchemaContextListener, Closeable {
+public final class ControllerContext implements EffectiveModelContextListener, Closeable {
// FIXME: this should be in md-sal somewhere
public static final String MOUNT = "yang-ext:mount";
private final DOMMountPointService mountService;
private final DOMYangTextSourceProvider yangTextSourceProvider;
- private final ListenerRegistration<SchemaContextListener> listenerRegistration;
- private volatile SchemaContext globalSchema;
+ private final ListenerRegistration<?> listenerRegistration;
+ private volatile EffectiveModelContext globalSchema;
private volatile DataNormalizer dataNormalizer;
@Inject
this.mountService = mountService;
this.yangTextSourceProvider = domSchemaService.getExtensions().getInstance(DOMYangTextSourceProvider.class);
- onGlobalContextUpdated(schemaService.getGlobalContext());
+ onModelContextUpdated(schemaService.getGlobalContext());
listenerRegistration = schemaService.registerSchemaContextListener(this);
}
return new ControllerContext(schemaService, mountService, domSchemaService);
}
- private void setGlobalSchema(final SchemaContext globalSchema) {
+ private void setGlobalSchema(final EffectiveModelContext globalSchema) {
this.globalSchema = globalSchema;
this.dataNormalizer = new DataNormalizer(globalSchema);
}
listenerRegistration.close();
}
- public void setSchemas(final SchemaContext schemas) {
- onGlobalContextUpdated(schemas);
+ public void setSchemas(final EffectiveModelContext schemas) {
+ onModelContextUpdated(schemas);
}
public InstanceIdentifierContext<?> toInstanceIdentifier(final String restconfInstance) {
return toIdentifier(restconfInstance, false);
}
- public SchemaContext getGlobalSchema() {
+ public EffectiveModelContext getGlobalSchema() {
return this.globalSchema;
}
}
final InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder();
- final Set<Module> latestModule = this.globalSchema.findModules(startModule);
+ final Collection<? extends Module> latestModule = this.globalSchema.findModules(startModule);
if (latestModule.isEmpty()) {
throw new RestconfDocumentedException("The module named '" + startModule + "' does not exist.",
return module == null ? null : module.getNamespace();
}
- public Set<Module> getAllModules(final DOMMountPoint mountPoint) {
+ public Collection<? extends Module> getAllModules(final DOMMountPoint mountPoint) {
checkPreconditions();
final SchemaContext schemaContext = mountPoint == null ? null : mountPoint.getSchemaContext();
return schemaContext == null ? null : schemaContext.getModules();
}
- public Set<Module> getAllModules() {
+ public Collection<? extends Module> getAllModules() {
checkPreconditions();
return this.globalSchema.getModules();
}
return null;
}
- final Set<GroupingDefinition> groupings = restconfModule.getGroupings();
+ final Collection<? extends GroupingDefinition> groupings = restconfModule.getGroupings();
- final Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings,
+ final Iterable<? extends GroupingDefinition> filteredGroups = Iterables.filter(groupings,
g -> RestConfModule.ERRORS_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()));
final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
return null;
}
- final Set<GroupingDefinition> groupings = restconfModule.getGroupings();
- final Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings,
+ final Collection<? extends GroupingDefinition> groupings = restconfModule.getGroupings();
+ final Iterable<? extends GroupingDefinition> filteredGroups = Iterables.filter(groupings,
g -> RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName()));
final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
}
private static DataSchemaNode childByQName(final ChoiceSchemaNode container, final QName name) {
- for (final CaseSchemaNode caze : container.getCases().values()) {
+ for (final CaseSchemaNode caze : container.getCases()) {
final DataSchemaNode ret = childByQName(caze, name);
if (ret != null) {
return ret;
if (strings.isEmpty()) {
return createContext(builder.build(), (DataSchemaNode) parentNode,
- mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : this.globalSchema);
+ mountPoint,mountPoint != null ? mountPoint.getEffectiveModelContext() : this.globalSchema);
}
final String head = strings.iterator().next();
}
final DOMMountPoint mount = mountOpt.get();
- final SchemaContext mountPointSchema = mount.getSchemaContext();
+ final EffectiveModelContext mountPointSchema = mount.getEffectiveModelContext();
if (mountPointSchema == null) {
throw new RestconfDocumentedException("Mount point does not contain any schema with modules.",
ErrorType.APPLICATION, ErrorTag.UNKNOWN_ELEMENT);
if (returnJustMountPoint || strings.size() == 1) {
final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().build();
- return new InstanceIdentifierContext<>(instance, mountPointSchema, mount,mountPointSchema);
+ return new InstanceIdentifierContext<>(instance, mountPointSchema, mount, mountPointSchema);
}
final String moduleNameBehindMountPoint = toModuleName(strings.get(1));
ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
- final Iterator<Module> it = mountPointSchema.findModules(moduleNameBehindMountPoint).iterator();
+ final Iterator<? extends Module> it = mountPointSchema.findModules(moduleNameBehindMountPoint)
+ .iterator();
if (!it.hasNext()) {
throw new RestconfDocumentedException("\"" + moduleNameBehindMountPoint
+ "\" module does not exist in mount point.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
}
} else {
- final SchemaContext schemaContext = mountPoint.getSchemaContext();
+ final EffectiveModelContext schemaContext = mountPoint.getEffectiveModelContext();
if (schemaContext != null) {
module = schemaContext.findModules(moduleName).stream().findFirst().orElse(null);
} else {
}
if (rpc != null) {
return new InstanceIdentifierContext<>(builder.build(), rpc, mountPoint,
- mountPoint != null ? mountPoint.getSchemaContext() : this.globalSchema);
+ mountPoint != null ? mountPoint.getEffectiveModelContext() : this.globalSchema);
}
}
}
return createContext(builder.build(), targetNode, mountPoint,
- mountPoint != null ? mountPoint.getSchemaContext() : this.globalSchema);
+ mountPoint != null ? mountPoint.getEffectiveModelContext() : this.globalSchema);
}
private static InstanceIdentifierContext<?> createContext(final YangInstanceIdentifier instance,
- final DataSchemaNode dataSchemaNode, final DOMMountPoint mountPoint, final SchemaContext schemaContext) {
+ final DataSchemaNode dataSchemaNode, final DOMMountPoint mountPoint,
+ final EffectiveModelContext schemaContext) {
final YangInstanceIdentifier instanceIdentifier = new DataNormalizer(schemaContext).toNormalized(instance);
return new InstanceIdentifierContext<>(instanceIdentifier, dataSchemaNode, mountPoint, schemaContext);
}
private static void collectInstanceDataNodeContainers(final List<DataSchemaNode> potentialSchemaNodes,
final DataNodeContainer container, final String name) {
- final Iterable<DataSchemaNode> nodes = Iterables.filter(container.getChildNodes(),
+ final Iterable<? extends DataSchemaNode> nodes = Iterables.filter(container.getChildNodes(),
node -> name.equals(node.getQName().getLocalName()));
// Can't combine this loop with the filter above because the filter is
final Iterable<ChoiceSchemaNode> choiceNodes = Iterables.filter(container.getChildNodes(),
ChoiceSchemaNode.class);
- final Iterable<Collection<CaseSchemaNode>> map = Iterables.transform(choiceNodes,
- choice -> choice.getCases().values());
+ final Iterable<Collection<? extends CaseSchemaNode>> map = Iterables.transform(choiceNodes,
+ ChoiceSchemaNode::getCases);
for (final CaseSchemaNode caze : Iterables.concat(map)) {
collectInstanceDataNodeContainers(potentialSchemaNodes, caze, name);
}
checkPreconditions();
final String module = toModuleName(name);
final String node = toNodeName(name);
- final Set<Module> modules = schemaContext.findModules(module);
+ final Collection<? extends Module> modules = schemaContext.findModules(module);
return modules.isEmpty() ? null : QName.create(modules.iterator().next().getQNameModule(), node);
}
}
@Override
- public void onGlobalContextUpdated(final SchemaContext context) {
+ public void onModelContextUpdated(final EffectiveModelContext context) {
if (context != null) {
- final Collection<RpcDefinition> defs = context.getOperations();
+ final Collection<? extends RpcDefinition> defs = context.getOperations();
final Map<QName, RpcDefinition> newMap = new HashMap<>(defs.size());
for (final RpcDefinition operation : defs) {