-
- @Override
- public final ImmutableMap<AugmentationIdentifier, Type> getAvailableAugmentationTypes(
- final DataNodeContainer container) {
- if (container instanceof AugmentationTarget) {
- final Map<AugmentationIdentifier, Type> identifierToType = new HashMap<>();
- final BindingRuntimeTypes types = getTypes();
- for (final AugmentationSchemaNode augment : ((AugmentationTarget) container).getAvailableAugmentations()) {
- // Augmentation must have child nodes if is to be used with Binding classes
- AugmentationSchemaNode augOrig = augment;
- while (augOrig.getOriginalDefinition().isPresent()) {
- augOrig = augOrig.getOriginalDefinition().get();
- }
-
- if (!augment.getChildNodes().isEmpty()) {
- final Optional<Type> augType = types.findType(augOrig);
- if (augType.isPresent()) {
- identifierToType.put(getAugmentationIdentifier(augment), augType.get());
- }
- }
- }
- return ImmutableMap.copyOf(identifierToType);
- }
-
- return ImmutableMap.of();
- }
-
- @Override
- public final Class<?> getIdentityClass(final QName input) {
- return identityClasses.getUnchecked(input);
- }
-
- private static AugmentationIdentifier getAugmentationIdentifier(final AugmentationSchemaNode augment) {
- // FIXME: use DataSchemaContextNode.augmentationIdentifierFrom() once it does caching
- return AugmentationIdentifier.create(augment.getChildNodes().stream().map(DataSchemaNode::getQName)
- .collect(ImmutableSet.toImmutableSet()));
- }
-
- private static Set<Type> collectAllContainerTypes(final GeneratedType type, final Set<Type> collection) {
- for (final MethodSignature definition : type.getMethodDefinitions()) {
- Type childType = definition.getReturnType();
- if (childType instanceof ParameterizedType) {
- childType = ((ParameterizedType) childType).getActualTypeArguments()[0];
- }
- if (childType instanceof GeneratedType || childType instanceof GeneratedTypeBuilder) {
- collection.add(childType);
- }
- }
- for (final Type parent : type.getImplements()) {
- if (parent instanceof GeneratedType) {
- collectAllContainerTypes((GeneratedType) parent, collection);
- }
- }
- return collection;
- }
-
- private static <T extends SchemaNode> T getOriginalSchema(final T choice) {
- @SuppressWarnings("unchecked")
- final T original = (T) originalNodeOf(choice);
- if (original != null) {
- return original;
- }
- return choice;
- }
-
- private static @NonNull Optional<CaseSchemaNode> findInstantiatedCase(final ChoiceSchemaNode instantiatedChoice,
- final CaseSchemaNode originalDefinition) {
- CaseSchemaNode potential = instantiatedChoice.findCase(originalDefinition.getQName()).orElse(null);
- if (originalDefinition.equals(potential)) {
- return Optional.of(potential);
- }
- if (potential != null) {
- SchemaNode potentialRoot = originalNodeOf(potential);
- if (originalDefinition.equals(potentialRoot)) {
- return Optional.of(potential);
- }
- }
-
- // We try to find case by name, then lookup its root definition
- // and compare it with original definition
- // This solves case, if choice was inside grouping
- // which was used in different module and thus namespaces are
- // different, but local names are still same.
- //
- // Still we need to check equality of definition, because local name is not
- // sufficient to uniquelly determine equality of cases
- //
- for (CaseSchemaNode caze : instantiatedChoice.findCaseNodes(originalDefinition.getQName().getLocalName())) {
- if (originalDefinition.equals(originalNodeOf(caze))) {
- return Optional.of(caze);
- }
- }
- return Optional.empty();
- }
-
- private static @Nullable SchemaNode originalNodeOf(final SchemaNode node) {
- return node instanceof DerivableSchemaNode ? ((DerivableSchemaNode) node).getOriginal().orElse(null) : null;
- }