- // get identities of base config:module-type
- Map<String, IdentitySchemaNode> moduleIdentities = new HashMap<>();
-
- for (IdentitySchemaNode id : currentModule.getIdentities()) {
- if (id.getBaseIdentity() != null
- && ConfigConstants.MODULE_TYPE_Q_NAME.equals(id
- .getBaseIdentity().getQName())) {
- String identityLocalName = id.getQName().getLocalName();
- if (moduleIdentities.containsKey(identityLocalName)) {
- throw new IllegalStateException(
- "Module name already defined in this module: "
- + identityLocalName);
- } else {
- moduleIdentities.put(identityLocalName, id);
- logger.debug("Found identity {}", identityLocalName);
- }
- // validation check on unknown schema nodes
- boolean providedServiceWasSet = false;
- for (UnknownSchemaNode unknownNode : id.getUnknownSchemaNodes()) {
- // TODO: test this
- if (ConfigConstants.PROVIDED_SERVICE_EXTENSION_QNAME
- .equals(unknownNode.getNodeType())) {
- // no op: 0 or more provided identities are allowed
- } else if (ConfigConstants.JAVA_NAME_PREFIX_EXTENSION_QNAME
- .equals(unknownNode.getNodeType())) {
- // 0..1 allowed
- checkState(
- providedServiceWasSet == false,
- format("More than one language extension %s is not allowed here: %s",
- ConfigConstants.JAVA_NAME_PREFIX_EXTENSION_QNAME,
- id));
- providedServiceWasSet = true;
- } else {
- throw new IllegalStateException(
- "Unexpected language extension "
- + unknownNode.getNodeType());
- }
- }
- }
- }
- Map<String, ModuleMXBeanEntry> result = new HashMap<>();
- // each module name should have an augmentation defined
- Map<String, IdentitySchemaNode> unaugmentedModuleIdentities = new HashMap<>(
- moduleIdentities);
- for (AugmentationSchema augmentation : currentModule.getAugmentations()) {
- Set<DataSchemaNode> childNodes = augmentation.getChildNodes();
- if (childNodes.size() == 1) {
- DataSchemaNode when = childNodes.iterator().next();
- if (when instanceof ChoiceCaseNode) {
- ChoiceCaseNode choiceCaseNode = (ChoiceCaseNode) when;
- if (choiceCaseNode.getConstraints() == null
- || choiceCaseNode.getConstraints()
- .getWhenCondition() == null) {
- continue;
- }
- RevisionAwareXPath xPath = choiceCaseNode.getConstraints()
- .getWhenCondition();
- Matcher matcher = getWhenConditionMatcher(
- configModulePrefix, xPath);
- if (matcher.matches() == false) {
- continue;
- }
- String moduleLocalNameFromXPath = matcher.group(1);
- IdentitySchemaNode moduleIdentity = moduleIdentities
- .get(moduleLocalNameFromXPath);
- unaugmentedModuleIdentities
- .remove(moduleLocalNameFromXPath);
- checkState(moduleIdentity != null, "Cannot find identity "
- + moduleLocalNameFromXPath
- + " matching augmentation " + augmentation);
- Map<String, QName> providedServices = findProvidedServices(
- moduleIdentity, currentModule, qNamesToSIEs,
- schemaContext);
-
- if (moduleIdentity == null) {
- throw new IllegalStateException(
- "Cannot find identity specified by augmentation xpath constraint: "
- + moduleLocalNameFromXPath + " of "
- + augmentation);
- }
- String javaNamePrefix = findJavaNamePrefix(moduleIdentity);
-
- Map<String, AttributeIfc> yangToAttributes = null;
- // runtime-data
- Collection<RuntimeBeanEntry> runtimeBeans = null;
-
- if (expectedConfigurationAugmentationSchemaPath
- .equals(augmentation.getTargetPath())) {
- logger.debug("Parsing configuration of {}",
- moduleLocalNameFromXPath);
- yangToAttributes = fillConfiguration(choiceCaseNode,
- currentModule, typeProviderWrapper,
- qNamesToSIEs, schemaContext, packageName);
- checkUniqueAttributesWithGeneratedClass(
- uniqueGeneratedClassesNames, when.getQName(),
- yangToAttributes);
- } else if (expectedStateAugmentationSchemaPath
- .equals(augmentation.getTargetPath())) {
- logger.debug("Parsing state of {}",
- moduleLocalNameFromXPath);
- try {
- runtimeBeans = fillRuntimeBeans(choiceCaseNode,
- 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);
- }
- if (result.containsKey(moduleLocalNameFromXPath)) {
- // either fill runtimeBeans or yangToAttributes
- ModuleMXBeanEntry moduleMXBeanEntry = result
- .get(moduleLocalNameFromXPath);
- if (yangToAttributes != null
- && moduleMXBeanEntry.getAttributes() == null) {
- moduleMXBeanEntry
- .setYangToAttributes(yangToAttributes);
- } else if (runtimeBeans != null
- && moduleMXBeanEntry.getRuntimeBeans() == null) {
- moduleMXBeanEntry.setRuntimeBeans(runtimeBeans);
- }
- } else {
- // construct ModuleMXBeanEntry
- ModuleMXBeanEntry moduleMXBeanEntry = new ModuleMXBeanEntry(
- moduleIdentity, yangToAttributes, packageName,
- providedServices, javaNamePrefix, currentModule
- .getNamespace().toString(),
- runtimeBeans,
- ModuleUtil.getQName(currentModule));
- moduleMXBeanEntry.setYangModuleName(currentModule
- .getName());
- moduleMXBeanEntry
- .setYangModuleLocalname(moduleLocalNameFromXPath);
- result.put(moduleLocalNameFromXPath, moduleMXBeanEntry);
- }
- } // skip if child node is not ChoiceCaseNode
- } // skip if childNodes != 1
- }
- // clean up nulls
- for (Entry<String, ModuleMXBeanEntry> entry : result.entrySet()) {
- ModuleMXBeanEntry module = entry.getValue();
- if (module.getAttributes() == null) {
- module.setYangToAttributes(Collections
- .<String, AttributeIfc> emptyMap());
- } else if (module.getRuntimeBeans() == null) {
- module.setRuntimeBeans(Collections
- .<RuntimeBeanEntry> emptyList());
- }
- }
- // check attributes name uniqueness
- for (Entry<String, ModuleMXBeanEntry> entry : result.entrySet()) {
- checkUniqueRuntimeBeanAttributesName(entry.getValue(),
- uniqueGeneratedClassesNames);
- }
- if (unaugmentedModuleIdentities.size() > 0) {
- logger.warn("Augmentation not found for all module identities: {}",
- unaugmentedModuleIdentities.keySet());
- }