@Override public boolean apply(final BindingRuntimeContext input) { return input.getSchemaContext().findModuleByNamespaceAndRevision(namespace, revision) != null; } });
public Module findModuleByNamespace(final URI namespace) { checkPreconditions(); Preconditions.checkArgument(namespace != null); return globalSchema.findModuleByNamespaceAndRevision(namespace, null); }
@Override protected String prefixForNamespace(final URI namespace) { final Module module = context.findModuleByNamespaceAndRevision(namespace, null); return module == null ? null : module.getName(); }
public Module findModuleByNamespace(final DOMMountPoint mountPoint, final URI namespace) { Preconditions.checkArgument(namespace != null && mountPoint != null); final SchemaContext mountPointSchema = mountPoint.getSchemaContext(); if (mountPointSchema == null) { return null; } return mountPointSchema.findModuleByNamespaceAndRevision(namespace, null); }
@Override public Module findModuleByNamespaceAndRevision(final URI uri, final Date date) { return getCurrentSchema().findModuleByNamespaceAndRevision(uri, date); }
private Optional<Module> getModule(final URI namespaceURI) { return Optional.fromNullable(schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(namespaceURI, null)); }
private Optional<Module> getModule(final URI namespaceURI) { return Optional.fromNullable(schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(namespaceURI, null)); }
private Module getParentModule(final SchemaNode node) { QName qname = node.getPath().getPathFromRoot().iterator().next(); URI namespace = qname.getNamespace(); Date revision = qname.getRevision(); return schemaContext.findModuleByNamespaceAndRevision(namespace, revision); }
public static CharSequence toRestconfIdentifier(final QName qname, final SchemaContext schemaContext) { URI namespace = qname.getNamespace(); String module = uriToModuleName.get(namespace); if (module == null) { Date revision = qname.getRevision(); final Module moduleSchema = schemaContext.findModuleByNamespaceAndRevision(namespace, revision); if (moduleSchema == null) { return null; } String name = moduleSchema.getName(); uriToModuleName.put(namespace, name); module = name; } return module + ':' + qname.getLocalName(); }
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; }
private Module getModuleBlocking(final Class<?> modeledClass) { final QNameModule moduleName = BindingReflections.getQNameModule(modeledClass); final URI namespace = moduleName.getNamespace(); final Date revision = moduleName.getRevision(); Module module = runtimeContext().getSchemaContext().findModuleByNamespaceAndRevision(namespace, revision); if(module == null && futureSchema.waitForSchema(namespace,revision)) { module = runtimeContext().getSchemaContext().findModuleByNamespaceAndRevision(namespace, revision); } Preconditions.checkState(module != null, "Schema for %s is not available.", modeledClass); return module; }
public static Entry<String, DataSchemaNode> toRestconfIdentifier(final YangInstanceIdentifier xmlInstanceIdentifier, final SchemaContext schemaContext) { final Iterable<YangInstanceIdentifier.PathArgument> elements = xmlInstanceIdentifier.getPathArguments(); final StringBuilder ret = new StringBuilder(); final QName startQName = elements.iterator().next().getNodeType(); URI namespace = startQName.getNamespace(); Date revision = startQName.getRevision(); final Module initialModule = schemaContext.findModuleByNamespaceAndRevision(namespace, revision); DataNodeContainer node = (initialModule); DataSchemaNode schemaNode = null; for (final YangInstanceIdentifier.PathArgument element : elements) { final DataSchemaNode potentialNode = node.getDataChildByName(element.getNodeType()); if (!isListOrContainer(potentialNode)) { return null; } node = ((DataNodeContainer) potentialNode); schemaNode = potentialNode; ret.append(convertToRestconfIdentifier(element, node, schemaContext)); } return new SimpleEntry<>(ret.toString(), schemaNode); }
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); }
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; }
private void retrievedSchemaContext(SchemaContext schemaContext) { LOG.debug("{}: retrievedSchemaContext", logName()); QNameModule moduleName = BindingReflections.getQNameModule(rpcInterface); Module module = schemaContext.findModuleByNamespaceAndRevision(moduleName.getNamespace(), moduleName.getRevision()); LOG.debug("{}: Got Module: {}", logName(), module); rpcSchemaPaths = new HashSet<>(); for(RpcDefinition rpcDef : module.getRpcs()) { rpcSchemaPaths.add(rpcDef.getPath()); } LOG.debug("{}: Got SchemaPaths: {}", logName(), rpcSchemaPaths); // First get the DOMRpcService OSGi service. This will be used to register a listener to be notified // when the underlying DOM RPC service is available. retrieveService("DOMRpcService", DOMRpcService.class, service -> retrievedDOMRpcService((DOMRpcService)service)); }
private static synchronized String resolveFullNameFromNode(final SchemaNode node, final SchemaContext schemaContext) { final URI namespace = node.getQName().getNamespace(); final Date revision = node.getQName().getRevision(); Map<Date, Module> revisionToModule = namespaceAndRevisionToModule.get(namespace); if (revisionToModule == null) { revisionToModule = new HashMap<>(); namespaceAndRevisionToModule.put(namespace, revisionToModule); } Module module = revisionToModule.get(revision); if (module == null) { module = schemaContext.findModuleByNamespaceAndRevision(namespace, revision); revisionToModule.put(revision, module); } if (module != null) { return module.getName() + ":" + node.getQName().getLocalName(); } return node.getQName().getLocalName(); }
private static final CharSequence toRestconfIdentifier(final SchemaContext context, final QName qname) { final Module schema = context.findModuleByNamespaceAndRevision(qname.getNamespace(), qname.getRevision()); return schema == null ? null : schema.getName() + ':' + qname.getLocalName(); }
private static RpcDefinition findRpcDefinition(final SchemaContext context, final SchemaPath schemaPath) { if (context != null) { final QName qname = schemaPath.getPathFromRoot().iterator().next(); final Module module = context.findModuleByNamespaceAndRevision(qname.getNamespace(), qname.getRevision()); if (module != null && module.getRpcs() != null) { for (RpcDefinition rpc : module.getRpcs()) { if (qname.equals(rpc.getQName())) { return rpc; } } } } return null; }
public DataNodeContainer getDataNodeContainerFor(final YangInstanceIdentifier path) { checkPreconditions(); final Iterable<PathArgument> elements = path.getPathArguments(); final PathArgument head = elements.iterator().next(); final QName startQName = head.getNodeType(); final Module initialModule = globalSchema.findModuleByNamespaceAndRevision(startQName.getNamespace(), startQName.getRevision()); DataNodeContainer node = initialModule; for (final PathArgument element : elements) { final QName _nodeType = element.getNodeType(); final DataSchemaNode potentialNode = ControllerContext.childByQName(node, _nodeType); if (potentialNode == null || !ControllerContext.isListOrContainer(potentialNode)) { return null; } node = (DataNodeContainer) potentialNode; } return node; }
/** * Validates filter content against this validator schema context. If the filter is valid, method returns {@link YangInstanceIdentifier} * of node which can be used as root for data selection. * @param filterContent filter content * @return YangInstanceIdentifier * @throws DocumentedException if filter content is not valid */ public YangInstanceIdentifier validate(XmlElement filterContent) throws DocumentedException { try { final URI namespace = new URI(filterContent.getNamespace()); final Module module = schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(namespace, null); final DataSchemaNode schema = getRootDataSchemaNode(module, namespace, filterContent.getName()); final FilterTree filterTree = validateNode(filterContent, schema, new FilterTree(schema.getQName(), Type.OTHER)); return getFilterDataRoot(filterTree, YangInstanceIdentifier.builder()); } catch (DocumentedException e) { throw e; } catch (Exception e) { throw new DocumentedException("Validation failed. Cause: " + e.getMessage(), DocumentedException.ErrorType.application, DocumentedException.ErrorTag.unknown_namespace, DocumentedException.ErrorSeverity.error); } }