/** * Returns operation Input or Output Data container from operation definition. * * @param schema * - SchemaContext in which lookup should be performed * @param path * - Schema path of operation input/output data container * @return operation schema or null, if operation is not present in schema context. */ private ContainerSchemaNode getOperationDataSchema(final SchemaContext schema, final SchemaPath path) { Preconditions.checkNotNull(schema, "Schema context must not be null."); Preconditions.checkNotNull(path, "Schema path must not be null."); final Iterator<QName> it = path.getPathFromRoot().iterator(); Preconditions.checkArgument(it.hasNext(), "Operation must have QName."); final QName operationName = it.next(); Preconditions.checkArgument(it.hasNext(), "input or output must be part of path."); final QName inOrOut = it.next(); ContainerSchemaNode contSchemaNode = null; if ((contSchemaNode = getOperationDataSchema(schema.getOperations(), operationName, inOrOut)) == null) { contSchemaNode = getOperationDataSchema(schema.getActions(), operationName, inOrOut); } return contSchemaNode; }
private static Optional<DataNodeContainer> findFirstDataNodeContainerInRpcOrAction(final SchemaContext ctx, final Class<? extends TreeNode> targetType) { final YangModuleInfo moduleInfo; try { moduleInfo = BindingReflections.getModuleInfo(targetType); } catch (final Exception e) { throw new IllegalArgumentException( String.format("Failed to load module information for class %s", targetType), e); } Optional<DataNodeContainer> optional = null; optional = findFirst(ctx.getOperations(), moduleInfo, targetType); if (optional.isPresent()) { return optional; } else { return findFirst(ctx.getActions(), moduleInfo, targetType); } }
private ContainerNodeCodecContext<?> createOperationDataContext(final Class<?> key) { Preconditions.checkArgument(Instantiable.class.isAssignableFrom(key)); final QName qname = BindingReflections.findQName(key); final QNameModule module = qname.getModule(); OperationDefinition operation = null; final SchemaContext schemaContext = getSchema(); if ((operation = findPotentialOperation(schemaContext.getOperations(), module, key, qname)) == null) { operation = findPotentialOperation(schemaContext.getActions(), module, key, qname); } Preconditions.checkArgument(operation != null, "Supplied class %s is not valid operation class.", key); final ContainerSchemaNode schema = getOperationDataSchema(operation, qname);// SchemaNodeUtils // .getRpcDataSchema(operation, qname); Preconditions.checkArgument(schema != null, "Schema for %s does not define input / output.", operation.getQName()); return (ContainerNodeCodecContext<?>) DataContainerCodecPrototype.from(key, schema, factory()).get(); }
/** * Resolve method with definition of specific action as binding object. * * @param key * - action as binding object * @return map of method with definition of specific action */ public ImmutableBiMap<Method, OperationDefinition> getActionMethodToSchema(final Class<?> key) { final Module module = getModuleBlocking(key); final ImmutableBiMap.Builder<Method, OperationDefinition> ret = ImmutableBiMap.builder(); try { for (final ActionDefinition actionDefinition : runtimeContext.getSchemaContext().getActions()) { final QName qName = actionDefinition.getQName(); if (qName.getModule().equals(module.getQNameModule())) { final Method method = runtimeContext.findOperationMethod(key, actionDefinition); ret.put(method, actionDefinition); } } } catch (final NoSuchMethodException e) { throw new IllegalStateException("Action defined in model does not have representation in generated class.", e); } return ret.build(); }