X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-path-parser%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Fcpspath%2Fparser%2FCpsPathBuilder.java;h=ebf6fd3c91fd4909b29bfd3450aa9343111321ae;hb=f0527c58c17963d940535d0ce0eb934c2b4c635c;hp=b9d0c25b13bfade570859bd0d47e6de04ab77129;hpb=6355b212de77e658b16614eb775f03c7713c8460;p=cps.git diff --git a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java index b9d0c25b1..ebf6fd3c9 100644 --- a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java +++ b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java @@ -20,18 +20,18 @@ package org.onap.cps.cpspath.parser; +import static org.onap.cps.cpspath.parser.CpsPathPrefixType.DESCENDANT; + import java.util.HashMap; import java.util.Map; import org.onap.cps.cpspath.parser.antlr4.CpsPathBaseListener; import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.AncestorAxisContext; -import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.CpsPathWithDescendantAndLeafConditionsContext; -import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.CpsPathWithDescendantContext; -import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.CpsPathWithSingleLeafConditionContext; +import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.DescendantContext; +import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.IncorrectPrefixContext; import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.LeafConditionContext; -import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.MultipleValueConditionsContext; -import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.PostfixContext; +import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.MultipleLeafConditionsContext; import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.PrefixContext; -import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.SingleValueConditionContext; +import org.onap.cps.cpspath.parser.antlr4.CpsPathParser.TextFunctionConditionContext; public class CpsPathBuilder extends CpsPathBaseListener { @@ -45,8 +45,8 @@ public class CpsPathBuilder extends CpsPathBaseListener { } @Override - public void exitPostfix(final PostfixContext ctx) { - throw new IllegalStateException(String.format("Unsupported postfix %s encountered in CpsPath.", ctx.getText())); + public void exitIncorrectPrefix(final IncorrectPrefixContext ctx) { + throw new IllegalStateException("CPS path can only start with one or two slashes (/)"); } @Override @@ -64,38 +64,18 @@ public class CpsPathBuilder extends CpsPathBaseListener { } @Override - public void enterSingleValueCondition(final SingleValueConditionContext ctx) { - leavesData.clear(); + public void exitDescendant(final DescendantContext ctx) { + cpsPathQuery.setCpsPathPrefixType(DESCENDANT); + cpsPathQuery.setDescendantName(ctx.getText().substring(2)); } @Override - public void enterMultipleValueConditions(final MultipleValueConditionsContext ctx) { + public void enterMultipleLeafConditions(final MultipleLeafConditionsContext ctx) { leavesData.clear(); } @Override - public void exitSingleValueCondition(final SingleValueConditionContext ctx) { - final String leafName = ctx.leafCondition().leafName().getText(); - cpsPathQuery.setLeafName(leafName); - cpsPathQuery.setLeafValue(leavesData.get(leafName)); - } - - @Override - public void exitCpsPathWithSingleLeafCondition(final CpsPathWithSingleLeafConditionContext ctx) { - cpsPathQuery.setCpsPathQueryType(CpsPathQueryType.XPATH_LEAF_VALUE); - } - - @Override - public void exitCpsPathWithDescendant(final CpsPathWithDescendantContext ctx) { - cpsPathQuery.setCpsPathQueryType(CpsPathQueryType.XPATH_HAS_DESCENDANT_ANYWHERE); - cpsPathQuery.setDescendantName(cpsPathQuery.getXpathPrefix().substring(1)); - } - - @Override - public void exitCpsPathWithDescendantAndLeafConditions( - final CpsPathWithDescendantAndLeafConditionsContext ctx) { - cpsPathQuery.setCpsPathQueryType(CpsPathQueryType.XPATH_HAS_DESCENDANT_WITH_LEAF_VALUES); - cpsPathQuery.setDescendantName(cpsPathQuery.getXpathPrefix().substring(1)); + public void exitMultipleLeafConditions(final MultipleLeafConditionsContext ctx) { cpsPathQuery.setLeavesData(leavesData); } @@ -104,6 +84,12 @@ public class CpsPathBuilder extends CpsPathBaseListener { cpsPathQuery.setAncestorSchemaNodeIdentifier(ctx.ancestorPath().getText()); } + @Override + public void exitTextFunctionCondition(final TextFunctionConditionContext ctx) { + cpsPathQuery.setTextFunctionConditionLeafName(ctx.leafName().getText()); + cpsPathQuery.setTextFunctionConditionValue(stripFirstAndLastCharacter(ctx.StringLiteral().getText())); + } + CpsPathQuery build() { return cpsPathQuery; }