- /**
- * Prepare codec for type from leaf's return type of leafref.
- *
- * @param unionCls
- * - union class
- * @param unionType
- * - union type
- * @param bindingCodecContext
- * - binding codec context
- * @param values
- * - union values
- * @param subtype
- * - subtype of union
- * @throws NoSuchMethodException when the getter method is not found
- */
- private static void addLeafrefValueCodec(final Class<?> unionCls, final UnionTypeDefinition unionType,
- final BindingCodecContext bindingCodecContext, final Set<UnionValueOptionContext> values,
- final TypeDefinition<?> subtype) throws NoSuchMethodException {
- final EffectiveModelContext schemaContext = bindingCodecContext.getRuntimeContext().getEffectiveModelContext();
- final Module module = schemaContext.findModule(subtype.getQName().getModule()).get();
- final PathExpression xpath = ((LeafrefTypeDefinition) subtype).getPathStatement();
- // find schema node in schema context by xpath of leafref
- final SchemaNode dataNode;
- if (xpath.isAbsolute()) {
- dataNode = SchemaContextUtil.findDataSchemaNode(schemaContext, module, xpath);
- } else {
- dataNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, module, unionType, xpath);