Search in sources :

Example 1 with EndpointNode

use of org.ballerinalang.model.tree.EndpointNode in project ballerina by ballerina-lang.

the class ClientContextHolder method buildContext.

/**
 * Build a parsable context from a Ballerina {@link ServiceNode}.
 *
 * @param service   {@code ServiceNode} for a valid ballerina source file
 * @param endpoints list of endpoints to be used as service endpoints for generated client
 * @return A parsable data model for provided ballerina {@code service}
 */
public static ClientContextHolder buildContext(ServiceNode service, List<EndpointNode> endpoints) throws CodeGeneratorException {
    ClientContextHolder context = new ClientContextHolder();
    context.name = service.getName().getValue();
    context.resources = new ArrayList<>();
    context.endpoints = new ArrayList<>();
    // Extract bound endpoint details
    for (EndpointNode ep : endpoints) {
        EndpointContextHolder epContext = EndpointContextHolder.buildContext(service, ep);
        if (epContext != null) {
            context.endpoints.add(EndpointContextHolder.buildContext(service, ep));
        }
    }
    // Extract ballerina resource nodes as parsable resources
    for (ResourceNode resource : service.getResources()) {
        ResourceContextHolder operation = ResourceContextHolder.buildContext(resource);
        context.resources.add(operation);
    }
    return context;
}
Also used : EndpointNode(org.ballerinalang.model.tree.EndpointNode) ResourceNode(org.ballerinalang.model.tree.ResourceNode)

Aggregations

EndpointNode (org.ballerinalang.model.tree.EndpointNode)1 ResourceNode (org.ballerinalang.model.tree.ResourceNode)1