- });
-
- private final LoadingCache<QName, DataContainerCodecContext<?,?>> childrenByQName = CacheBuilder.newBuilder().build(
- new CacheLoader<QName, DataContainerCodecContext<?,?>>() {
- @Override
- public DataContainerCodecContext<?,?> load(final QName qname) {
- final DataSchemaNode childSchema = getSchema().getDataChildByName(qname);
- childNonNull(childSchema, qname,"Argument %s is not valid child of %s", qname,getSchema());
- if (childSchema instanceof DataNodeContainer || childSchema instanceof ChoiceSchemaNode) {
- @SuppressWarnings("unchecked")
- final Class<? extends DataObject> childCls = (Class<? extends DataObject>)
- factory().getRuntimeContext().getClassForSchema(childSchema);
- return streamChild(childCls);
+
+ final CodecContextFactory factory = factory();
+ final BindingRuntimeContext context = factory.getRuntimeContext();
+
+ final QName qname = BindingReflections.findQName(key);
+ final QNameModule qnameModule = qname.getModule();
+ final Module module = context.getEffectiveModelContext().findModule(qnameModule)
+ .orElseThrow(() -> new IllegalArgumentException("Failed to find module for " + qnameModule));
+ final String className = BindingMapping.getClassName(qname);
+
+ for (final RpcDefinition potential : module.getRpcs()) {
+ final QName potentialQName = potential.getQName();
+ /*
+ * Check if rpc and class represents data from same module and then checks if rpc local name
+ * produces same class name as class name appended with Input/Output based on QName associated
+ * with binding class.
+ *
+ * FIXME: Rework this to have more precise logic regarding Binding Specification.
+ */
+ if (key.getSimpleName().equals(BindingMapping.getClassName(potentialQName) + className)) {
+ final ContainerLike schema = getRpcDataSchema(potential, qname);
+ checkArgument(schema != null, "Schema for %s does not define input / output.", potentialQName);
+
+ final ContainerLikeRuntimeType<?, ?> type = lookup.apply(context.getTypes(), potentialQName)
+ .orElseThrow(() -> new IllegalArgumentException("Cannot find runtime type for " + key));
+
+ return (ContainerNodeCodecContext) DataContainerCodecPrototype.from(key,
+ (ContainerLikeRuntimeType<?, ?>) type, factory).get();