use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.
the class JsonParserStream method toModuleNames.
private String toModuleNames(final Set<XMLNamespace> potentialUris) {
final StringBuilder builder = new StringBuilder();
for (final XMLNamespace potentialUri : potentialUris) {
builder.append('\n');
// FIXME how to get information about revision from JSON input? currently first available is used.
builder.append(codecs.getEffectiveModelContext().findModules(potentialUri).iterator().next().getName());
}
return builder.toString();
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.
the class JsonParserStream method read.
private void read(final JsonReader in, AbstractNodeDataWithSchema<?> parent) throws IOException {
switch(in.peek()) {
case STRING:
case NUMBER:
setValue(parent, in.nextString());
break;
case BOOLEAN:
setValue(parent, Boolean.toString(in.nextBoolean()));
break;
case NULL:
in.nextNull();
setValue(parent, null);
break;
case BEGIN_ARRAY:
in.beginArray();
while (in.hasNext()) {
if (parent instanceof LeafNodeDataWithSchema) {
read(in, parent);
} else {
final AbstractNodeDataWithSchema<?> newChild = newArrayEntry(parent);
read(in, newChild);
}
}
in.endArray();
return;
case BEGIN_OBJECT:
final Set<String> namesakes = new HashSet<>();
in.beginObject();
/*
* This allows parsing of incorrectly /as showcased/
* in testconf nesting of list items - eg.
* lists with one value are sometimes serialized
* without wrapping array.
*
*/
if (isArray(parent)) {
parent = newArrayEntry(parent);
}
while (in.hasNext()) {
final String jsonElementName = in.nextName();
final DataSchemaNode parentSchema = parent.getSchema();
final Entry<String, XMLNamespace> namespaceAndName = resolveNamespace(jsonElementName, parentSchema);
final String localName = namespaceAndName.getKey();
final XMLNamespace namespace = namespaceAndName.getValue();
if (lenient && (localName == null || namespace == null)) {
LOG.debug("Schema node with name {} was not found under {}", localName, parentSchema.getQName());
in.skipValue();
continue;
}
addNamespace(namespace);
if (!namesakes.add(jsonElementName)) {
throw new JsonSyntaxException("Duplicate name " + jsonElementName + " in JSON input.");
}
final Deque<DataSchemaNode> childDataSchemaNodes = ParserStreamUtils.findSchemaNodeByNameAndNamespace(parentSchema, localName, getCurrentNamespace());
checkState(!childDataSchemaNodes.isEmpty(), "Schema for node with name %s and namespace %s does not exist at %s", localName, getCurrentNamespace(), parentSchema);
final QName qname = childDataSchemaNodes.peekLast().getQName();
final AbstractNodeDataWithSchema<?> newChild = ((CompositeNodeDataWithSchema<?>) parent).addChild(childDataSchemaNodes, ChildReusePolicy.NOOP);
if (newChild instanceof AnyXmlNodeDataWithSchema) {
readAnyXmlValue(in, (AnyXmlNodeDataWithSchema) newChild, jsonElementName);
} else {
stack.enterDataTree(qname);
read(in, newChild);
stack.exit();
}
removeNamespace();
}
in.endObject();
return;
default:
break;
}
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.
the class SchemaContextProxyTest method mockModuleLike.
private static void mockModuleLike(final ModuleLike mockedModule, final String name) {
doReturn(name).when(mockedModule).getName();
doReturn(Optional.of(REVISION)).when(mockedModule).getRevision();
final XMLNamespace newNamespace = XMLNamespace.of(NAMESPACE.toString() + ":" + name);
doReturn(newNamespace).when(mockedModule).getNamespace();
doReturn(QNameModule.create(newNamespace, REVISION)).when(mockedModule).getQNameModule();
doReturn(new HashSet<>()).when(mockedModule).getSubmodules();
doReturn(mockedModule.getQNameModule().toString()).when(mockedModule).toString();
mockModuleImport(mockedModule);
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.
the class SourceSpecificContext method preLinkagePrefixes.
private PrefixToModule preLinkagePrefixes() {
final PrefixToModuleMap preLinkagePrefixes = new PrefixToModuleMap();
final Map<String, XMLNamespace> prefixToNamespaceMap = getAllFromLocalStorage(ImpPrefixToNamespace.class);
if (prefixToNamespaceMap == null) {
// :FIXME if it is a submodule without any import, the map is null. Handle also submodules and includes...
return null;
}
prefixToNamespaceMap.forEach((key, value) -> preLinkagePrefixes.put(key, QNameModule.create(value)));
return preLinkagePrefixes;
}
use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.
the class ModuleStatementSupport method onLinkageDeclared.
@Override
public void onLinkageDeclared(final Mutable<Unqualified, ModuleStatement, ModuleEffectiveStatement> stmt) {
final XMLNamespace moduleNs = SourceException.throwIfNull(firstAttributeOf(stmt.declaredSubstatements(), NamespaceStatement.class), stmt, "Namespace of the module [%s] is missing", stmt.argument());
final Optional<Revision> revisionDate = StmtContextUtils.getLatestRevision(stmt.declaredSubstatements());
final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate.orElse(null)).intern();
final StmtContext<?, ModuleStatement, ModuleEffectiveStatement> possibleDuplicateModule = stmt.getFromNamespace(NamespaceToModule.class, qNameModule);
if (possibleDuplicateModule != null && possibleDuplicateModule != stmt) {
throw new SourceException(stmt, "Module namespace collision: %s. At %s", qNameModule.getNamespace(), possibleDuplicateModule.sourceReference());
}
final String moduleName = stmt.getRawArgument();
final SourceIdentifier moduleIdentifier = RevisionSourceIdentifier.create(moduleName, revisionDate);
stmt.addContext(ModuleNamespace.class, moduleIdentifier, stmt);
stmt.addContext(ModuleNamespaceForBelongsTo.class, moduleIdentifier.getName(), stmt);
stmt.addContext(NamespaceToModule.class, qNameModule, stmt);
final String modulePrefix = SourceException.throwIfNull(firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt, "Prefix of the module [%s] is missing", stmt.argument());
stmt.addToNs(QNameModuleNamespace.class, Empty.value(), qNameModule);
stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule);
stmt.addToNs(ModuleNameToModuleQName.class, moduleName, qNameModule);
stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
stmt.addToNs(ModuleCtxToSourceIdentifier.class, stmt, moduleIdentifier);
stmt.addToNs(ModuleQNameToModuleName.class, qNameModule, moduleName);
stmt.addToNs(ImportPrefixToModuleCtx.class, modulePrefix, stmt);
if (semanticVersioning) {
addToSemVerModuleNamespace(stmt, moduleIdentifier);
}
}
Aggregations