Package net.sourceforge.temply.base.rules

Examples of net.sourceforge.temply.base.rules.Rule


        _repo = project.getRepository();
    }

    @Test
    public void test() throws Exception {
        Rule sqlServer = _repo.getRule("SqlServer");
        assertNotNull(sqlServer);
        Rule connection = _repo.getRule("Connection");
        assertNotNull(connection);

        Rule sqlServerDev = _repo.getRule("SqlServer.Dev");
        assertNotNull(sqlServerDev);
    }
View Full Code Here


        DirectedGraph<Rule, DefaultEdge> graph = getGraph(project);
       
        Set<DefaultEdge> edges = graph.incomingEdgesOf(project.getRepository().getRule("Oracle"));
        for (DefaultEdge edge : edges) {
            Rule source = graph.getEdgeSource(edge);
            System.out.print(source + " = ");
//            System.out.println(graph.inDegreeOf(source));
//            System.out.println(countPointedTo(graph, source));
        }
       
View Full Code Here

        }
       
    }
   
    private Rule getRule(XMLRule xmlRule) {
        Rule rule = _rules.get(xmlRule.getName());
        if (rule == null) {
            rule = new Rule(xmlRule.getName(), xmlRule.getCategory());
           
            if (xmlRule.getExtends() != null) {
                for (String anchestorName : xmlRule.getExtends().split(",")) {
                    Rule anchestor = getRule(_xmlRules.get(anchestorName));
                    for (Var var : anchestor.getVars()) {
                        rule.add(var);
                    }
                    for (Resolve resolve : anchestor.getResolves()) {
                        rule.add(new Resolve(rule, resolve.getRule(), resolve.getCategory(), resolve.getVar(), resolve.getValue()));
                    }
                    for (RuleValidator validator : anchestor.getValidators()) {
                        rule.add(validator);
                    }
                }
            }
           
            for (XMLVar xmlVar : xmlRule.getXMLVar()) {
                rule.add(new Var(xmlVar.getName(), VarType.valueOf(xmlVar
                        .getType().toString()), xmlVar.getDefault()));
            }
           
            for (XMLResolve xmlResolve : xmlRule.getXMLResolve()) {
                Rule varRule = getRule(_xmlRules.get(xmlResolve.getRule()));
                if (varRule == null) {
                    log.error("Unknown rule " + xmlResolve.getRule()
                            + " referred in " + rule);
                    continue;
                }
                Var var = varRule.getVar(xmlResolve.getVar());
                if (var == null) {
                    log.error("Unknown var " + xmlResolve.getVar()
                            + " in rule " + xmlResolve.getRule()
                            + " referred in " + rule);
                    continue;
View Full Code Here

        _functionFinder = new TemplyFunctionFinder();
        addAll();
    }

    public void add(String ruleName) {
        Rule rule = _project.getRepository().getRule(ruleName);
        if (rule == null) {
            throw new RuntimeException("Cannot find rule " + ruleName);
        }
        add(rule);
    }
View Full Code Here

     * @param ruleName
     * @param category
     * @return key=rule var name, value=value
     */
    public Map<String, String> resolve(String ruleName, String category) {
        Rule rule = _project.getRepository().getRule(ruleName);
        if (rule == null) {
            throw new IllegalArgumentException("Cannot find rule " + ruleName);
        }
        String categorizedRule = ruleName + (category == null ? "" : "(" + category + ")");
        Map<String, String> result = new HashMap<String, String>();
        for (Var var : rule.getVars()) {
            try {
                result.put(var.getName(), resolve("$temply{" + categorizedRule + ":" + var.getName() + "}"));
            } catch (NoPathException e) {
                throw new RuntimeException("Cannot find a valid path to resolve " + categorizedRule + ":" + var.getName());
            }
View Full Code Here

    }
   
    public Collection<RuleSolution> resolveAllPaths(String ruleName, String category) {
        // I don't want duplicates so the HashSet
        Collection<RuleSolution> result = new HashSet<RuleSolution>();
        Rule rule = _project.getRepository().getRule(ruleName);
        if (rule == null) {
            throw new IllegalArgumentException("Cannot find rule " + ruleName);
        }
        String categorizedRule = ruleName + (category == null ? "" : "(" + category + ")");
       
        // I build a String like a properties file with var.name=temply expression to get the value
        StringBuffer in = new StringBuffer();
        for (Var var : rule.getVars()) {
            in.append(var.getName()).append("=$temply{").append(categorizedRule).append(":").append(var.getName()).append("}").append("\n");
        }
       
        // then I resolve all paths
//        InputNode inputNode = new InputNode(_project.getRepository(), _rules, in.toString(), _forcedCategories,
//                _forcedPaths);
       
        Collection<List<PathEntry>> paths = getPaths(in.toString());
        for (List<PathEntry> path : paths) {
            Properties prop = new Properties();
            try {
                // I resolve the path and put it in a properties
                prop.load(new StringReader(resolvePath(in.toString(), path)));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            // then I read the properties and put them in the result
            RuleValue value = new RuleValue();
            for (Var var : rule.getVars()) {
                value.put(var.getName(), prop.getProperty(var.getName()));
            }
            result.add(new RuleSolution(value, path));
        }
        return result;
View Full Code Here

        return function.evaluate(_project, args);
    }
   
    public Rule addResolve(String resolveRuleName, String varName,
            String value, String category) {
        Rule resolveRule = _project.getRepository().getRule(resolveRuleName);
        if (resolveRule == null) {
            throw new IllegalArgumentException("Cannot find rule \"" + resolveRuleName + "\".");
        }
        Rule rule = addManualRule(null);
        Resolve resolve = new Resolve(rule, resolveRule, category, resolveRule.getVar(varName),
                value);
        rule.add(resolve);
        return rule;
    }
View Full Code Here

//        }
//        return rule;
//    }
   
    private Rule addManualRule(String category) {
        Rule rule = new Rule("_manual_rule_" + count++, category);
        _rules.add(rule);
        return rule;
    }
View Full Code Here

        _rules.add(rule);
        return rule;
    }
   
    public void removeForcedCategory(String ruleName, String mainCategory) {
        Rule rule = _project.getRepository().getRule(ruleName);
        if (rule == null) {
            throw new IllegalArgumentException("Cannot find rule \"" + ruleName + "\".");
        }

        for (Var var : rule.getVars()) {
            _forcedCategories.remove(new VarExpression(rule, Utils.getCategories(mainCategory), var));
        }
    }
View Full Code Here

   
    /**
     * force a resolution for the given rule and mainCategory to use the given category
     */
    public void forceCategory(String ruleName, String mainCategory, String category) {
        Rule rule = _project.getRepository().getRule(ruleName);
        if (rule == null) {
            throw new IllegalArgumentException("Cannot find rule \"" + ruleName + "\".");
        }

        for (Var var : rule.getVars()) {
            _forcedCategories.put(new VarExpression(rule, Utils.getCategories(mainCategory), var), category);
        }
    }
View Full Code Here

TOP

Related Classes of net.sourceforge.temply.base.rules.Rule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.