X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=code-generator%2Fbinding-data-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fbinding%2Fdata%2Fcodec%2Fimpl%2FSchemaRootCodecContext.java;h=681b7906ed06a359b5d232013e833e1ed95ac5c3;hb=9e5540fb30986583d69e51f9290dbb651338f4b0;hp=9460bf2a173c8e0af046125b0e8608a83a9d0687;hpb=2719da7f1a121b999310aa1e075872e1a1d8d196;p=yangtools.git diff --git a/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/SchemaRootCodecContext.java b/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/SchemaRootCodecContext.java index 9460bf2a17..681b7906ed 100644 --- a/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/SchemaRootCodecContext.java +++ b/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/SchemaRootCodecContext.java @@ -16,6 +16,7 @@ import org.opendaylight.yangtools.util.ClassLoaderUtils; import org.opendaylight.yangtools.yang.binding.BindingMapping; import org.opendaylight.yangtools.yang.binding.ChildOf; import org.opendaylight.yangtools.yang.binding.DataContainer; +import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.DataRoot; import org.opendaylight.yangtools.yang.binding.Notification; import org.opendaylight.yangtools.yang.binding.util.BindingReflections; @@ -34,52 +35,54 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils; -final class SchemaRootCodecContext extends DataContainerCodecContext { +final class SchemaRootCodecContext extends DataContainerCodecContext { - private final LoadingCache, DataContainerCodecContext> childrenByClass = CacheBuilder.newBuilder() - .build(new CacheLoader, DataContainerCodecContext>() { + private final LoadingCache, DataContainerCodecContext> childrenByClass = CacheBuilder.newBuilder() + .build(new CacheLoader, DataContainerCodecContext>() { @Override - public DataContainerCodecContext load(final Class key) { + public DataContainerCodecContext load(final Class key) { return createDataTreeChildContext(key); } }); - private final LoadingCache, ContainerNodeCodecContext> rpcDataByClass = CacheBuilder.newBuilder().build( - new CacheLoader, ContainerNodeCodecContext>() { + private final LoadingCache, ContainerNodeCodecContext> rpcDataByClass = CacheBuilder.newBuilder().build( + new CacheLoader, ContainerNodeCodecContext>() { @Override - public ContainerNodeCodecContext load(final Class key) { + public ContainerNodeCodecContext load(final Class key) { return createRpcDataContext(key); } }); - private final LoadingCache, NotificationCodecContext> notificationsByClass = CacheBuilder.newBuilder() - .build(new CacheLoader, NotificationCodecContext>() { + private final LoadingCache, NotificationCodecContext> notificationsByClass = CacheBuilder.newBuilder() + .build(new CacheLoader, NotificationCodecContext>() { @Override - public NotificationCodecContext load(final Class key) { + public NotificationCodecContext load(final Class key) { return createNotificationDataContext(key); } }); - private final LoadingCache> childrenByQName = CacheBuilder.newBuilder().build( - new CacheLoader>() { + private final LoadingCache> childrenByQName = CacheBuilder.newBuilder().build( + new CacheLoader>() { + @SuppressWarnings("unchecked") @Override - public DataContainerCodecContext load(final QName qname) { + public DataContainerCodecContext load(final QName qname) { final DataSchemaNode childSchema = schema().getDataChildByName(qname); Preconditions.checkArgument(childSchema != null, "Argument %s is not valid child of %s", qname, schema()); if (childSchema instanceof DataNodeContainer || childSchema instanceof ChoiceSchemaNode) { - final Class childCls = factory().getRuntimeContext().getClassForSchema(childSchema); - return getStreamChild(childCls); + @SuppressWarnings("rawtypes") + final Class childCls = factory().getRuntimeContext().getClassForSchema(childSchema); + return streamChild(childCls); } else { throw new UnsupportedOperationException("Unsupported child type " + childSchema.getClass()); } } }); - private final LoadingCache rpcDataByPath = CacheBuilder.newBuilder().build( - new CacheLoader() { + private final LoadingCache> rpcDataByPath = CacheBuilder.newBuilder().build( + new CacheLoader>() { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override @@ -90,8 +93,8 @@ final class SchemaRootCodecContext extends DataContainerCodecContext notificationsByPath = CacheBuilder.newBuilder() - .build(new CacheLoader() { + private final LoadingCache> notificationsByPath = CacheBuilder.newBuilder() + .build(new CacheLoader>() { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override @@ -113,48 +116,53 @@ final class SchemaRootCodecContext extends DataContainerCodecContext create(final CodecContextFactory factory) { final DataContainerCodecPrototype prototype = DataContainerCodecPrototype.rootPrototype(factory); - return new SchemaRootCodecContext(prototype); + return new SchemaRootCodecContext<>(prototype); } + + @SuppressWarnings("unchecked") @Override - protected DataContainerCodecContext getStreamChild(final Class childClass) { - return childrenByClass.getUnchecked(childClass); + public DataContainerCodecContext streamChild(Class childClass) + throws IllegalArgumentException { + return (DataContainerCodecContext) childrenByClass.getUnchecked(childClass); } @Override - protected Optional> getPossibleStreamChild(final Class childClass) { + public Optional> possibleStreamChild(final Class childClass) { throw new UnsupportedOperationException("Not supported"); } @Override - protected NodeCodecContext getYangIdentifierChild(final PathArgument arg) { + public DataContainerCodecContext yangPathArgumentChild(final PathArgument arg) { return childrenByQName.getUnchecked(arg.getNodeType()); } @Override - protected Object dataFromNormalizedNode(final NormalizedNode normalizedNode) { - throw new UnsupportedOperationException("Could not create Binding data representation for root"); + public D deserialize(final NormalizedNode normalizedNode) { + throw new UnsupportedOperationException( + "Could not create Binding data representation for root"); } - ContainerNodeCodecContext getRpc(final Class rpcInputOrOutput) { + + ContainerNodeCodecContext getRpc(final Class rpcInputOrOutput) { return rpcDataByClass.getUnchecked(rpcInputOrOutput); } - NotificationCodecContext getNotification(final Class notification) { + NotificationCodecContext getNotification(final Class notification) { return notificationsByClass.getUnchecked(notification); } - NotificationCodecContext getNotification(final SchemaPath notification) { + NotificationCodecContext getNotification(final SchemaPath notification) { return notificationsByPath.getUnchecked(notification); } - ContainerNodeCodecContext getRpc(final SchemaPath notification) { + ContainerNodeCodecContext getRpc(final SchemaPath notification) { return rpcDataByPath.getUnchecked(notification); } - private DataContainerCodecContext createDataTreeChildContext(final Class key) { + private DataContainerCodecContext createDataTreeChildContext(final Class key) { final Class parent = ClassLoaderUtils.findFirstGenericArgument(key, ChildOf.class); Preconditions.checkArgument(DataRoot.class.isAssignableFrom(parent)); final QName qname = BindingReflections.findQName(key); @@ -162,7 +170,7 @@ final class SchemaRootCodecContext extends DataContainerCodecContext key) { + private ContainerNodeCodecContext createRpcDataContext(final Class key) { Preconditions.checkArgument(DataContainer.class.isAssignableFrom(key)); final QName qname = BindingReflections.findQName(key); final QNameModule module = qname.getModule(); @@ -189,10 +197,10 @@ final class SchemaRootCodecContext extends DataContainerCodecContext) DataContainerCodecPrototype.from(key, schema, factory()).get(); } - private NotificationCodecContext createNotificationDataContext(final Class notificationType) { + private NotificationCodecContext createNotificationDataContext(final Class notificationType) { Preconditions.checkArgument(Notification.class.isAssignableFrom(notificationType)); Preconditions.checkArgument(notificationType.isInterface(), "Supplied class must be interface."); final QName qname = BindingReflections.findQName(notificationType); @@ -204,7 +212,12 @@ final class SchemaRootCodecContext extends DataContainerCodecContext(notificationType, schema, factory()); + } + + @Override + protected Object deserializeObject(NormalizedNode normalizedNode) { + throw new UnsupportedOperationException("Unable to deserialize root"); } } \ No newline at end of file