use of org.opendaylight.yangtools.yang.common.QName in project controller by opendaylight.
the class ModuleMXBeanEntryBuilder method checkUniqueRuntimeBeanAttributesName.
private static void checkUniqueRuntimeBeanAttributesName(final ModuleMXBeanEntry mxBeanEntry, final Map<String, QName> uniqueGeneratedClassesNames) {
for (RuntimeBeanEntry runtimeBeanEntry : mxBeanEntry.getRuntimeBeans()) {
for (String runtimeAttName : runtimeBeanEntry.getYangPropertiesToTypesMap().keySet()) {
if (mxBeanEntry.getAttributes().keySet().contains(runtimeAttName)) {
QName qName1 = uniqueGeneratedClassesNames.get(runtimeBeanEntry.getJavaNameOfRuntimeMXBean());
QName qName2 = uniqueGeneratedClassesNames.get(mxBeanEntry.getGloballyUniqueName());
throw new NameConflictException(runtimeAttName, qName1, qName2);
}
}
}
}
use of org.opendaylight.yangtools.yang.common.QName in project controller by opendaylight.
the class ModuleMXBeanEntryBuilder method checkUniqueRuntimeBeansGeneratedClasses.
private static void checkUniqueRuntimeBeansGeneratedClasses(final Map<String, QName> uniqueGeneratedClassesNames, final DataSchemaNode when, final Collection<RuntimeBeanEntry> runtimeBeans) {
for (RuntimeBeanEntry runtimeBean : runtimeBeans) {
final String javaNameOfRuntimeMXBean = runtimeBean.getJavaNameOfRuntimeMXBean();
if (uniqueGeneratedClassesNames.containsKey(javaNameOfRuntimeMXBean)) {
QName firstDefinedQName = uniqueGeneratedClassesNames.get(javaNameOfRuntimeMXBean);
throw new NameConflictException(javaNameOfRuntimeMXBean, firstDefinedQName, when.getQName());
}
uniqueGeneratedClassesNames.put(javaNameOfRuntimeMXBean, when.getQName());
}
}
use of org.opendaylight.yangtools.yang.common.QName in project controller by opendaylight.
the class ModuleMXBeanEntryBuilder method processCaseSchemaNode.
private <HAS_CHILDREN_AND_QNAME extends DataNodeContainer & SchemaNode> void processCaseSchemaNode(final Map<String, ModuleMXBeanEntry> result, final Map<String, QName> uniqueGeneratedClassesNames, final String configModulePrefix, final Map<String, IdentitySchemaNode> moduleIdentities, final Map<String, IdentitySchemaNode> unaugmentedModuleIdentities, final AugmentationSchemaNode augmentation, final DataSchemaNode when) {
CaseSchemaNode choiceCaseNode = (CaseSchemaNode) when;
if (!choiceCaseNode.getWhenCondition().isPresent()) {
return;
}
java.util.Optional<RevisionAwareXPath> xPath = choiceCaseNode.getWhenCondition();
checkState(xPath.isPresent(), "Choice node %s does not have a when condition", choiceCaseNode);
Matcher matcher = getWhenConditionMatcher(configModulePrefix, xPath.get());
if (matcher.matches() == false) {
return;
}
String moduleLocalNameFromXPath = matcher.group(1);
IdentitySchemaNode moduleIdentity = moduleIdentities.get(moduleLocalNameFromXPath);
unaugmentedModuleIdentities.remove(moduleLocalNameFromXPath);
checkState(moduleIdentity != null, "Cannot find identity %s matching augmentation %s", moduleLocalNameFromXPath, augmentation);
Map<String, QName> providedServices = findProvidedServices(moduleIdentity, currentModule, qNamesToSIEs, schemaContext);
String javaNamePrefix = TypeProviderWrapper.findJavaNamePrefix(moduleIdentity);
Map<String, AttributeIfc> yangToAttributes = null;
// runtime-data
Collection<RuntimeBeanEntry> runtimeBeans = null;
HAS_CHILDREN_AND_QNAME dataNodeContainer = getDataNodeContainer(choiceCaseNode);
if (EXPECTED_CONFIGURATION_AUGMENTATION_SCHEMA_PATH.equals(augmentation.getTargetPath())) {
LOG.debug("Parsing configuration of {}", moduleLocalNameFromXPath);
yangToAttributes = fillConfiguration(dataNodeContainer, currentModule, typeProviderWrapper, qNamesToSIEs, schemaContext, packageName);
checkUniqueAttributesWithGeneratedClass(uniqueGeneratedClassesNames, when.getQName(), yangToAttributes);
} else if (EXPECTED_STATE_AUGMENTATION_SCHEMA_PATH.equals(augmentation.getTargetPath())) {
LOG.debug("Parsing state of {}", moduleLocalNameFromXPath);
try {
runtimeBeans = fillRuntimeBeans(dataNodeContainer, currentModule, typeProviderWrapper, packageName, moduleLocalNameFromXPath, javaNamePrefix);
} catch (NameConflictException e) {
throw new NameConflictException(e.getConflictingName(), when.getQName(), when.getQName());
}
checkUniqueRuntimeBeansGeneratedClasses(uniqueGeneratedClassesNames, when, runtimeBeans);
Set<RuntimeBeanEntry> runtimeBeanEntryValues = Sets.newHashSet(runtimeBeans);
for (RuntimeBeanEntry entry : runtimeBeanEntryValues) {
checkUniqueAttributesWithGeneratedClass(uniqueGeneratedClassesNames, when.getQName(), entry.getYangPropertiesToTypesMap());
}
} else {
throw new IllegalArgumentException("Cannot parse augmentation " + augmentation);
}
boolean hasDummyContainer = choiceCaseNode.equals(dataNodeContainer) == false;
String nullableDummyContainerName = hasDummyContainer ? dataNodeContainer.getQName().getLocalName() : null;
if (result.containsKey(moduleLocalNameFromXPath)) {
// either fill runtimeBeans or yangToAttributes, merge
ModuleMXBeanEntry moduleMXBeanEntry = result.get(moduleLocalNameFromXPath);
if (yangToAttributes != null && moduleMXBeanEntry.getAttributes() == null) {
moduleMXBeanEntry.setYangToAttributes(yangToAttributes);
} else if (runtimeBeans != null && moduleMXBeanEntry.getRuntimeBeans() == null) {
moduleMXBeanEntry.setRuntimeBeans(runtimeBeans);
}
checkState(Objects.equals(nullableDummyContainerName, moduleMXBeanEntry.getNullableDummyContainerName()), "Mismatch in module " + moduleMXBeanEntry.toString() + " - dummy container must be present/missing in" + " both state and configuration");
} else {
ModuleMXBeanEntry.ModuleMXBeanEntryInitial initial = new ModuleMXBeanEntry.ModuleMXBeanEntryInitialBuilder().setIdSchemaNode(moduleIdentity).setPackageName(packageName).setJavaNamePrefix(javaNamePrefix).setNamespace(currentModule.getNamespace().toString()).setqName(ModuleUtil.getQName(currentModule)).build();
// construct ModuleMXBeanEntry
ModuleMXBeanEntry moduleMXBeanEntry = new ModuleMXBeanEntry(initial, yangToAttributes, providedServices, runtimeBeans);
moduleMXBeanEntry.setYangModuleName(currentModule.getName());
moduleMXBeanEntry.setYangModuleLocalname(moduleLocalNameFromXPath);
moduleMXBeanEntry.setNullableDummyContainerName(nullableDummyContainerName);
result.put(moduleLocalNameFromXPath, moduleMXBeanEntry);
}
}
use of org.opendaylight.yangtools.yang.common.QName 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.common.QName in project controller by opendaylight.
the class RuntimeBeanEntry method extractSubtree.
/**
* Get direct descendants of this subtree, together with attributes defined
* in subtree.
*/
private static AttributesRpcsAndRuntimeBeans extractSubtree(final String packageName, final DataNodeContainer subtree, final TypeProviderWrapper typeProviderWrapper, final Module currentModule, final SchemaContext ctx) {
Multimap<QName, RpcDefinition> identitiesToRpcs = getIdentitiesToRpcs(ctx);
List<AttributeIfc> attributes = Lists.newArrayList();
List<RuntimeBeanEntry> runtimeBeanEntries = new ArrayList<>();
for (DataSchemaNode child : subtree.getChildNodes()) {
// runtime beans
if (child instanceof LeafSchemaNode) {
// just save the attribute
LeafSchemaNode leaf = (LeafSchemaNode) child;
attributes.add(new JavaAttribute(leaf, typeProviderWrapper));
} else if (child instanceof ContainerSchemaNode) {
ContainerSchemaNode container = (ContainerSchemaNode) child;
// this can be either TO or hierarchical RB
TOAttribute toAttribute = TOAttribute.create(container, typeProviderWrapper, packageName);
attributes.add(toAttribute);
} else if (child instanceof ListSchemaNode) {
if (isInnerStateBean(child)) {
ListSchemaNode listSchemaNode = (ListSchemaNode) child;
RuntimeBeanEntry hierarchicalChild = createHierarchical(packageName, listSchemaNode, typeProviderWrapper, currentModule, ctx);
runtimeBeanEntries.add(hierarchicalChild);
} else /* ordinary list attribute */
{
ListAttribute listAttribute = ListAttribute.create((ListSchemaNode) child, typeProviderWrapper, packageName);
attributes.add(listAttribute);
}
} else if (child instanceof LeafListSchemaNode) {
ListAttribute listAttribute = ListAttribute.create((LeafListSchemaNode) child, typeProviderWrapper);
attributes.add(listAttribute);
} else {
throw new IllegalStateException("Unexpected running-data node " + child);
}
}
Set<Rpc> rpcs = new HashSet<>();
SchemaNode subtreeSchemaNode = (SchemaNode) subtree;
for (UnknownSchemaNode unknownSchemaNode : subtreeSchemaNode.getUnknownSchemaNodes()) {
if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME.equals(unknownSchemaNode.getNodeType())) {
String localIdentityName = unknownSchemaNode.getNodeParameter();
QName identityQName = unknownSchemaNode.isAddedByUses() ? findQNameFromGrouping(subtree, ctx, unknownSchemaNode, localIdentityName) : QName.create(currentModule.getNamespace(), currentModule.getRevision(), localIdentityName);
// convert RpcDefinition to Rpc
for (RpcDefinition rpcDefinition : identitiesToRpcs.get(identityQName)) {
String name = TypeProviderWrapper.findJavaParameter(rpcDefinition);
AttributeIfc returnType;
if (rpcDefinition.getOutput() == null || rpcDefinition.getOutput().getChildNodes().isEmpty()) {
returnType = VoidAttribute.getInstance();
} else if (rpcDefinition.getOutput().getChildNodes().size() == 1) {
DataSchemaNode returnDSN = rpcDefinition.getOutput().getChildNodes().iterator().next();
returnType = getReturnTypeAttribute(returnDSN, typeProviderWrapper, packageName);
} else {
throw new IllegalArgumentException("More than one child node in rpc output is not supported. " + "Error occured in " + rpcDefinition);
}
List<JavaAttribute> parameters = new ArrayList<>();
for (DataSchemaNode childNode : sortAttributes(rpcDefinition.getInput().getChildNodes())) {
if (childNode.isAddedByUses() == false) {
// skip
// refined
// context-instance
checkArgument(childNode instanceof LeafSchemaNode, "Unexpected type of rpc input type. " + "Currently only leafs and empty output nodes are supported, got " + childNode);
JavaAttribute javaAttribute = new JavaAttribute((LeafSchemaNode) childNode, typeProviderWrapper);
parameters.add(javaAttribute);
}
}
Rpc newRpc = new Rpc(returnType, name, rpcDefinition.getQName().getLocalName(), parameters);
rpcs.add(newRpc);
}
}
}
return new AttributesRpcsAndRuntimeBeans(runtimeBeanEntries, attributes, rpcs);
}
Aggregations