mountPoint, schemaContext), moduleContainerBuilder.build());
}
-
@Override
- public StructuredData getAvailableStreams(final UriInfo uriInfo) {
- final Set<String> availableStreams = Notificator.getStreamNames();
-
- final List<Node<?>> streamsAsData = new ArrayList<Node<?>>();
- final Module restconfModule = getRestconfModule();
- final DataSchemaNode streamSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule,
- Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE);
- for (final String streamName : availableStreams) {
- streamsAsData.add(toStreamCompositeNode(streamName, streamSchemaNode));
- }
-
- final DataSchemaNode streamsSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule,
- Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
- final QName qName = streamsSchemaNode.getQName();
- final CompositeNode streamsNode = NodeFactory.createImmutableCompositeNode(qName, null, streamsAsData);
- return new StructuredData(streamsNode, streamsSchemaNode, null, parsePrettyPrintParameter(uriInfo));
- }
-
- @Override
- public StructuredData getModule(final String identifier, final UriInfo uriInfo) {
+ public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
+ Preconditions.checkNotNull(identifier);
final QName moduleNameAndRevision = getModuleNameAndRevision(identifier);
Module module = null;
DOMMountPoint mountPoint = null;
+ final SchemaContext schemaContext;
if (identifier.contains(ControllerContext.MOUNT)) {
final InstanceIdentifierContext mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier);
mountPoint = mountPointIdentifier.getMountPoint();
module = controllerContext.findModuleByNameAndRevision(mountPoint, moduleNameAndRevision);
+ schemaContext = mountPoint.getSchemaContext();
} else {
module = controllerContext.findModuleByNameAndRevision(moduleNameAndRevision);
+ schemaContext = controllerContext.getGlobalSchema();
}
if (module == null) {
- throw new RestconfDocumentedException("Module with name '" + moduleNameAndRevision.getLocalName()
- + "' and revision '" + moduleNameAndRevision.getRevision() + "' was not found.",
- ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
+ final String errMsg = "Module with name '" + moduleNameAndRevision.getLocalName()
+ + "' and revision '" + moduleNameAndRevision.getRevision() + "' was not found.";
+ throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT);
}
final Module restconfModule = getRestconfModule();
- final DataSchemaNode moduleSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule,
- Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
- final CompositeNode moduleNode = toModuleCompositeNode(module, moduleSchemaNode);
- return new StructuredData(moduleNode, moduleSchemaNode, mountPoint, parsePrettyPrintParameter(uriInfo));
+ final Set<Module> modules = Collections.singleton(module);
+ final MapNode moduleMap = makeModuleMapNode(modules);
+
+ final DataSchemaNode moduleSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(
+ restconfModule, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
+ Preconditions.checkState(moduleSchemaNode instanceof ListSchemaNode);
+
+ return new NormalizedNodeContext(new InstanceIdentifierContext(null, moduleSchemaNode, mountPoint,
+ schemaContext), moduleMap);
+ }
+
+ @Override
+ public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
+ final SchemaContext schemaContext = controllerContext.getGlobalSchema();
+ final Set<String> availableStreams = Notificator.getStreamNames();
+ final Module restconfModule = getRestconfModule();
+ final DataSchemaNode streamSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule,
+ Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE);
+ Preconditions.checkState(streamSchemaNode instanceof ListSchemaNode);
+
+ final CollectionNodeBuilder<MapEntryNode, MapNode> listStreamsBuilder = Builders
+ .mapBuilder((ListSchemaNode) streamSchemaNode);
+
+ for (final String streamName : availableStreams) {
+ listStreamsBuilder.withChild(toStreamEntryNode(streamName, streamSchemaNode));
+ }
+
+ final DataSchemaNode streamsContainerSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(
+ restconfModule, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+ Preconditions.checkState(streamsContainerSchemaNode instanceof ContainerSchemaNode);
+
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> streamsContainerBuilder =
+ Builders.containerBuilder((ContainerSchemaNode) streamsContainerSchemaNode);
+ streamsContainerBuilder.withChild(listStreamsBuilder.build());
+
+
+ return new NormalizedNodeContext(new InstanceIdentifierContext(null, streamsContainerSchemaNode, null,
+ schemaContext), streamsContainerBuilder.build());
}
@Override
Preconditions.checkArgument(moduleSchemaNode instanceof ListSchemaNode,
"moduleSchemaNode has to be of type ListSchemaNode");\r final ListSchemaNode listModuleSchemaNode = (ListSchemaNode) moduleSchemaNode;\r final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> moduleNodeValues = Builders\r .mapEntryBuilder(listModuleSchemaNode);\r\r List<DataSchemaNode> instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(\r (listModuleSchemaNode), "name");\r final DataSchemaNode nameSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);\r Preconditions.checkState(nameSchemaNode instanceof LeafSchemaNode);\r moduleNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) nameSchemaNode).withValue(module.getName())\r .build());\r\r instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(\r (listModuleSchemaNode), "revision");\r final DataSchemaNode revisionSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);\r Preconditions.checkState(revisionSchemaNode instanceof LeafSchemaNode);\r final String revision = REVISION_FORMAT.format(module.getRevision());\r moduleNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) revisionSchemaNode).withValue(revision)\r .build());\r\r instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(\r (listModuleSchemaNode), "namespace");\r final DataSchemaNode namespaceSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);\r Preconditions.checkState(namespaceSchemaNode instanceof LeafSchemaNode);\r moduleNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) namespaceSchemaNode)\r .withValue(module.getNamespace().toString()).build());\r\r instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(\r (listModuleSchemaNode), "feature");\r final DataSchemaNode featureSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);\r Preconditions.checkState(featureSchemaNode instanceof LeafListSchemaNode);\r final ListNodeBuilder<Object, LeafSetEntryNode<Object>> featuresBuilder = Builders\r .leafSetBuilder((LeafListSchemaNode) featureSchemaNode);\r for (final FeatureDefinition feature : module.getFeatures()) {\r featuresBuilder.withChild(Builders.leafSetEntryBuilder(((LeafListSchemaNode) featureSchemaNode))\r .withValue(feature.getQName().getLocalName()).build());\r }\r moduleNodeValues.withChild(featuresBuilder.build());
\r return moduleNodeValues.build();\r }
+
+ protected MapEntryNode toStreamEntryNode(final String streamName, final DataSchemaNode streamSchemaNode) {
+ Preconditions.checkArgument(streamSchemaNode instanceof ListSchemaNode,
+ "streamSchemaNode has to be of type ListSchemaNode");
+ final ListSchemaNode listStreamSchemaNode = (ListSchemaNode) streamSchemaNode;
+ final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> streamNodeValues = Builders
+ .mapEntryBuilder(listStreamSchemaNode);
+
+ List<DataSchemaNode> instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
+ (listStreamSchemaNode), "name");
+ final DataSchemaNode nameSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
+ Preconditions.checkState(nameSchemaNode instanceof LeafSchemaNode);
+ streamNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) nameSchemaNode).withValue(streamName)
+ .build());
+
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
+ (listStreamSchemaNode), "description");
+ final DataSchemaNode descriptionSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
+ Preconditions.checkState(descriptionSchemaNode instanceof LeafSchemaNode);
+ streamNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) nameSchemaNode)
+ .withValue("DESCRIPTION_PLACEHOLDER").build());
+
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
+ (listStreamSchemaNode), "replay-support");
+ final DataSchemaNode replaySupportSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
+ Preconditions.checkState(replaySupportSchemaNode instanceof LeafSchemaNode);
+ streamNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) replaySupportSchemaNode)
+ .withValue(Boolean.valueOf(true)).build());
+
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
+ (listStreamSchemaNode), "replay-log-creation-time");
+ final DataSchemaNode replayLogCreationTimeSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
+ Preconditions.checkState(replayLogCreationTimeSchemaNode instanceof LeafSchemaNode);
+ streamNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) replayLogCreationTimeSchemaNode)
+ .withValue("").build());
+
+ instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(
+ (listStreamSchemaNode), "events");
+ final DataSchemaNode eventsSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
+ Preconditions.checkState(eventsSchemaNode instanceof LeafSchemaNode);
+ streamNodeValues.withChild(Builders.leafBuilder((LeafSchemaNode) eventsSchemaNode)
+ .withValue("").build());
+
+ return streamNodeValues.build();
+ }
}