protected void buildInterpreter() { RuleStore rs = new SimpleRuleStore(context); addInstanceRules(rs); this.interpreter = new Interpreter(context, rs, initialElementPath()); InterpretationContext interpretationContext = interpreter.getInterpretationContext(); interpretationContext.setContext(context); addImplicitRules(interpreter); addDefaultNestedComponentRegistryRules(interpretationContext.getDefaultNestedComponentRegistry()); }
public void addRule(ElementSelector elementSelector, String actionClassName) { Action action = null; try { action = (Action) OptionHelper.instantiateByClassName(actionClassName, Action.class, context); } catch (Exception e) { addError("Could not instantiate class [" + actionClassName + "]", e); } if (action != null) { addRule(elementSelector, action); } }
public List<Action> matchActions(ElementPath elementPath) { List<Action> actionList; if ((actionList = fullPathMatch(elementPath)) != null) { return actionList; } else if ((actionList = suffixMatch(elementPath)) != null) { return actionList; } else if ((actionList = prefixMatch(elementPath)) != null) { return actionList; } else if ((actionList = middleMatch(elementPath)) != null) { return actionList; } else { return null; } }
@Test public void testSlashSuffix() throws Exception { ElementSelector pa = new ElementSelector("a/"); srs.addRule(pa, new XAction()); for (String s : cc.combinations("a")) { List<Action> r = srs.matchActions(new ElementPath(s)); assertNotNull(r); assertEquals(1, r.size()); if (!(r.get(0) instanceof XAction)) { fail("Wrong type"); } } }
public List matchActions(Pattern currentPattern) { List actionList; if ((actionList = rules.get(currentPattern)) != null) { return actionList; } else if ((actionList = tailMatch(currentPattern)) != null) { return actionList; } else if ((actionList = prefixMatch(currentPattern)) != null) { return actionList; } else if ((actionList = middleMatch(currentPattern)) != null) { return actionList; } else { return null; } }
public SimpleRuleStore(Context context) { setContext(context); }
@Test public void testTail2() throws Exception { SimpleRuleStore srs = new SimpleRuleStore(new ContextBase()); srs.addRule(new ElementSelector("*/c"), new XAction()); for (String s : cc.combinations("a/b/c")) { List<Action> r = srs.matchActions(new ElementPath(s)); assertNotNull(r); assertEquals(1, r.size()); if (!(r.get(0) instanceof XAction)) { fail("Wrong type"); } } }
List<Action> prefixMatch(ElementPath elementPath) { int max = 0; ElementSelector longestMatchingElementSelector = null; for (ElementSelector selector : rules.keySet()) { String last = selector.peekLast(); if (isKleeneStar(last)) { int r = selector.getPrefixMatchLength(elementPath); // to qualify the match length must equal p's size omitting the '*' if ((r == selector.size() - 1) && (r > max)) { max = r; longestMatchingElementSelector = selector; } } } if (longestMatchingElementSelector != null) { return rules.get(longestMatchingElementSelector); } else { return null; } }
public List matchActions(Pattern currentPattern) { List actionList; if ((actionList = rules.get(currentPattern)) != null) { return actionList; } else if ((actionList = tailMatch(currentPattern)) != null) { return actionList; } else if ((actionList = prefixMatch(currentPattern)) != null) { // System.out.println(currentPattern + " prefixMatches "+actionList); return actionList; } else { return null; } }
List<Action> suffixMatch(ElementPath elementPath) { int max = 0; ElementSelector longestMatchingElementSelector = null; for (ElementSelector selector : rules.keySet()) { if (isSuffixPattern(selector)) { int r = selector.getTailMatchLength(elementPath); if (r > max) { max = r; longestMatchingElementSelector = selector; } } } if (longestMatchingElementSelector != null) { return rules.get(longestMatchingElementSelector); } else { return null; } }
@Test public void smoke() throws Exception { srs.addRule(new ElementSelector("a/b"), new XAction()); // test for all possible case combinations of "a/b" for (String s : cc.combinations("a/b")) { List<Action> r = srs.matchActions(new ElementPath(s)); assertNotNull(r); assertEquals(1, r.size()); if (!(r.get(0) instanceof XAction)) { fail("Wrong type"); } } }
public List matchActions(Pattern currentPattern) { List actionList; if ((actionList = rules.get(currentPattern)) != null) { return actionList; } else if ((actionList = tailMatch(currentPattern)) != null) { return actionList; } else if ((actionList = prefixMatch(currentPattern)) != null) { return actionList; } else if ((actionList = middleMatch(currentPattern)) != null) { return actionList; } else { return null; } }
public SimpleRuleStore(Context context) { setContext(context); }
first = selector.get(0); if (isKleeneStar(last) && isKleeneStar(first)) { List<String> copyOfPartList = selector.getCopyOfPartList(); if(copyOfPartList.size() > 2) {
List<Action> suffixMatch(ElementPath elementPath) { int max = 0; ElementSelector longestMatchingElementSelector = null; for (ElementSelector selector : rules.keySet()) { if (isSuffixPattern(selector)) { int r = selector.getTailMatchLength(elementPath); if (r > max) { max = r; longestMatchingElementSelector = selector; } } } if (longestMatchingElementSelector != null) { return rules.get(longestMatchingElementSelector); } else { return null; } }
public List<Action> matchActions(ElementPath elementPath) { List<Action> actionList; if ((actionList = fullPathMatch(elementPath)) != null) { return actionList; } else if ((actionList = suffixMatch(elementPath)) != null) { return actionList; } else if ((actionList = prefixMatch(elementPath)) != null) { return actionList; } else if ((actionList = middleMatch(elementPath)) != null) { return actionList; } else { return null; } }
public void addRule(ElementSelector elementSelector, String actionClassName) { Action action = null; try { action = (Action) OptionHelper.instantiateByClassName(actionClassName, Action.class, context); } catch (Exception e) { addError("Could not instantiate class [" + actionClassName + "]", e); } if (action != null) { addRule(elementSelector, action); } }
@Test public void testTail1() throws Exception { srs.addRule(new ElementSelector("*/b"), new XAction()); for (String s : cc.combinations("a/b")) { List<Action> r = srs.matchActions(new ElementPath(s)); assertNotNull(r); assertEquals(1, r.size()); if (!(r.get(0) instanceof XAction)) { fail("Wrong type"); } } }
/** * Builds a generic configuration-XML interpreter */ protected void buildInterpreter() { RuleStore rs = new SimpleRuleStore(context); addInstanceRules(rs); this.interpreter = new Interpreter(context, rs, initialElementPath()); InterpretationContext interpretationContext = interpreter.getInterpretationContext(); interpretationContext.setContext(context); addImplicitRules(interpreter); addDefaultNestedComponentRegistryRules(interpretationContext.getDefaultNestedComponentRegistry()); }
public SimpleRuleStore(Context context) { setContext(context); }