private static boolean isEqualNamespaceAndRevision(QName parentQName, QName nodeQName) { if (parentQName == null) { if (nodeQName == null) { return true; } return false; } return parentQName.getNamespace().equals(nodeQName.getNamespace()) && parentQName.getRevision().equals(nodeQName.getRevision()); } }
@Override public @NonNull String toString() { final StringBuilder sb = new StringBuilder(); if (getNamespace() != null) { sb.append(QNAME_LEFT_PARENTHESIS).append(getNamespace()); final Optional<Revision> rev = getRevision(); if (rev.isPresent()) { sb.append(QNAME_REVISION_DELIMITER).append(rev.get()); } sb.append(QNAME_RIGHT_PARENTHESIS); } sb.append(localName); return sb.toString(); }
@Override public @NonNull String toString() { final StringBuilder sb = new StringBuilder(); if (getNamespace() != null) { sb.append(QNAME_LEFT_PARENTHESIS).append(getNamespace()); final Optional<Revision> rev = getRevision(); if (rev.isPresent()) { sb.append(QNAME_REVISION_DELIMITER).append(rev.get()); } sb.append(QNAME_RIGHT_PARENTHESIS); } sb.append(localName); return sb.toString(); }
public static void printConfiguration(final Set<YangModuleInfo> allModelsFromClasspath) { final Set<YangModuleInfo> topLevelModels = YangModuleUtils.filterTopLevelModels(allModelsFromClasspath); LOG.info("# top-level models list: {}", topLevelModels.size()); for (final YangModuleInfo yangModuleInfo : topLevelModels) { final QName qname = yangModuleInfo.getName(); System.out.println("{ \"nameSpace\": \"" + qname.getNamespace() + "\", \"name\": \"" + qname.getLocalName() + "\", \"revision\": \"" + qname.getRevision().orElse(null) + "\" },"); } LOG.info("# top-level models list: {}", topLevelModels.size()); for (final YangModuleInfo yangModuleInfo: topLevelModels) { System.out.println(yangModuleInfo.getClass().getCanonicalName() + ".getInstance(),"); } }
public Module findModuleByNameAndRevision(final QName module) { checkPreconditions(); Preconditions.checkArgument(module != null && module.getLocalName() != null && module.getRevision() != null); return globalSchema.findModuleByName(module.getLocalName(), module.getRevision()); }
public String getLinkForType(final String classname) { final Class<?> loadedClass; final QName qname; try { loadedClass = this.getClass().getClassLoader().loadClass(classname); final Field qnameField = loadedClass.getField("QNAME"); qname = QName.class.cast(qnameField.get(null)); } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException e) { throw new IllegalStateException(format("Unable to extract QNAME from %s", classname), e); } final String namespace = qname.getNamespace().toString(); final String formattedRevision = qname.getRevision().get().toString(); final String model = modelTypeIndex.namespaceToModule(namespace, formattedRevision); return modelLinkIndex.linkForModel(model, formattedRevision); } }
public Module findModuleByNameAndRevision(final DOMMountPoint mountPoint, final QName module) { checkPreconditions(); Preconditions.checkArgument(module != null && module.getLocalName() != null && module.getRevision() != null && mountPoint != null); final SchemaContext schemaContext = mountPoint.getSchemaContext(); return schemaContext == null ? null : schemaContext.findModuleByName(module.getLocalName(), module.getRevision()); }
private static Optional<DataNodeContainer> findFirst(final Set<? extends OperationDefinition> operations, final YangModuleInfo moduleInfo, final Class<? extends TreeNode> targetType) { for (final OperationDefinition operation : operations) { final String operationNamespace = operation.getQName().getNamespace().toString(); final String operationRevision = operation.getQName().getRevision().map(Revision::toString).orElse(null); if (moduleInfo.getNamespace().equals(operationNamespace) && moduleInfo.getRevision().equals(operationRevision)) { final Optional<DataNodeContainer> potential = findInputOutput(operation, targetType.getSimpleName()); if(potential.isPresent()) { return potential; } } } return Optional.empty(); }
YangModelKey(final YangModuleInfo moduleInfo) { this.namespace = moduleInfo.getName().getNamespace().toString(); Optional<Revision> optRevision = moduleInfo.getName().getRevision(); this.revision = optRevision.isPresent() ? optRevision.get().toString() : ""; }
@Override protected void writeQName(final QName qname) throws IOException { writeString(qname.getLocalName()); writeString(qname.getNamespace().toString()); writeString(qname.getRevision().map(Revision::toString).orElse(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 static SourceIdentifier sourceIdentifierFrom(final YangModuleInfo moduleInfo) { final QName name = moduleInfo.getName(); return RevisionSourceIdentifier.create(name.getLocalName(), name.getRevision()); }
private static void printDependencies(final Collection<YangModuleInfo> yangModuleInfos, final int prefixLength) { for (final YangModuleInfo yangModuleInfo : yangModuleInfos) { final QName qname = yangModuleInfo.getName(); LOG.info("{}{} {} {}", Strings.repeat(" ", prefixLength), qname.getNamespace(), qname.getLocalName(), qname.getRevision()); printDependencies(yangModuleInfo.getImportedModules(), prefixLength + PREFIX); } }
public static ModuleId from(final YangModuleInfo yangModuleInfo) { final QName name = yangModuleInfo.getName(); return new ModuleId(name.getNamespace().toString(), name.getLocalName(), name.getRevision().get().toString()); }
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 org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier createBIPath(final String name) { final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder builder = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.builder(); builder.node(Nodes.QNAME).node(Node.QNAME).nodeWithKey(Node.QNAME, QName.create(Node.QNAME.getNamespace(), Node.QNAME.getRevision(), "id"), name); return builder.build(); }
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 static String resolveNodesName(final SchemaNode node, final Module module, final SchemaContext schemaContext) { if (node.getQName().getNamespace().equals(module.getQNameModule().getNamespace()) && node.getQName().getRevision().equals(module.getQNameModule().getRevision())) { return node.getQName().getLocalName(); } else { return resolveFullNameFromNode(node, schemaContext); } }
private static NormalizedNodeMessages.QName.Builder encodeQName(QNameSerializationContext context, QName qName) { if(qName == null) { return NormalizedNodeMessages.QName.getDefaultInstance().toBuilder(); } NormalizedNodeMessages.QName.Builder qNameBuilder = NormalizedNodeMessages.QName.newBuilder(); qNameBuilder.setNamespace(context.addNamespace(qName.getNamespace())); qNameBuilder.setRevision(context.addRevision(qName.getRevision())); qNameBuilder.setLocalName(context.addLocalName(qName.getLocalName())); return qNameBuilder; }