- private DataContainerCodecPrototype<?> loadChildPrototype(final Class<?> childClass) {
- final DataSchemaNode origDef = factory().getRuntimeContext().getSchemaDefinition(childClass);
- // Direct instantiation or use in same module in which grouping
- // was defined.
- DataSchemaNode sameName;
- try {
- sameName = getSchema().dataChildByName(origDef.getQName());
- } catch (final IllegalArgumentException e) {
- LOG.trace("Failed to find schema for {}", origDef, e);
- sameName = null;
- }
- final DataSchemaNode childSchema;
- if (sameName != null) {
- // Check if it is:
- // - exactly same schema node, or
- // - instantiated node was added via uses statement and is instantiation of same grouping
- if (origDef.equals(sameName) || origDef.equals(getRootOriginalIfPossible(sameName))) {
- childSchema = sameName;
- } else {
- // Node has same name, but clearly is different
- childSchema = null;
- }
- } else {
- // We are looking for instantiation via uses in other module
- final QName instantiedName = origDef.getQName().bindTo(namespace());
- final DataSchemaNode potential = getSchema().dataChildByName(instantiedName);
- // We check if it is really instantiated from same definition as class was derived
- if (potential != null && origDef.equals(getRootOriginalIfPossible(potential))) {
- childSchema = potential;
- } else {
- childSchema = null;
- }
- }
- final DataSchemaNode nonNullChild =
- childNonNull(childSchema, childClass, "Node %s does not have child named %s", getSchema(), childClass);
- return DataContainerCodecPrototype.from(createBindingArg(childClass, nonNullChild), nonNullChild, factory());
- }
+ private DataContainerCodecPrototype<?> loadChildPrototype(final Class<? extends DataContainer> childClass) {
+ final var type = getType();
+ final var child = childNonNull(type.bindingChild(JavaTypeName.create(childClass)), childClass,
+ "Node %s does not have child named %s", type, childClass);