- public DataContainerCodecContext<?> load(final Class<?> key) {
- Class<Object> parent = ClassLoaderUtils.findFirstGenericArgument(key, ChildOf.class);
- Preconditions.checkArgument(DataRoot.class.isAssignableFrom(parent));
- QName qname = BindingReflections.findQName(key);
- DataSchemaNode childSchema = schema().getDataChildByName(qname);
- return DataContainerCodecPrototype.from(key, childSchema, factory()).get();
+ public DataContainerCodecContext<?,?> load(final Class<?> key) {
+ return createDataTreeChildContext(key);
+ }
+
+ });
+
+ private final LoadingCache<Class<?>, ContainerNodeCodecContext<?>> rpcDataByClass = CacheBuilder.newBuilder().build(
+ new CacheLoader<Class<?>, ContainerNodeCodecContext<?>>() {
+ @Override
+ public ContainerNodeCodecContext<?> load(final Class<?> key) {
+ return createRpcDataContext(key);
+ }
+ });
+
+ private final LoadingCache<Class<?>, NotificationCodecContext<?>> notificationsByClass = CacheBuilder.newBuilder()
+ .build(new CacheLoader<Class<?>, NotificationCodecContext<?>>() {
+ @Override
+ public NotificationCodecContext<?> load(final Class<?> key) {
+ return createNotificationDataContext(key);
+ }
+ });
+
+ private final LoadingCache<QName, DataContainerCodecContext<?,?>> childrenByQName = CacheBuilder.newBuilder().build(
+ new CacheLoader<QName, DataContainerCodecContext<?,?>>() {
+ @SuppressWarnings("unchecked")
+ @Override
+ public DataContainerCodecContext<?,?> load(final QName qname) {
+ final DataSchemaNode childSchema = schema().getDataChildByName(qname);
+ childNonNull(childSchema, qname,"Argument %s is not valid child of %s", qname,schema());
+ if (childSchema instanceof DataNodeContainer || childSchema instanceof ChoiceSchemaNode) {
+ @SuppressWarnings("rawtypes")
+ final Class childCls = factory().getRuntimeContext().getClassForSchema(childSchema);
+ return streamChild(childCls);
+ } else {
+ throw new UnsupportedOperationException("Unsupported child type " + childSchema.getClass());
+ }
+ }
+ });
+
+ private final LoadingCache<SchemaPath, ContainerNodeCodecContext<?>> rpcDataByPath = CacheBuilder.newBuilder().build(
+ new CacheLoader<SchemaPath, ContainerNodeCodecContext<?>>() {
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public ContainerNodeCodecContext load(final SchemaPath key) {
+ final ContainerSchemaNode schema = SchemaContextUtil.getRpcDataSchema(schema(), key);
+ final Class cls = factory().getRuntimeContext().getClassForSchema(schema);
+ return getRpc(cls);
+ }
+ });
+
+ private final LoadingCache<SchemaPath, NotificationCodecContext<?>> notificationsByPath = CacheBuilder.newBuilder()
+ .build(new CacheLoader<SchemaPath, NotificationCodecContext<?>>() {
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public NotificationCodecContext load(final SchemaPath key) throws Exception {
+ final NotificationDefinition schema = SchemaContextUtil.getNotificationSchema(schema(), key);
+ final Class clz = factory().getRuntimeContext().getClassForSchema(schema);
+ return getNotification(clz);