1 package org.opendaylight.controller.sal.binding.dom.serializer.impl;
3 import java.lang.ref.WeakReference;
4 import java.lang.reflect.Field;
5 import java.util.ArrayList;
6 import java.util.Collection;
7 import java.util.Collections;
8 import java.util.HashMap;
9 import java.util.HashSet;
10 import java.util.Iterator;
11 import java.util.List;
13 import java.util.Map.Entry;
14 import java.util.Objects;
15 import java.util.concurrent.ConcurrentHashMap;
16 import java.util.concurrent.ConcurrentMap;
18 import java.util.WeakHashMap;
20 import org.opendaylight.controller.sal.binding.dom.serializer.api.AugmentationCodec;
21 import org.opendaylight.controller.sal.binding.dom.serializer.api.ChoiceCaseCodec;
22 import org.opendaylight.controller.sal.binding.dom.serializer.api.ChoiceCodec;
23 import org.opendaylight.controller.sal.binding.dom.serializer.api.CodecRegistry;
24 import org.opendaylight.controller.sal.binding.dom.serializer.api.DataContainerCodec;
25 import org.opendaylight.controller.sal.binding.dom.serializer.api.DomCodec;
26 import org.opendaylight.controller.sal.binding.dom.serializer.api.IdentifierCodec;
27 import org.opendaylight.controller.sal.binding.dom.serializer.api.InstanceIdentifierCodec;
28 import org.opendaylight.controller.sal.binding.dom.serializer.api.ValueWithQName;
29 import org.opendaylight.controller.sal.core.api.model.SchemaServiceListener;
30 import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;
31 import org.opendaylight.yangtools.binding.generator.util.Types;
32 import org.opendaylight.yangtools.concepts.Delegator;
33 import org.opendaylight.yangtools.concepts.Identifiable;
34 import org.opendaylight.yangtools.yang.binding.Augmentable;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
36 import org.opendaylight.yangtools.yang.binding.BindingCodec;
37 import org.opendaylight.yangtools.yang.binding.DataContainer;
38 import org.opendaylight.yangtools.yang.binding.DataObject;
39 import org.opendaylight.yangtools.yang.binding.Identifier;
40 import org.opendaylight.yangtools.yang.common.QName;
41 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
42 import org.opendaylight.yangtools.yang.data.api.Node;
43 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
44 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
45 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
46 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
47 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
48 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
49 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
50 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
54 import static com.google.common.base.Preconditions.*;
55 import static org.opendaylight.controller.sal.binding.dom.serializer.impl.IntermediateMapping.*;
57 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleContext;
58 import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType;
59 import org.opendaylight.yangtools.sal.binding.model.api.Type;
60 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
61 import org.opendaylight.yangtools.yang.model.api.Module;
62 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
64 public class LazyGeneratedCodecRegistry implements //
66 SchemaServiceListener, //
69 private final static Logger LOG = LoggerFactory.getLogger(LazyGeneratedCodecRegistry.class);
70 private final static LateMixinCodec NOT_READY_CODEC = new LateMixinCodec();
72 private final InstanceIdentifierCodec instanceIdentifierCodec = new InstanceIdentifierCodecImpl(this);
74 private TransformerGenerator generator;
76 // Concrete class to codecs
77 private Map<Class<?>, DataContainerCodec<?>> containerCodecs = new WeakHashMap<>();
78 private Map<Class<?>, IdentifierCodec<?>> identifierCodecs = new WeakHashMap<>();
79 private Map<Class<?>, ChoiceCodecImpl<?>> choiceCodecs = new WeakHashMap<>();
80 private Map<Class<?>, ChoiceCaseCodecImpl<?>> caseCodecs = new WeakHashMap<>();
81 private Map<Class<?>, AugmentableCompositeCodec> augmentableCodecs = new WeakHashMap<>();
83 /** Binding type to encountered classes mapping **/
84 @SuppressWarnings("rawtypes")
85 Map<Type, WeakReference<Class>> typeToClass = new ConcurrentHashMap<>();
87 @SuppressWarnings("rawtypes")
88 private ConcurrentMap<Type, ChoiceCaseCodecImpl> typeToCaseNodes = new ConcurrentHashMap<>();
90 private CaseClassMapFacade classToCaseRawCodec = new CaseClassMapFacade();
92 Map<SchemaPath, GeneratedTypeBuilder> pathToType = new ConcurrentHashMap<>();
94 private SchemaContext currentSchema;
96 public TransformerGenerator getGenerator() {
100 public void setGenerator(TransformerGenerator generator) {
101 this.generator = generator;
105 public InstanceIdentifierCodec getInstanceIdentifierCodec() {
106 return instanceIdentifierCodec;
110 public <T extends Augmentation<?>> AugmentationCodec<T> getCodecForAugmentation(Class<T> object) {
111 // TODO Auto-generated method stub
116 public Class<?> getClassForPath(List<QName> names) {
117 DataSchemaNode node = getSchemaNode(names);
118 SchemaPath path = node.getPath();
119 GeneratedTypeBuilder type = pathToType.get(path);
120 ReferencedTypeImpl typeref = new ReferencedTypeImpl(type.getPackageName(), type.getName());
121 @SuppressWarnings("rawtypes")
122 WeakReference<Class> weakRef = typeToClass.get(typeref);
123 if(weakRef == null) {
124 LOG.error("Could not find loaded class for path: {} and type: {}",path,typeref.getFullyQualifiedName());
126 return weakRef.get();
130 public IdentifierCodec<?> getKeyCodecForPath(List<QName> names) {
131 @SuppressWarnings("unchecked")
132 Class<? extends Identifiable<?>> cls = (Class<? extends Identifiable<?>>) getClassForPath(names);
133 return getIdentifierCodecForIdentifiable(cls);
137 public <T extends DataContainer> DataContainerCodec<T> getCodecForDataObject(Class<T> type) {
138 @SuppressWarnings("unchecked")
139 DataContainerCodec<T> ret = (DataContainerCodec<T>) containerCodecs.get(type);
143 Class<? extends BindingCodec<Map<QName, Object>, Object>> newType = generator.transformerFor(type);
144 BindingCodec<Map<QName, Object>, Object> rawCodec = newInstanceOf(newType);
145 DataContainerCodecImpl<T> newWrapper = new DataContainerCodecImpl<>(rawCodec);
146 containerCodecs.put(type, newWrapper);
151 @SuppressWarnings("rawtypes")
152 public void bindingClassEncountered(Class cls) {
154 ConcreteType typeRef = Types.typeForClass(cls);
155 if(typeToClass.containsKey(typeRef)) {
158 LOG.info("Binding Class {} encountered.",cls);
159 WeakReference<Class> weakRef = new WeakReference<>(cls);
160 typeToClass.put(typeRef, weakRef);
161 if(DataObject.class.isAssignableFrom(cls)) {
162 @SuppressWarnings({"unchecked","unused"})
163 Object cdc = getCodecForDataObject((Class<? extends DataObject>) cls);
168 public void onClassProcessed(Class<?> cls) {
169 ConcreteType typeRef = Types.typeForClass(cls);
170 if(typeToClass.containsKey(typeRef)) {
173 LOG.info("Binding Class {} encountered.",cls);
174 WeakReference<Class> weakRef = new WeakReference<>((Class) cls);
175 typeToClass.put(typeRef, weakRef);
178 private DataSchemaNode getSchemaNode(List<QName> path) {
179 QName firstNode = path.get(0);
180 DataNodeContainer previous = currentSchema.findModuleByNamespaceAndRevision(firstNode.getNamespace(),
181 firstNode.getRevision());
182 Iterator<QName> iterator = path.iterator();
183 while (iterator.hasNext()) {
184 QName arg = iterator.next();
185 DataSchemaNode currentNode = previous.getDataChildByName(arg);
186 if (currentNode == null && previous instanceof DataNodeContainer) {
187 currentNode = searchInChoices(previous, arg);
189 if (currentNode instanceof DataNodeContainer) {
190 previous = (DataNodeContainer) currentNode;
191 } else if (currentNode instanceof LeafSchemaNode || currentNode instanceof LeafListSchemaNode) {
192 checkState(!iterator.hasNext(), "Path tries to nest inside leaf node.");
196 return (DataSchemaNode) previous;
199 private DataSchemaNode searchInChoices(DataNodeContainer node, QName arg) {
200 Set<DataSchemaNode> children = node.getChildNodes();
201 for (DataSchemaNode child : children) {
202 if (child instanceof ChoiceNode) {
203 ChoiceNode choiceNode = (ChoiceNode) child;
204 DataSchemaNode potential = searchInCases(choiceNode, arg);
205 if (potential != null) {
213 private DataSchemaNode searchInCases(ChoiceNode choiceNode, QName arg) {
214 Set<ChoiceCaseNode> cases = choiceNode.getCases();
215 for (ChoiceCaseNode caseNode : cases) {
216 DataSchemaNode node = caseNode.getDataChildByName(arg);
224 private <T> T newInstanceOf(Class<?> newType) {
226 @SuppressWarnings("unchecked")
227 T ret = (T) newType.newInstance();
229 } catch (InstantiationException e) {
230 throw new IllegalStateException(e);
231 } catch (IllegalAccessException e) {
232 throw new IllegalStateException(e);
237 public <T extends Identifiable<?>> IdentifierCodec<?> getIdentifierCodecForIdentifiable(Class<T> type) {
238 IdentifierCodec<?> obj = identifierCodecs.get(type);
242 Class<? extends BindingCodec<Map<QName, Object>, Object>> newCodec = generator
243 .keyTransformerForIdentifiable(type);
244 BindingCodec<Map<QName, Object>, Object> newInstance;
245 newInstance = newInstanceOf(newCodec);
246 IdentifierCodecImpl<?> newWrapper = new IdentifierCodecImpl<>(newInstance);
247 identifierCodecs.put(type, newWrapper);
252 public void onCodecCreated(Class<?> cls) {
253 CodecMapping.setIdentifierCodec(cls, instanceIdentifierCodec);
257 public <T extends Identifier<?>> IdentifierCodec<T> getCodecForIdentifier(Class<T> object) {
258 @SuppressWarnings("unchecked")
259 IdentifierCodec<T> obj = (IdentifierCodec<T>) identifierCodecs.get(object);
263 Class<? extends BindingCodec<Map<QName, Object>, Object>> newCodec = generator
264 .keyTransformerForIdentifier(object);
265 BindingCodec<Map<QName, Object>, Object> newInstance;
266 newInstance = newInstanceOf(newCodec);
267 IdentifierCodecImpl<T> newWrapper = new IdentifierCodecImpl<>(newInstance);
268 identifierCodecs.put(object, newWrapper);
272 @SuppressWarnings("rawtypes")
273 public ChoiceCaseCodecImpl getCaseCodecFor(Class caseClass) {
274 ChoiceCaseCodecImpl<?> potential = caseCodecs.get(caseClass);
275 if (potential != null) {
278 ConcreteType typeref = Types.typeForClass(caseClass);
279 ChoiceCaseCodecImpl caseCodec = typeToCaseNodes.get(typeref);
281 @SuppressWarnings("unchecked")
282 Class<? extends BindingCodec> newCodec = generator.caseCodecFor(caseClass, caseCodec.schema);
283 BindingCodec newInstance = newInstanceOf(newCodec);
284 caseCodec.setDelegate(newInstance);
285 caseCodecs.put(caseClass, caseCodec);
287 for (Entry<Class<?>, ChoiceCodecImpl<?>> choice : choiceCodecs.entrySet()) {
288 if (choice.getKey().isAssignableFrom(caseClass)) {
289 choice.getValue().cases.put(caseClass, caseCodec);
295 public void onModuleContextAdded(SchemaContext schemaContext, Module module, ModuleContext context) {
296 pathToType.putAll(context.getChildNodes());
298 captureCases(context.getCases(), schemaContext);
301 private void captureCases(Map<SchemaPath, GeneratedTypeBuilder> cases, SchemaContext module) {
302 for (Entry<SchemaPath, GeneratedTypeBuilder> caseNode : cases.entrySet()) {
303 ReferencedTypeImpl typeref = new ReferencedTypeImpl(caseNode.getValue().getPackageName(), caseNode
304 .getValue().getName());
305 ChoiceCaseNode node = (ChoiceCaseNode) SchemaContextUtil.findDataSchemaNode(module, caseNode.getKey());
307 LOG.error("YANGTools Bug: SchemaNode for {}, with path {} was not found in context.",
308 typeref.getFullyQualifiedName(), caseNode.getKey());
312 @SuppressWarnings("rawtypes")
313 ChoiceCaseCodecImpl value = new ChoiceCaseCodecImpl(node);
314 typeToCaseNodes.putIfAbsent(typeref, value);
319 public void onGlobalContextUpdated(SchemaContext context) {
320 currentSchema = context;
323 @SuppressWarnings({ "unchecked", "rawtypes" })
325 public void onChoiceCodecCreated(Class<?> choiceClass,
326 Class<? extends BindingCodec<Map<QName, Object>, Object>> choiceCodec) {
327 ChoiceCodec<?> oldCodec = choiceCodecs.get(choiceClass);
328 checkState(oldCodec == null);
329 BindingCodec<Map<QName, Object>, Object> delegate = newInstanceOf(choiceCodec);
330 ChoiceCodecImpl<?> newCodec = new ChoiceCodecImpl(delegate);
331 choiceCodecs.put(choiceClass, newCodec);
332 CodecMapping.setClassToCaseMap(choiceCodec, (Map<Class<?>, BindingCodec<?, ?>>) classToCaseRawCodec);
333 CodecMapping.setCompositeNodeToCaseMap(choiceCodec, newCodec.getCompositeToCase());
338 public void onValueCodecCreated(Class<?> valueClass, Class<?> valueCodec) {
342 public void onCaseCodecCreated(Class<?> choiceClass,
343 Class<? extends BindingCodec<Map<QName, Object>, Object>> choiceCodec) {
347 public void onDataContainerCodecCreated(Class<?> dataClass,
348 Class<? extends BindingCodec<Map<QName, Object>, Object>> dataCodec) {
349 if (Augmentable.class.isAssignableFrom(dataClass)) {
350 AugmentableCompositeCodec augmentableCodec = getAugmentableCodec(dataClass);
351 CodecMapping.setAugmentationCodec(dataCodec, augmentableCodec);
356 private AugmentableCompositeCodec getAugmentableCodec(Class<?> dataClass) {
357 AugmentableCompositeCodec ret = augmentableCodecs.get(dataClass);
361 ret = new AugmentableCompositeCodec(dataClass);
362 augmentableCodecs.put(dataClass, ret);
366 private static abstract class IntermediateCodec<T> implements //
367 DomCodec<T>, Delegator<BindingCodec<Map<QName, Object>, Object>> {
369 private final BindingCodec<Map<QName, Object>, Object> delegate;
372 public BindingCodec<Map<QName, Object>, Object> getDelegate() {
376 public IntermediateCodec(BindingCodec<Map<QName, Object>, Object> delegate) {
377 this.delegate = delegate;
381 public Node<?> serialize(ValueWithQName<T> input) {
382 Map<QName, Object> intermediateOutput = delegate.serialize(input);
383 return toNode(intermediateOutput);
387 private static class IdentifierCodecImpl<T extends Identifier<?>> //
388 extends IntermediateCodec<T> //
389 implements IdentifierCodec<T> {
391 public IdentifierCodecImpl(BindingCodec<Map<QName, Object>, Object> delegate) {
396 public ValueWithQName<T> deserialize(Node<?> input) {
397 QName qname = input.getNodeType();
398 @SuppressWarnings("unchecked")
399 T value = (T) getDelegate().deserialize((Map<QName, Object>) input);
400 return new ValueWithQName<T>(qname, value);
404 public CompositeNode serialize(ValueWithQName<T> input) {
405 return (CompositeNode) super.serialize(input);
409 private static class DataContainerCodecImpl<T extends DataContainer> //
410 extends IntermediateCodec<T> //
411 implements DataContainerCodec<T> {
413 public DataContainerCodecImpl(BindingCodec<Map<QName, Object>, Object> delegate) {
418 public ValueWithQName<T> deserialize(Node<?> input) {
422 QName qname = input.getNodeType();
423 @SuppressWarnings("unchecked")
424 T value = (T) getDelegate().deserialize((Map<QName, Object>) input);
425 return new ValueWithQName<T>(qname, value);
429 public CompositeNode serialize(ValueWithQName<T> input) {
430 return (CompositeNode) super.serialize(input);
434 @SuppressWarnings("rawtypes")
435 private static class ChoiceCaseCodecImpl<T extends DataContainer> implements ChoiceCaseCodec<T>, //
436 Delegator<BindingCodec> {
437 private final boolean augmenting;
438 private BindingCodec delegate;
440 private final Set<String> validNames;
441 private final Set<QName> validQNames;
442 private ChoiceCaseNode schema;
444 public ChoiceCaseCodecImpl(ChoiceCaseNode caseNode) {
445 this.delegate = NOT_READY_CODEC;
446 this.schema = caseNode;
447 validNames = new HashSet<>();
448 validQNames = new HashSet<>();
449 for (DataSchemaNode node : caseNode.getChildNodes()) {
450 QName qname = node.getQName();
451 validQNames.add(qname);
452 validNames.add(qname.getLocalName());
454 augmenting = caseNode.isAugmenting();
458 public ValueWithQName<T> deserialize(Node<?> input) {
459 throw new UnsupportedOperationException("Direct invocation of this codec is not allowed.");
463 public CompositeNode serialize(ValueWithQName<T> input) {
464 throw new UnsupportedOperationException("Direct invocation of this codec is not allowed.");
467 public BindingCodec getDelegate() {
471 public void setDelegate(BindingCodec delegate) {
472 this.delegate = delegate;
475 public ChoiceCaseNode getSchema() {
480 public boolean isAcceptable(Node<?> input) {
481 if (false == (input instanceof CompositeNode)) {
483 return checkAugmenting((CompositeNode) input);
485 return checkLocal((CompositeNode) input);
491 private boolean checkLocal(CompositeNode input) {
492 QName parent = input.getNodeType();
493 for (Node<?> childNode : input.getChildren()) {
494 QName child = childNode.getNodeType();
495 if (false == Objects.equals(parent.getNamespace(), child.getNamespace())) {
498 if (false == Objects.equals(parent.getRevision(), child.getRevision())) {
501 if (validNames.contains(child.getLocalName())) {
508 private boolean checkAugmenting(CompositeNode input) {
509 for (Node<?> child : input.getChildren()) {
510 if (validQNames.contains(child.getNodeType())) {
518 private static class ChoiceCodecImpl<T> implements ChoiceCodec<T> {
520 private final BindingCodec<Map<QName, Object>, Object> delegate;
522 @SuppressWarnings("rawtypes")
523 private final Map<Class, ChoiceCaseCodecImpl<?>> cases = new WeakHashMap<>();
525 private final CaseCompositeNodeMapFacade CompositeToCase;
527 public ChoiceCodecImpl(BindingCodec<Map<QName, Object>, Object> delegate) {
528 this.delegate = delegate;
529 this.CompositeToCase = new CaseCompositeNodeMapFacade(cases);
533 public ValueWithQName<T> deserialize(Node<?> input) {
534 throw new UnsupportedOperationException("Direct invocation of this codec is not allowed.");
538 public Node<?> serialize(ValueWithQName<T> input) {
539 throw new UnsupportedOperationException("Direct invocation of this codec is not allowed.");
542 public CaseCompositeNodeMapFacade getCompositeToCase() {
543 return CompositeToCase;
546 public Map<Class, ChoiceCaseCodecImpl<?>> getCases() {
550 public BindingCodec<Map<QName, Object>, Object> getDelegate() {
556 @SuppressWarnings("rawtypes")
557 private class CaseClassMapFacade extends MapFacadeBase {
560 public Set<java.util.Map.Entry<Class, BindingCodec<Object, Object>>> entrySet() {
565 public BindingCodec get(Object key) {
566 if (key instanceof Class) {
567 Class cls = (Class) key;
568 //bindingClassEncountered(cls);
569 ChoiceCaseCodecImpl caseCodec = getCaseCodecFor(cls);
570 return caseCodec.getDelegate();
576 @SuppressWarnings("rawtypes")
577 private static class CaseCompositeNodeMapFacade extends MapFacadeBase<CompositeNode> {
579 final Map<Class, ChoiceCaseCodecImpl<?>> choiceCases;
581 public CaseCompositeNodeMapFacade(Map<Class, ChoiceCaseCodecImpl<?>> choiceCases) {
582 this.choiceCases = choiceCases;
586 public BindingCodec get(Object key) {
587 if (false == (key instanceof CompositeNode)) {
590 for (java.util.Map.Entry<Class, ChoiceCaseCodecImpl<?>> entry : choiceCases.entrySet()) {
591 ChoiceCaseCodecImpl<?> codec = entry.getValue();
592 if (codec.isAcceptable((CompositeNode) key)) {
593 return codec.getDelegate();
603 * This map is used as only facade for {@link BindingCodec} in different
604 * classloaders to retrieve codec dynamicly based on provided key.
609 @SuppressWarnings("rawtypes")
610 private static abstract class MapFacadeBase<T> implements Map<T, BindingCodec<?, ?>> {
613 public boolean containsKey(Object key) {
614 return get(key) != null;
618 public void clear() {
619 throw notModifiable();
623 public boolean equals(Object obj) {
624 return super.equals(obj);
628 public BindingCodec remove(Object key) {
638 public Collection<BindingCodec<?, ?>> values() {
642 private UnsupportedOperationException notModifiable() {
643 return new UnsupportedOperationException("Not externally modifiable.");
647 public BindingCodec<Map<QName, Object>, Object> put(T key, BindingCodec<?,?> value) {
648 throw notModifiable();
652 public void putAll(Map<? extends T, ? extends BindingCodec<?, ?>> m) {
653 throw notModifiable();
657 public int hashCode() {
658 return super.hashCode();
662 public boolean isEmpty() {
667 public Set<T> keySet() {
672 public Set<java.util.Map.Entry<T, BindingCodec<?, ?>>> entrySet() {
673 // TODO Auto-generated method stub
678 public boolean containsValue(Object value) {
683 @SuppressWarnings({ "rawtypes", "unchecked" })
684 private class AugmentableCompositeCodec implements BindingCodec {
686 private final Class augmentableType;
688 Map<Class, BindingCodec> rawAugmentationCodecs = new WeakHashMap<>();
690 public AugmentableCompositeCodec(Class type) {
691 checkArgument(Augmentable.class.isAssignableFrom(type));
692 augmentableType = type;
696 public Object serialize(Object input) {
697 if (input instanceof Augmentable<?>) {
699 Map<Class, Augmentation> augmentations = getAugmentations(input);
700 return serializeImpl(augmentations);
705 private Map<Class, Augmentation> getAugmentations(Object input) {
706 Field augmentationField;
708 augmentationField = input.getClass().getDeclaredField("augmentation");
709 augmentationField.setAccessible(true);
710 Map<Class, Augmentation> augMap = (Map<Class, Augmentation>) augmentationField.get(input);
712 } catch (NoSuchFieldException e) {
714 } catch (SecurityException e) {
716 } catch (IllegalArgumentException e) {
718 } catch (IllegalAccessException e) {
721 return Collections.emptyMap();
724 private List serializeImpl(Map<Class, Augmentation> input) {
725 List ret = new ArrayList<>();
726 for (Entry<Class, Augmentation> entry : input.entrySet()) {
727 BindingCodec codec = getRawCodecForAugmentation(entry.getKey());
728 List output = (List) codec.serialize(new ValueWithQName(null, entry.getValue()));
734 private BindingCodec getRawCodecForAugmentation(Class key) {
735 BindingCodec ret = rawAugmentationCodecs.get(key);
740 Class<? extends BindingCodec> retClass = generator.augmentationTransformerFor(key);
741 ret = retClass.newInstance();
742 rawAugmentationCodecs.put(key, ret);
744 } catch (InstantiationException e) {
746 } catch (IllegalAccessException e) {
753 public Map<Class, Augmentation> deserialize(Object input) {
754 Map<Class, Augmentation> ret = new HashMap<>();
755 if (input instanceof CompositeNode) {
756 for (Entry<Class, BindingCodec> codec : rawAugmentationCodecs.entrySet()) {
757 Augmentation value = (Augmentation) codec.getValue().deserialize(input);
759 ret.put(codec.getKey(), value);
766 public Map<Class, BindingCodec> getRawAugmentationCodecs() {
767 return rawAugmentationCodecs;
770 public void setRawAugmentationCodecs(Map<Class, BindingCodec> rawAugmentationCodecs) {
771 this.rawAugmentationCodecs = rawAugmentationCodecs;
774 public Class getAugmentableType() {
775 return augmentableType;
779 @SuppressWarnings({ "rawtypes", "unchecked" })
780 private static class LateMixinCodec implements BindingCodec, Delegator<BindingCodec> {
782 private BindingCodec delegate;
785 public BindingCodec getDelegate() {
786 if (delegate == null) {
787 throw new IllegalStateException("Codec not initialized yet.");
793 public Object deserialize(Object input) {
794 return getDelegate().deserialize(input);
798 public Object serialize(Object input) {
799 return getDelegate().serialize(input);