Search in sources :

Example 1 with InboundContext

use of com.linkedin.restli.client.config.RequestConfigKeyParser.InboundContext in project parseq by linkedin.

the class RequestConfigElement method parse.

static RequestConfigElement parse(String property, String key, Object value) throws RequestConfigKeyParsingException {
    RequestConfigKeyParsingErrorListener errorListener = new RequestConfigKeyParsingErrorListener();
    ANTLRInputStream input = new ANTLRInputStream(key);
    RequestConfigKeyLexer lexer = new RequestConfigKeyLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(errorListener);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    RequestConfigKeyParser parser = new RequestConfigKeyParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(errorListener);
    KeyContext keyTree = parser.key();
    if (!errorListener.hasErrors()) {
        InboundContext inbound = keyTree.inbound();
        OutboundContext outbound = keyTree.outbound();
        Optional<String> inboundName = handlingWildcard(inbound.restResource());
        Optional<String> outboundName = handlingWildcard(outbound.restResource());
        Optional<String> inboundOp = getOpIn(inbound.operationIn());
        Optional<ResourceMethod> outboundOp = getOpOut(outbound.operationOut());
        Optional<String> inboundOpName = inboundOp.flatMap(method -> getOpInName(method, inbound.operationIn()));
        Optional<String> outboundOpName = outboundOp.flatMap(method -> getOpOutName(method, outbound.operationOut()));
        return new RequestConfigElement(key, coerceValue(property, value), property, inboundName, outboundName, inboundOpName, outboundOpName, inboundOp, outboundOp);
    } else {
        throw new RequestConfigKeyParsingException("Error" + ((errorListener.errorsSize() > 1) ? "s" : "") + " parsing key: " + key + "\n" + errorListener);
    }
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) InboundContext(com.linkedin.restli.client.config.RequestConfigKeyParser.InboundContext) OutboundContext(com.linkedin.restli.client.config.RequestConfigKeyParser.OutboundContext) KeyContext(com.linkedin.restli.client.config.RequestConfigKeyParser.KeyContext) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Aggregations

InboundContext (com.linkedin.restli.client.config.RequestConfigKeyParser.InboundContext)1 KeyContext (com.linkedin.restli.client.config.RequestConfigKeyParser.KeyContext)1 OutboundContext (com.linkedin.restli.client.config.RequestConfigKeyParser.OutboundContext)1 ResourceMethod (com.linkedin.restli.common.ResourceMethod)1 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1