public ImmutableMap<AugmentationIdentifier,Type> getAvailableAugmentationTypes(final DataNodeContainer container) { final Map<AugmentationIdentifier,Type> identifierToType = new HashMap<>(); if (container instanceof AugmentationTarget) { final Set<AugmentationSchema> augments = ((AugmentationTarget) container).getAvailableAugmentations(); for (final AugmentationSchema augment : augments) { // Augmentation must have child nodes if is to be used with Binding classes AugmentationSchema augOrig = augment; while (augOrig.getOriginalDefinition().isPresent()) { augOrig = augOrig.getOriginalDefinition().get(); } if (!augment.getChildNodes().isEmpty()) { final Type augType = typeToDefiningSchema.inverse().get(augOrig); if (augType != null) { identifierToType.put(getAugmentationIdentifier(augment),augType); } } } } return ImmutableMap.copyOf(identifierToType); }
private static AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) { if (parent instanceof AugmentationTarget && !(parent instanceof ChoiceSchemaNode)) { for (final AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) { final DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName()); if (childInAugmentation != null) { return augmentation; } } } return null; } }
public static QName getAugmentationIdentifier(final AugmentationSchema augmentation) { for(final UnknownSchemaNode extension : augmentation.getUnknownSchemaNodes()) { if(AUGMENT_IDENTIFIER.equals(extension.getNodeType().getLocalName())) { return extension.getQName(); } } return null; }
public static CharSequence writeAugment(final AugmentationSchema augment) { StringConcatenation _builder = new StringConcatenation(); _builder.append("augment "); SchemaPath _targetPath = augment.getTargetPath(); Iterable<QName> _pathFromRoot = _targetPath.getPathFromRoot(); String _formatToAugmentPath = YangTemplate.formatToAugmentPath(_pathFromRoot); RevisionAwareXPath _whenCondition = augment.getWhenCondition(); boolean _notEquals = (!Objects.equal(_whenCondition, null)); if (!_notEquals) { _and = false; } else { RevisionAwareXPath _whenCondition_1 = augment.getWhenCondition(); String _string = _whenCondition_1.toString(); boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(_string); _builder.append(" "); _builder.append("when \""); RevisionAwareXPath _whenCondition_2 = augment.getWhenCondition(); String _string_1 = _whenCondition_2.toString(); _builder.append(_string_1, " "); String _description = augment.getDescription(); boolean _isNullOrEmpty_1 = StringExtensions.isNullOrEmpty(_description); boolean _not_1 = (!_isNullOrEmpty_1); _builder.append(" "); _builder.append("\""); String _description_1 = augment.getDescription(); _builder.append(_description_1, " ");
checkArgument(augmentPackageName != null, "Package Name cannot be NULL."); checkArgument(augSchema != null, "Augmentation Schema cannot be NULL."); checkState(augSchema.getTargetPath() != null, "Augmentation Schema does not contain Target Path (Target Path is NULL)."); final SchemaPath targetPath = augSchema.getTargetPath(); final SchemaNode targetSchemaNode = findOriginalTargetFromGrouping(targetPath, usesNode); if (targetSchemaNode == null) { } else { generateTypesFromAugmentedChoiceCases(module, augmentPackageName, targetTypeBuilder.toInstance(), (ChoiceSchemaNode) targetSchemaNode, augSchema.getChildNodes());
private AugmentationIdentifier getAugmentationIdentifier(final AugmentationSchema augment) { final Set<QName> childNames = new HashSet<>(); for (final DataSchemaNode child : augment.getChildNodes()) { childNames.add(child.getQName()); } return new AugmentationIdentifier(childNames); }
genTypeBuilders.put(augmentPackageName, augmentBuilders); final String augIdentifier = getAugmentIdentifier(augSchema.getUnknownSchemaNodes()); addImplementedInterfaceFromUses(augSchema, augTypeBuilder); augSchemaNodeToMethods(module, basePackageName, augTypeBuilder, augTypeBuilder, augSchema.getChildNodes()); augmentBuilders.put(augTypeName, augTypeBuilder); if(!augSchema.getChildNodes().isEmpty()) { genCtx.get(module).addTargetToAugmentation(targetTypeRef, augTypeBuilder); genCtx.get(module).addTypeToAugmentation(augTypeBuilder, augSchema);
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 {
checkArgument(augmentPackageName != null, "Package Name cannot be NULL."); checkArgument(augSchema != null, "Augmentation Schema cannot be NULL."); checkState(augSchema.getTargetPath() != null, "Augmentation Schema does not contain Target Path (Target Path is NULL)."); final SchemaPath targetPath = augSchema.getTargetPath(); SchemaNode targetSchemaNode = null; (ChoiceSchemaNode) targetSchemaNode, augSchema.getChildNodes());
public Entry<AugmentationIdentifier, AugmentationSchema> getResolvedAugmentationSchema(final DataNodeContainer target, final Class<? extends Augmentation<?>> aug) { final AugmentationSchema origSchema = getAugmentationDefinition(aug); Preconditions.checkArgument(origSchema != null, "Augmentation %s is not known in current schema context",aug); /* * FIXME: Validate augmentation schema lookup * * Currently this algorithm, does not verify if instantiated child nodes * are real one derived from augmentation schema. The problem with * full validation is, if user used copy builders, he may use * augmentation which was generated for different place. * * If this augmentations have same definition, we emit same identifier * with data and it is up to underlying user to validate data. * */ final Set<QName> childNames = new HashSet<>(); final Set<DataSchemaNode> realChilds = new HashSet<>(); for (final DataSchemaNode child : origSchema.getChildNodes()) { realChilds.add(target.getDataChildByName(child.getQName())); childNames.add(child.getQName()); } final AugmentationIdentifier identifier = new AugmentationIdentifier(childNames); final AugmentationSchema proxy = new EffectiveAugmentationSchema(origSchema, realChilds); return new AbstractMap.SimpleEntry<>(identifier, proxy); }
final SchemaPath targetPath = augSchema.getTargetPath(); SchemaNode targetSchemaNode = findDataSchemaNode(schemaContext, targetPath); if (targetSchemaNode instanceof DataSchemaNode
Collection<DataSchemaNode> childNodes = augmentation.getChildNodes(); if (areAllChildrenChoiceCaseNodes(childNodes)) { for (ChoiceCaseNode childCase : castChildNodesToChoiceCases(childNodes)) {
public static QName getAugmentationQName(final AugmentationSchema augmentation) { checkNotNull(augmentation, "Augmentation must not be null."); final QName identifier = getAugmentationIdentifier(augmentation); if(identifier != null) { return identifier; } URI namespace = null; Date revision = null; if(augmentation instanceof NamespaceRevisionAware) { namespace = ((NamespaceRevisionAware) augmentation).getNamespace(); revision = ((NamespaceRevisionAware) augmentation).getRevision(); } if(namespace == null || revision == null) { for(final DataSchemaNode child : augmentation.getChildNodes()) { // Derive QName from child nodes if(!child.isAugmenting()) { namespace = child.getQName().getNamespace(); revision = child.getQName().getRevision(); break; } } } checkState(namespace != null, "Augmentation namespace must not be null"); checkState(revision != null, "Augmentation revision must not be null"); // FIXME: Allways return a qname with module namespace. return QName.create(namespace,revision, "foo_augment"); }