- private static final MethodType CONSTRUCTOR_TYPE = MethodType.methodType(void.class,
- DataObjectCodecContext.class, NormalizedNodeContainer.class);
- private static final MethodType DATAOBJECT_TYPE = MethodType.methodType(DataObject.class,
- DataObjectCodecContext.class, NormalizedNodeContainer.class);
- private static final Augmentations EMPTY_AUGMENTATIONS = new Augmentations(ImmutableMap.of(), ImmutableMap.of());
-
- private final ImmutableMap<String, ValueNodeCodecContext> leafChild;
- private final ImmutableMap<YangInstanceIdentifier.PathArgument, NodeContextSupplier> byYang;
- private final ImmutableMap<Class<?>, DataContainerCodecPrototype<?>> byStreamClass;
- private final ImmutableMap<Class<?>, DataContainerCodecPrototype<?>> byBindingArgClass;
- private final ImmutableMap<AugmentationIdentifier, Type> possibleAugmentations;
- private final MethodHandle proxyConstructor;
-
- // FIXME: the presence of these two volatile fields may be preventing us from being able to improve
- // DataContainerCodecPrototype.get() publication.
- @SuppressWarnings("rawtypes")
- private static final AtomicReferenceFieldUpdater<DataObjectCodecContext, Augmentations>
- AUGMENTATIONS_UPDATER = AtomicReferenceFieldUpdater.newUpdater(DataObjectCodecContext.class,
- Augmentations.class, "augmentations");
- private volatile Augmentations augmentations = EMPTY_AUGMENTATIONS;
-
- private volatile ImmutableMap<Class<?>, DataContainerCodecPrototype<?>> mismatchedAugmented = ImmutableMap.of();
-
- DataObjectCodecContext(final DataContainerCodecPrototype<T> prototype) {
- this(prototype, null);
- }
-
- DataObjectCodecContext(final DataContainerCodecPrototype<T> prototype, final Method keyMethod) {
- super(prototype);
-
- final Class<D> bindingClass = getBindingClass();
-
- final ImmutableMap<Method, ValueNodeCodecContext> tmpLeaves = factory().getLeafNodes(bindingClass, getSchema());
- final Map<Class<?>, Method> clsToMethod = BindingReflections.getChildrenClassToMethod(bindingClass);
-
- final Map<YangInstanceIdentifier.PathArgument, NodeContextSupplier> byYangBuilder = new HashMap<>();
- final Map<Class<?>, DataContainerCodecPrototype<?>> byStreamClassBuilder = new HashMap<>();
- final Map<Class<?>, DataContainerCodecPrototype<?>> byBindingArgClassBuilder = new HashMap<>();
-
- // Adds leaves to mapping
- final Builder<String, ValueNodeCodecContext> leafChildBuilder =
- ImmutableMap.builderWithExpectedSize(tmpLeaves.size());
- for (final Entry<Method, ValueNodeCodecContext> entry : tmpLeaves.entrySet()) {
- final ValueNodeCodecContext leaf = entry.getValue();
- leafChildBuilder.put(leaf.getSchema().getQName().getLocalName(), leaf);
- byYangBuilder.put(leaf.getDomPathArgument(), leaf);
- }
- this.leafChild = leafChildBuilder.build();
-
- final Map<Method, Class<?>> tmpDataObjects = new HashMap<>();
- for (final Entry<Class<?>, Method> childDataObj : clsToMethod.entrySet()) {
- final Method method = childDataObj.getValue();
- verify(!method.isDefault(), "Unexpected default method %s in %s", method, bindingClass);
-
- final Class<?> retClass = childDataObj.getKey();
- if (OpaqueObject.class.isAssignableFrom(retClass)) {
- // Filter OpaqueObjects, they are not containers
- continue;
- }
-
- final DataContainerCodecPrototype<?> childProto = loadChildPrototype(retClass);
- tmpDataObjects.put(method, childProto.getBindingClass());
- byStreamClassBuilder.put(childProto.getBindingClass(), childProto);
- byYangBuilder.put(childProto.getYangArg(), childProto);
- if (childProto.isChoice()) {
- final ChoiceNodeCodecContext<?> choice = (ChoiceNodeCodecContext<?>) childProto.get();
- for (final Class<?> cazeChild : choice.getCaseChildrenClasses()) {
- byBindingArgClassBuilder.put(cazeChild, childProto);
- }
- }
- }