use of org.opendaylight.yangtools.yang.model.api.Module in project controller by opendaylight.
the class ModuleMXBeanEntryBuilder method findSIE.
private static ServiceInterfaceEntry findSIE(final String prefixAndIdentityLocalName, final Module currentModule, final Map<QName, ServiceInterfaceEntry> qNamesToSIEs, final SchemaContext schemaContext) {
Matcher m = PREFIX_COLON_LOCAL_NAME.matcher(prefixAndIdentityLocalName);
Module foundModule;
String localSIName;
if (m.matches()) {
// if there is a prefix, look for ModuleImport with this prefix. Get
// Module from SchemaContext
String prefix = m.group(1);
ModuleImport moduleImport = findModuleImport(currentModule, prefix);
foundModule = schemaContext.findModule(moduleImport.getModuleName(), moduleImport.getRevision()).orElse(null);
checkNotNull(foundModule, format("Module not found in SchemaContext by %s", moduleImport));
localSIName = m.group(2);
} else {
// no prefix => SIE is in currentModule
foundModule = currentModule;
localSIName = prefixAndIdentityLocalName;
}
QName siQName = QName.create(foundModule.getNamespace(), foundModule.getRevision(), localSIName);
ServiceInterfaceEntry sie = qNamesToSIEs.get(siQName);
checkState(sie != null, "Cannot find referenced Service Interface by " + prefixAndIdentityLocalName);
return sie;
}
use of org.opendaylight.yangtools.yang.model.api.Module in project controller by opendaylight.
the class RuntimeBeanEntry method getIdentitiesToRpcs.
private static Multimap<QName, /* of identity */
RpcDefinition> getIdentitiesToRpcs(final SchemaContext schemaCtx) {
Multimap<QName, RpcDefinition> result = HashMultimap.create();
for (Module currentModule : schemaCtx.getModules()) {
// Find all identities in current module for later identity->rpc mapping
Set<QName> allIdentitiesInModule = Sets.newHashSet(Collections2.transform(currentModule.getIdentities(), SchemaNode::getQName));
for (RpcDefinition rpc : currentModule.getRpcs()) {
ContainerSchemaNode input = rpc.getInput();
if (input != null) {
for (UsesNode uses : input.getUses()) {
// Check if the rpc is config rpc by looking for input argument rpc-context-ref
Iterator<QName> pathFromRoot = uses.getGroupingPath().getPathFromRoot().iterator();
if (!pathFromRoot.hasNext() || !pathFromRoot.next().equals(ConfigConstants.RPC_CONTEXT_REF_GROUPING_QNAME)) {
continue;
}
for (SchemaNode refinedNode : uses.getRefines().values()) {
for (UnknownSchemaNode unknownSchemaNode : refinedNode.getUnknownSchemaNodes()) {
if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME.equals(unknownSchemaNode.getNodeType())) {
String localIdentityName = unknownSchemaNode.getNodeParameter();
QName identityQName = QName.create(currentModule.getNamespace(), currentModule.getRevision(), localIdentityName);
Preconditions.checkArgument(allIdentitiesInModule.contains(identityQName), "Identity referenced by rpc not found. Identity: %s, rpc: %s", localIdentityName, rpc);
result.put(identityQName, rpc);
}
}
}
}
}
}
}
return result;
}
use of org.opendaylight.yangtools.yang.model.api.Module in project controller by opendaylight.
the class YangModelSearchUtils method mapModulesByNames.
public static Map<String, Module> mapModulesByNames(Collection<Module> modules) {
Map<String, Module> result = new HashMap<>();
for (Module m : modules) {
String moduleName = m.getName();
Preconditions.checkArgument(result.containsKey(moduleName) == false, "Two modules have same name " + moduleName);
result.put(moduleName, m);
}
return result;
}
use of org.opendaylight.yangtools.yang.model.api.Module in project controller by opendaylight.
the class PackageTranslatorTest method test.
@Test
public void test() throws Exception {
Map<String, String> map = Maps.newHashMap();
map.put(ConfigConstants.CONFIG_NAMESPACE, EXPECTED_PACKAGE_PREFIX);
PackageTranslator tested = new PackageTranslator(map);
Module module = mock(Module.class);
doReturn(new URI(ConfigConstants.CONFIG_NAMESPACE + ":threads:api")).when(module).getNamespace();
assertEquals(EXPECTED_PACKAGE_PREFIX + ".threads.api", tested.getPackageName(module));
}
use of org.opendaylight.yangtools.yang.model.api.Module in project controller by opendaylight.
the class DataStoreAppConfigDefaultXMLReader method createDefaultInstance.
@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;
}
Aggregations