X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-dom-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fcodec%2Fimpl%2FDataObjectCodecContext.java;h=2fa41e9585c2599e14dd84413affe9c588828c1b;hb=refs%2Fchanges%2F56%2F100156%2F1;hp=47575f9321d707a46eeb43a1276d983e76127bb5;hpb=dd0dc89b9d35cf8bae27bc8a277943bd61594ebd;p=mdsal.git diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataObjectCodecContext.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataObjectCodecContext.java index 47575f9321..2fa41e9585 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataObjectCodecContext.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataObjectCodecContext.java @@ -177,14 +177,16 @@ public abstract class DataObjectCodecContext> augByYang = new HashMap<>(); final Map, DataContainerCodecPrototype> augByStream = new HashMap<>(); for (final AugmentRuntimeType augment : possibleAugmentations) { - 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); + final DataContainerCodecPrototype augProto = loadAugmentPrototype(augment); + if (augProto != null) { + 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); @@ -386,23 +388,29 @@ public abstract class DataObjectCodecContext getAugmentationPrototype(final AugmentRuntimeType augment) { - final BindingRuntimeContext ctx = factory().getRuntimeContext(); + private @Nullable DataContainerCodecPrototype loadAugmentPrototype(final AugmentRuntimeType augment) { + // FIXME: in face of deviations this code should be looking at declared view, i.e. all possibilities at augment + // declaration site + final var possibleChildren = augment.statement() + .streamEffectiveSubstatements(SchemaTreeEffectiveStatement.class) + .map(SchemaTreeEffectiveStatement::getIdentifier) + .collect(ImmutableSet.toImmutableSet()); + if (possibleChildren.isEmpty()) { + return null; + } + final var factory = factory(); final GeneratedType javaType = augment.javaType(); final Class> augClass; try { - augClass = ctx.loadClass(javaType); + augClass = factory.getRuntimeContext().loadClass(javaType); } catch (final ClassNotFoundException e) { throw new IllegalStateException( "RuntimeContext references type " + javaType + " but failed to load its class", e); } - // TODO: at some point we need the effective children - return DataContainerCodecPrototype.from(augClass, new AugmentationIdentifier(augment.statement() - .streamEffectiveSubstatements(SchemaTreeEffectiveStatement.class) - .map(SchemaTreeEffectiveStatement::getIdentifier) - .collect(ImmutableSet.toImmutableSet())), augment, factory()); + return DataContainerCodecPrototype.from(augClass, new AugmentationIdentifier(possibleChildren), augment, + factory); } @SuppressWarnings("checkstyle:illegalCatch")