/** * Returns RPC Input or Output Data container from RPC definition. * * @param schema SchemaContext in which lookup should be performed. * @param path Schema path of RPC input/output data container * @return Notification schema or null, if notification is not present in schema context. */ @Beta public static @Nullable ContainerSchemaNode getRpcDataSchema(final @NonNull SchemaContext schema, final @NonNull SchemaPath path) { requireNonNull(schema, "Schema context must not be null."); requireNonNull(path, "Schema path must not be null."); final Iterator<QName> it = path.getPathFromRoot().iterator(); checkArgument(it.hasNext(), "Rpc must have QName."); final QName rpcName = it.next(); checkArgument(it.hasNext(), "input or output must be part of path."); final QName inOrOut = it.next(); for (final RpcDefinition potential : schema.getOperations()) { if (rpcName.equals(potential.getQName())) { return SchemaNodeUtils.getRpcDataSchema(potential, inOrOut); } } return null; }
/** * Returns RPC Input or Output Data container from RPC definition. * * @param schema SchemaContext in which lookup should be performed. * @param path Schema path of RPC input/output data container * @return Notification schema or null, if notification is not present in schema context. */ @Beta public static @Nullable ContainerSchemaNode getRpcDataSchema(final @NonNull SchemaContext schema, final @NonNull SchemaPath path) { requireNonNull(schema, "Schema context must not be null."); requireNonNull(path, "Schema path must not be null."); final Iterator<QName> it = path.getPathFromRoot().iterator(); checkArgument(it.hasNext(), "Rpc must have QName."); final QName rpcName = it.next(); checkArgument(it.hasNext(), "input or output must be part of path."); final QName inOrOut = it.next(); for (final RpcDefinition potential : schema.getOperations()) { if (rpcName.equals(potential.getQName())) { return SchemaNodeUtils.getRpcDataSchema(potential, inOrOut); } } return null; }
ContainerNodeCodecContext<?> createRpcDataContext(final Class<?> key) { checkArgument(DataContainer.class.isAssignableFrom(key)); final QName qname = BindingReflections.findQName(key); final QNameModule qnameModule = qname.getModule(); final Module module = getSchema().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 ContainerSchemaNode schema = SchemaNodeUtils.getRpcDataSchema(potential, qname); checkArgument(schema != null, "Schema for %s does not define input / output.", potential.getQName()); return (ContainerNodeCodecContext<?>) DataContainerCodecPrototype.from(key, schema, factory()).get(); } } throw new IllegalArgumentException("Supplied class " + key + " is not valid RPC class."); }