Search in sources :

Example 1 with TypeObject

use of org.opendaylight.yangtools.yang.binding.TypeObject in project mdsal by opendaylight.

the class CachingNormalizedNodeSerializer method leafNode.

@Override
public void leafNode(final String localName, final Object value) throws IOException {
    if (value instanceof TypeObject) {
        // TypeObject is a tagging interface used for generated classes which wrap derived and restricted types.
        // They are immutable and hence we can safely wrap them in LeafNodes and reuse them, if directed to do so.
        final TypeObject typed = (TypeObject) value;
        final Class<? extends TypeObject> type = typed.getClass();
        if (cacheHolder.isCached(type)) {
            final ValueNodeCodecContext context = ((DataObjectCodecContext<?, ?>) delegate.current()).getLeafChild(localName);
            if (context instanceof OfTypeObject) {
                final AbstractBindingNormalizedNodeCache<TypeObject, ?> cache = cacheHolder.getCachingSerializer((OfTypeObject<?>) context);
                if (cache != null) {
                    // We have a cache hit and are thus done
                    domWriter.addChild(cache.get(typed));
                    return;
                }
                LOG.debug("Unexpected failure to acquire cache for context {}, skipping caching", context);
            } else {
                LOG.debug("Context {} does not match expected TypeObject {}, skipping caching", context, typed);
            }
        }
    }
    super.leafNode(localName, value);
}
Also used : OfTypeObject(org.opendaylight.mdsal.binding.dom.codec.impl.LeafNodeCodecContext.OfTypeObject) OfTypeObject(org.opendaylight.mdsal.binding.dom.codec.impl.LeafNodeCodecContext.OfTypeObject) TypeObject(org.opendaylight.yangtools.yang.binding.TypeObject)

Aggregations

OfTypeObject (org.opendaylight.mdsal.binding.dom.codec.impl.LeafNodeCodecContext.OfTypeObject)1 TypeObject (org.opendaylight.yangtools.yang.binding.TypeObject)1