private String findModuleName(final YangInstanceIdentifier id, final SchemaContext context) { PathArgument rootQName = id.getPathArguments().iterator().next(); for (Module mod : context.getModules()) { if (mod.getDataChildByName(rootQName.getNodeType()) != null) { return mod.getName(); } } return null; }
private Optional<DataSchemaNode> getSchemaNodeFromNamespace(final String namespace, final XmlElement element) throws NetconfDocumentedException{ Optional<DataSchemaNode> dataSchemaNode = Optional.absent(); try { //returns module with newest revision since findModuleByNamespace returns a set of modules and we only need the newest one final Module module = schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(new URI(namespace), null); if (module == null) { // no module is present with this namespace throw new NetconfDocumentedException("Unable to find module by namespace: " + namespace, ErrorType.application, ErrorTag.unknown_namespace, ErrorSeverity.error); } DataSchemaNode schemaNode = module.getDataChildByName(element.getName()); if (schemaNode != null) { dataSchemaNode = Optional.of(module.getDataChildByName(element.getName())); } else { throw new NetconfDocumentedException("Unable to find node with namespace: " + namespace + "in module: " + module.toString(), ErrorType.application, ErrorTag.unknown_namespace, ErrorSeverity.error); } } catch (URISyntaxException e) { LOG.debug("Unable to create URI for namespace : {}", namespace); } return dataSchemaNode; }
final Iterable<QName> nextPath = nextLevel(path); foundNode = module.getDataChildByName(current); if (foundNode != null && nextPath.iterator().hasNext()) { foundNode = findNodeIn(foundNode, nextPath);
private Optional<DataSchemaNode> getSchemaNodeFromNamespace(final String namespace, final XmlElement element) throws DocumentedException{ Optional<DataSchemaNode> dataSchemaNode = Optional.absent(); try { //returns module with newest revision since findModuleByNamespace returns a set of modules and we only need the newest one final Module module = schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(new URI(namespace), null); if (module == null) { // no module is present with this namespace throw new NetconfDocumentedException("Unable to find module by namespace: " + namespace, ErrorType.application, ErrorTag.unknown_namespace, ErrorSeverity.error); } DataSchemaNode schemaNode = module.getDataChildByName(QName.create(module.getQNameModule(), element.getName())); if (schemaNode != null) { dataSchemaNode = Optional.of(schemaNode); } else { throw new DocumentedException("Unable to find node with namespace: " + namespace + "in module: " + module.toString(), ErrorType.application, ErrorTag.unknown_namespace, ErrorSeverity.error); } } catch (URISyntaxException e) { LOG.debug("Unable to create URI for namespace : {}", namespace); } return dataSchemaNode; }
final Iterable<QName> nextPath = nextLevel(path); foundNode = module.getDataChildByName(current); if (foundNode != null && nextPath.iterator().hasNext()) { foundNode = findNodeIn(foundNode, nextPath);
private DataSchemaNode getSchemaNodeFromNamespace(final XmlElement element) throws NetconfDocumentedException { try { final Module module = schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(new URI(element.getNamespace()), null); DataSchemaNode dataSchemaNode = module.getDataChildByName(element.getName()); if (dataSchemaNode != null) { return dataSchemaNode; } } catch (URISyntaxException e) { LOG.debug("Error during parsing of element namespace, this should not happen since namespace of an xml " + "element is valid and if the xml was parsed then the URI should be as well"); throw new IllegalArgumentException("Unable to parse element namespace, this should not happen since " + "namespace of an xml element is valid and if the xml was parsed then the URI should be as well"); } throw new NetconfDocumentedException("Unable to find node with namespace: " + element.getNamespace() + "in schema context: " + schemaContext.getCurrentContext().toString(), ErrorType.application, ErrorTag.unknown_namespace, ErrorSeverity.error); }
@SuppressWarnings("unchecked") public T createDefaultInstance(final FallbackConfigProvider fallback) throws ConfigXMLReaderException, URISyntaxException, ParserConfigurationException, XMLStreamException, SAXException, IOException { YangInstanceIdentifier yangPath = bindingSerializer.toYangInstanceIdentifier(bindingContext.appConfigPath); LOG.debug("{}: Creating app config instance from path {}, Qname: {}", logName, yangPath, bindingContext.bindingQName); checkNotNull(schemaService, "%s: Could not obtain the SchemaService OSGi service", logName); SchemaContext schemaContext = schemaService.getGlobalContext(); Module module = schemaContext.findModule(bindingContext.bindingQName.getModule()).orElse(null); checkNotNull(module, "%s: Could not obtain the module schema for namespace %s, revision %s", logName, bindingContext.bindingQName.getNamespace(), bindingContext.bindingQName.getRevision()); DataSchemaNode dataSchema = module.getDataChildByName(bindingContext.bindingQName); checkNotNull(dataSchema, "%s: Could not obtain the schema for %s", logName, bindingContext.bindingQName); checkCondition(bindingContext.schemaType.isAssignableFrom(dataSchema.getClass()), "%s: Expected schema type %s for %s but actual type is %s", logName, bindingContext.schemaType, bindingContext.bindingQName, dataSchema.getClass()); NormalizedNode<?, ?> dataNode = parsePossibleDefaultAppConfigXMLFile(schemaContext, dataSchema); if (dataNode == null) { dataNode = fallback.get(schemaService.getGlobalContext(), dataSchema); } DataObject appConfig = bindingSerializer.fromNormalizedNode(yangPath, dataNode).getValue(); // This shouldn't happen but need to handle it in case... checkNotNull(appConfig, "%s: Could not create instance for app config binding %s", logName, bindingContext.appConfigBindingClass); return (T) appConfig; }
DataSchemaNode dataSchema = module.getDataChildByName(bindingContext.bindingQName); if(dataSchema == null) { setFailureMessage(String.format("%s: Could not obtain the schema for %s", logName(), bindingContext.bindingQName));