- DataObjectCodecContext(final DataContainerCodecPrototype<T> prototype, final Method keyMethod) {
- super(prototype);
-
- final Class<D> bindingClass = getBindingClass();
-
- final ImmutableMap<Method, ValueNodeCodecContext> tmpLeaves = factory().getLeafNodes(bindingClass,
- getType().statement());
- final Map<Class<? extends DataContainer>, Method> clsToMethod = 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 ValueNodeCodecContext leaf : tmpLeaves.values()) {
- leafChildBuilder.put(leaf.getSchema().getQName().getLocalName(), leaf);
- byYangBuilder.put(leaf.getDomPathArgument(), leaf);
- }
- this.leafChild = leafChildBuilder.build();
-
- final Map<Class<?>, PropertyInfo> daoProperties = new HashMap<>();
- for (final Entry<Class<? extends DataContainer>, Method> childDataObj : clsToMethod.entrySet()) {
- final Method method = childDataObj.getValue();
- verify(!method.isDefault(), "Unexpected default method %s in %s", method, bindingClass);
-
- final Class<? extends DataContainer> retClass = childDataObj.getKey();
- if (OpaqueObject.class.isAssignableFrom(retClass)) {
- // Filter OpaqueObjects, they are not containers
- continue;
- }
-
- // Record getter method
- daoProperties.put(retClass, new PropertyInfo.Getter(method));
-
- final DataContainerCodecPrototype<?> childProto = loadChildPrototype(retClass);
- byStreamClassBuilder.put(childProto.getBindingClass(), childProto);
- byYangBuilder.put(childProto.getYangArg(), childProto);
-
- // FIXME: It really feels like we should be specializing DataContainerCodecPrototype so as to ditch
- // createInstance() and then we could do an instanceof check instead.
- if (childProto.getType() instanceof ChoiceRuntimeType) {
- final ChoiceNodeCodecContext<?> choice = (ChoiceNodeCodecContext<?>) childProto.get();
- for (final Class<?> cazeChild : choice.getCaseChildrenClasses()) {
- byBindingArgClassBuilder.put(cazeChild, childProto);
- }
- }
- }