X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fdom%2Fserializer%2Fimpl%2FLazyGeneratedCodecRegistry.java;h=d33272d6413bfa90628f49a459671eab756ef2d0;hp=de6836489e6a6b970fb96a409e832876d02e82a7;hb=43f506ead639607367b6bdc8a04287b57e189b01;hpb=a158ee12b65d80611aa7f2a34ab962ea795dccec diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/dom/serializer/impl/LazyGeneratedCodecRegistry.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/dom/serializer/impl/LazyGeneratedCodecRegistry.java index de6836489e..d33272d641 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/dom/serializer/impl/LazyGeneratedCodecRegistry.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/dom/serializer/impl/LazyGeneratedCodecRegistry.java @@ -91,7 +91,7 @@ public class LazyGeneratedCodecRegistry implements // Map> typeToClass = new ConcurrentHashMap<>(); @SuppressWarnings("rawtypes") - private ConcurrentMap typeToCaseNodes = new ConcurrentHashMap<>(); + private ConcurrentMap typeToCaseCodecs = new ConcurrentHashMap<>(); private CaseClassMapFacade classToCaseRawCodec = new CaseClassMapFacade(); @@ -136,15 +136,14 @@ public class LazyGeneratedCodecRegistry implements // } return weakRef.get(); } - + @Override - public void putPathToClass(List names,Class cls) { + public void putPathToClass(List names, Class cls) { Type reference = Types.typeForClass(cls); - pathToInstantiatedType.put(names, reference ); + pathToInstantiatedType.put(names, reference); bindingClassEncountered(cls); } - @Override public IdentifierCodec getKeyCodecForPath(List names) { @SuppressWarnings("unchecked") @@ -297,10 +296,12 @@ public class LazyGeneratedCodecRegistry implements // return potential; } ConcreteType typeref = Types.typeForClass(caseClass); - ChoiceCaseCodecImpl caseCodec = typeToCaseNodes.get(typeref); + ChoiceCaseCodecImpl caseCodec = typeToCaseCodecs.get(typeref); + checkState(caseCodec != null, "Case Codec was not created proactivelly for %s", caseClass.getName()); + checkState(caseCodec.getSchema() != null, "Case schema is not available for %s", caseClass.getName()); @SuppressWarnings("unchecked") - Class newCodec = generator.caseCodecFor(caseClass, caseCodec.schema); + Class newCodec = generator.caseCodecFor(caseClass, caseCodec.getSchema()); BindingCodec newInstance = newInstanceOf(newCodec); caseCodec.setDelegate(newInstance); caseCodecs.put(caseClass, caseCodec); @@ -322,17 +323,23 @@ public class LazyGeneratedCodecRegistry implements // for (Entry caseNode : cases.entrySet()) { ReferencedTypeImpl typeref = new ReferencedTypeImpl(caseNode.getValue().getPackageName(), caseNode .getValue().getName()); + + LOG.info("Case path: {} Type : {}", caseNode.getKey(), caseNode.getValue().getFullyQualifiedName()); + pathToType.put(caseNode.getKey(), caseNode.getValue()); + ChoiceCaseNode node = (ChoiceCaseNode) SchemaContextUtil.findDataSchemaNode(module, caseNode.getKey()); + if (node == null) { LOG.error("YANGTools Bug: SchemaNode for {}, with path {} was not found in context.", typeref.getFullyQualifiedName(), caseNode.getKey()); + @SuppressWarnings("rawtypes") + ChoiceCaseCodecImpl value = new ChoiceCaseCodecImpl(); + typeToCaseCodecs.putIfAbsent(typeref, value); continue; } - - pathToType.put(caseNode.getKey(), caseNode.getValue()); @SuppressWarnings("rawtypes") ChoiceCaseCodecImpl value = new ChoiceCaseCodecImpl(node); - typeToCaseNodes.putIfAbsent(typeref, value); + typeToCaseCodecs.putIfAbsent(typeref, value); } } @@ -352,18 +359,24 @@ public class LazyGeneratedCodecRegistry implements // choiceCodecs.put(choiceClass, newCodec); CodecMapping.setClassToCaseMap(choiceCodec, (Map, BindingCodec>) classToCaseRawCodec); CodecMapping.setCompositeNodeToCaseMap(choiceCodec, newCodec.getCompositeToCase()); - + tryToCreateCasesCodecs(schema); } private void tryToCreateCasesCodecs(ChoiceNode schema) { - for(ChoiceCaseNode caseNode : schema.getCases()) { + for (ChoiceCaseNode caseNode : schema.getCases()) { SchemaPath path = caseNode.getPath(); GeneratedTypeBuilder type; - if(path != null && (type = pathToType.get(path)) != null) { + if (path != null && (type = pathToType.get(path)) != null) { + ReferencedTypeImpl typeref = new ReferencedTypeImpl(type.getPackageName(), type.getName()); + ChoiceCaseCodecImpl partialCodec = typeToCaseCodecs.get(typeref); + if(partialCodec.getSchema() == null ) { + partialCodec.setSchema(caseNode); + } + Class caseClass = ClassLoaderUtils.tryToLoadClassWithTCCL(type.getFullyQualifiedName()); - if(caseClass != null) { + if (caseClass != null) { getCaseCodecFor(caseClass); } } @@ -381,8 +394,7 @@ public class LazyGeneratedCodecRegistry implements // } @Override - public void onDataContainerCodecCreated(Class dataClass, - Class> dataCodec) { + public void onDataContainerCodecCreated(Class dataClass, Class> dataCodec) { if (Augmentable.class.isAssignableFrom(dataClass)) { AugmentableCompositeCodec augmentableCodec = getAugmentableCodec(dataClass); CodecMapping.setAugmentationCodec(dataCodec, augmentableCodec); @@ -471,15 +483,15 @@ public class LazyGeneratedCodecRegistry implements // @SuppressWarnings("rawtypes") private static class ChoiceCaseCodecImpl implements ChoiceCaseCodec, // Delegator { - private final boolean augmenting; + private boolean augmenting; private BindingCodec delegate; - private final Set validNames; - private final Set validQNames; + private Set validNames; + private Set validQNames; private ChoiceCaseNode schema; - public ChoiceCaseCodecImpl(ChoiceCaseNode caseNode) { - this.delegate = NOT_READY_CODEC; + public void setSchema(ChoiceCaseNode caseNode) { + this.schema = schema; this.schema = caseNode; validNames = new HashSet<>(); validQNames = new HashSet<>(); @@ -491,6 +503,15 @@ public class LazyGeneratedCodecRegistry implements // augmenting = caseNode.isAugmenting(); } + public ChoiceCaseCodecImpl() { + this.delegate = NOT_READY_CODEC; + } + + public ChoiceCaseCodecImpl(ChoiceCaseNode caseNode) { + this.delegate = NOT_READY_CODEC; + setSchema(caseNode); + } + @Override public ValueWithQName deserialize(Node input) { throw new UnsupportedOperationException("Direct invocation of this codec is not allowed.");