-
- this.byYang = ImmutableMap.copyOf(byYangBuilder);
- this.byStreamClass = ImmutableMap.copyOf(byStreamClassBuilder);
-
- // Slight footprint optimization: we do not want to copy byStreamClass, as that would force its entrySet view
- // to be instantiated. Furthermore the two maps can easily end up being equal -- hence we can reuse
- // byStreamClass for the purposes of both.
- byBindingArgClassBuilder.putAll(byStreamClassBuilder);
- this.byBindingArgClass = byStreamClassBuilder.equals(byBindingArgClassBuilder) ? this.byStreamClass
- : ImmutableMap.copyOf(byBindingArgClassBuilder);
-
- final ImmutableMap<AugmentationIdentifier, Type> possibleAugmentations;
- if (Augmentable.class.isAssignableFrom(bindingClass)) {
- possibleAugmentations = factory().getRuntimeContext().getAvailableAugmentationTypes(getSchema());
- generatedClass = CodecDataObjectGenerator.generateAugmentable(prototype.getFactory().getLoader(),
- bindingClass, tmpLeaves, tmpDataObjects, keyMethod);
- } else {
- possibleAugmentations = ImmutableMap.of();
- generatedClass = CodecDataObjectGenerator.generate(prototype.getFactory().getLoader(), bindingClass,
- tmpLeaves, tmpDataObjects, keyMethod);
- }
-
- // Iterate over all possible augmentations, indexing them as needed
- final Map<PathArgument, DataContainerCodecPrototype<?>> augByYang = new HashMap<>();
- final Map<Class<?>, DataContainerCodecPrototype<?>> augByStream = new HashMap<>();
- for (final Type augment : possibleAugmentations.values()) {
- final DataContainerCodecPrototype<?> augProto = getAugmentationPrototype(augment);
- final PathArgument augYangArg = augProto.getYangArg();
- if (augByYang.putIfAbsent(augYangArg, augProto) == null) {
- LOG.trace("Discovered new YANG mapping {} -> {} in {}", augYangArg, augProto, this);
- }
- final Class<?> augBindingClass = augProto.getBindingClass();
- if (augByStream.putIfAbsent(augBindingClass, augProto) == null) {
- LOG.trace("Discovered new class mapping {} -> {} in {}", augBindingClass, augProto, this);
- }
- }
- augmentationByYang = ImmutableMap.copyOf(augByYang);
- augmentationByStream = ImmutableMap.copyOf(augByStream);
-
- final MethodHandle ctor;
- try {
- ctor = MethodHandles.publicLookup().findConstructor(generatedClass, CONSTRUCTOR_TYPE);
- } catch (NoSuchMethodException | IllegalAccessException e) {
- throw new LinkageError("Failed to find contructor for class " + generatedClass, e);
- }
-
- proxyConstructor = ctor.asType(DATAOBJECT_TYPE);