static YangInstanceIdentifier getRootInstanceIdentifier(final Class type) { try { return YangInstanceIdentifier.of(QName.class.cast(type.getField("QNAME").get(null))); } catch (IllegalAccessException e) { throw new IllegalStateException("Constant QNAME not accessible for type" + type, e); } catch (NoSuchFieldException e) { throw new IllegalStateException("Class " + type + " does not have QName defined", e); } }
@Nonnull @Override public DataObject getNodeData(@Nonnull YangInstanceIdentifier yangInstanceIdentifier, @Nonnull String resourcePath) { final InputStream resourceStream = this.getClass().getResourceAsStream(resourcePath); checkState(resourceStream != null, "Resource %s not found", resourcePath); final YangInstanceIdentifier nodeParent = getNodeParent(yangInstanceIdentifier).orElse(null); final SchemaNode parentSchema = parentSchema(schemaContext(), serializer(), nodeParent, LOG); // to be able to process containers in root of model if (isRoot(yangInstanceIdentifier)) { // if root ,read as root final ContainerNode data = readJson(schemaContext(), resourceStream, parentSchema); checkState(data.getValue().size() == 1, "Single root expected in %s", resourcePath); //then extracts first child final QName rootNodeType = data.getValue().iterator().next().getNodeType(); final YangInstanceIdentifier realIdentifier = YangInstanceIdentifier.of(rootNodeType); return nodeBinding(serializer(), realIdentifier, data).getValue(); } else { // reads just container final YangInstanceIdentifier.NodeIdentifier nodeIdentifier = containerNodeIdentifier(yangInstanceIdentifier); final ContainerNode data = readContainerEntryJson(schemaContext(), resourceStream, parentSchema, nodeIdentifier); return nodeBinding(serializer(), yangInstanceIdentifier, data.getValue().iterator().next()).getValue(); } }
private static AbstractDOMRpcRoutingTableEntry createRpcEntry(final SchemaContext context, final SchemaPath key, final Map<YangInstanceIdentifier, List<DOMRpcImplementation>> implementations) { final RpcDefinition rpcDef = findRpcDefinition(context, key); if (rpcDef != null) { final ContainerSchemaNode input = rpcDef.getInput(); if (input != null) { for (DataSchemaNode c : input.getChildNodes()) { for (UnknownSchemaNode extension : c.getUnknownSchemaNodes()) { if (CONTEXT_REFERENCE.equals(extension.getNodeType())) { final YangInstanceIdentifier keyId = YangInstanceIdentifier.of(c.getQName()); return new RoutedDOMRpcRoutingTableEntry(rpcDef, keyId, implementations); } } } } return new GlobalDOMRpcRoutingTableEntry(rpcDef, implementations); } else { return new UnknownDOMRpcRoutingTableEntry(key, implementations); } }
private void createEmptyMonitor() { final DOMDataWriteTransaction wTx = this.domDataBroker.newWriteOnlyTransaction(); ensureParentExists(wTx, YangInstanceIdentifier.of(BmpMonitor.QNAME)); wTx.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().node(BmpMonitor.QNAME).node(Monitor.QNAME) .nodeWithKey(Monitor.QNAME, MONITOR_ID_QNAME, this.monitorId.getValue()).build(), ImmutableNodes.mapEntryBuilder(Monitor.QNAME, MONITOR_ID_QNAME, this.monitorId.getValue()) .addChild(ImmutableNodes.leafNode(MONITOR_ID_QNAME, this.monitorId.getValue())) .addChild(ImmutableNodes.mapNodeBuilder(Router.QNAME).build()) .build()); try { wTx.submit().checkedGet(); } catch (final TransactionCommitFailedException e) { LOG.error("Failed to initiate BMP Monitor {}.", this.monitorId.getValue(), e); } }