Java Code Examples for org.drools.core.util.StringUtils#ucFirst()

The following examples show how to use org.drools.core.util.StringUtils#ucFirst() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private static void generateInvokerTemplate(final String invokerTemplate,
                                            final RuleBuildContext context,
                                            final String className,
                                            final Map vars,
                                            final Object invokerLookup,
                                            final BaseDescr descrLookup) {
    TemplateRegistry registry = getInvokerTemplateRegistry(context.getKnowledgeBuilder().getRootClassLoader());
    final String invokerClassName = context.getPkg().getName() + "." + context.getRuleDescr().getClassName() + StringUtils.ucFirst( className ) + "Invoker";

    context.addInvoker( invokerClassName,
                        (String) TemplateRuntime.execute( registry.getNamedTemplate( invokerTemplate ),
                                                          null,
                                                          new MapVariableResolverFactory( vars ),
                                                          registry ) );

    context.addInvokerLookup( invokerClassName, invokerLookup );
    context.addDescrLookups( invokerClassName, descrLookup );
}
 
Example 2
public void removeRule( KnowledgePackageImpl pkg,
                        RuleImpl rule ) {

    if (!( rule instanceof QueryImpl)) {
        // Query's don't have a consequence, so skip those
        final String consequenceName = rule.getConsequence().getClass().getName();

        // check for compiled code and remove if present.
        if (remove( consequenceName )) {
            removeClasses( rule.getLhs() );

            // Now remove the rule class - the name is a subset of the consequence name
            String sufix = StringUtils.ucFirst( rule.getConsequence().getName() ) + "ConsequenceInvoker";
            remove( consequenceName.substring( 0,
                                               consequenceName.indexOf( sufix ) ) );
        }
    }
}
 
Example 3
public void generateTemplates(final String ruleTemplate,
                             final String invokerTemplate,
                             final ProcessBuildContext context,
                             final String className,
                             final Map vars,
                             final Object invokerLookup,
                             final BaseDescr descrLookup) {
    TemplateRegistry registry = getRuleTemplateRegistry();

    context.getMethods().add((String)
            TemplateRuntime.execute(registry.getNamedTemplate(ruleTemplate), null, new MapVariableResolverFactory(vars), registry)
    );

    registry = getInvokerTemplateRegistry();
    final String invokerClassName = context.getPkg().getName() + "." + context.getProcessDescr().getClassName() + StringUtils.ucFirst(className) + "Invoker";

    context.getInvokers().put(invokerClassName,
            (String)TemplateRuntime.execute(registry.getNamedTemplate(invokerTemplate), null, new MapVariableResolverFactory(vars), registry)
    );

    context.addInvokerLookup(invokerClassName, invokerLookup);
    context.addDescrLookups(invokerClassName, descrLookup);
}
 
Example 4
Source Project: kogito-runtimes   File: JavaDialect.java    License: Apache License 2.0 5 votes vote down vote up
public void addFunction(final FunctionDescr functionDescr,
                        final TypeResolver typeResolver,
                        final Resource resource) {

    //logger.info( functionDescr + " : " + typeResolver );
    final String functionClassName = this.pkg.getName() + "." + StringUtils.ucFirst(functionDescr.getName());
    functionDescr.setClassName(functionClassName);

    this.pkg.addStaticImport(functionClassName + "." + functionDescr.getName());

    Function function = new Function(functionDescr.getNamespace(), functionDescr.getName(), ID);
    if (resource != null && ((InternalResource) resource).hasURL()) {
        function.setResource(resource);
    }
    this.pkg.addFunction(function);

    final String functionSrc = getFunctionBuilder().build(this.pkg,
                                                          functionDescr,
                                                          typeResolver,
                                                          this.pkg.getDialectRuntimeRegistry().getLineMappings(),
                                                          this.results);

    addClassCompileTask(functionClassName,
                        functionDescr,
                        functionSrc,
                        this.src,
                        new FunctionErrorHandler(functionDescr,
                                                 "Function Compilation error"));

    final LineMappings mapping = new LineMappings(functionClassName);
    mapping.setStartLine(functionDescr.getLine());
    mapping.setOffset(functionDescr.getOffset());
    this.pkg.getDialectRuntimeRegistry().getLineMappings().put(functionClassName,
                                                               mapping);
}
 
Example 5
Source Project: kogito-runtimes   File: JavaDialect.java    License: Apache License 2.0 5 votes vote down vote up
public void postCompileAddFunction(FunctionDescr functionDescr,
                                   TypeResolver typeResolver) {
    final String functionClassName = this.pkg.getName() + "." + StringUtils.ucFirst(functionDescr.getName());
    ImportDescr importDescr = new ImportDescr(functionClassName + "." + functionDescr.getName());
    importDescr.setResource(functionDescr.getResource());
    importDescr.setNamespace(functionDescr.getNamespace());
    this.packageRegistry.addStaticImport(importDescr);
}
 
Example 6
Source Project: kogito-runtimes   File: MVELDialect.java    License: Apache License 2.0 5 votes vote down vote up
public void addRule(RuleBuildContext context) {
    // MVEL: Compiler change
    final RuleDescr ruleDescr = context.getRuleDescr();

    // setup the line mappins for this rule
    final String name = this.pkg.getName() + "." + StringUtils.ucFirst(ruleDescr.getClassName());
    final LineMappings mapping = new LineMappings(name);
    mapping.setStartLine(ruleDescr.getConsequenceLine());
    mapping.setOffset(ruleDescr.getConsequenceOffset());

    context.getPkg().getDialectRuntimeRegistry().getLineMappings().put(name,
                                                                       mapping);
}
 
Example 7
public String getNativeReadMethodName() {
    String method = "";
    if ( type != null && type.isPrimitive() ) {
        method = StringUtils.ucFirst( type.getName () );
    }
    return "get" + method + "Value";
}
 
Example 8
Source Project: kogito-runtimes   File: JavaDialect.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * This will add the rule for compiling later on.
 * It will not actually call the compiler
 */
public void addRule(final RuleBuildContext context) {
    final RuleImpl rule = context.getRule();
    final RuleDescr ruleDescr = context.getRuleDescr();

    RuleClassBuilder classBuilder = context.getDialect().getRuleClassBuilder();

    String ruleClass = classBuilder.buildRule(context);
    // return if there is no ruleclass name;
    if (ruleClass == null) {
        return;
    }

    // The compilation result is for the entire rule, so difficult to associate with any descr
    addClassCompileTask(this.pkg.getName() + "." + ruleDescr.getClassName(),
                        ruleDescr,
                        ruleClass,
                        this.src,
                        new RuleErrorHandler(ruleDescr,
                                             rule,
                                             "Rule Compilation error"));

    JavaDialectRuntimeData data = (JavaDialectRuntimeData) this.pkg.getDialectRuntimeRegistry().getDialectData(ID);

    for (Map.Entry<String, String> invokers : context.getInvokers().entrySet()) {
        final String className = invokers.getKey();

        // Check if an invoker - returnvalue, predicate, eval or consequence has been associated
        // If so we add it to the PackageCompilationData as it will get wired up on compilation
        final Object invoker = context.getInvokerLookup(className);
        if (invoker instanceof Wireable) {
            data.putInvoker(className, (Wireable)invoker);
        }
        final String text = invokers.getValue();

        final BaseDescr descr = context.getDescrLookup(className);
        addClassCompileTask(className,
                            descr,
                            text,
                            this.src,
                            new RuleInvokerErrorHandler(descr,
                                                        rule,
                                                        "Unable to generate rule invoker."));
    }

    // setup the line mappins for this rule
    final String name = this.pkg.getName() + "." + StringUtils.ucFirst(ruleDescr.getClassName());
    final LineMappings mapping = new LineMappings(name);
    mapping.setStartLine(ruleDescr.getConsequenceLine());
    mapping.setOffset(ruleDescr.getConsequenceOffset());

    this.pkg.getDialectRuntimeRegistry().getLineMappings().put(name,
                                                               mapping);
}
 
Example 9
Source Project: kogito-runtimes   File: JavaDialect.java    License: Apache License 2.0 4 votes vote down vote up
public void preCompileAddFunction(FunctionDescr functionDescr,
                                  TypeResolver typeResolver) {
    final String functionClassName = this.pkg.getName() + "." + StringUtils.ucFirst(functionDescr.getName());
    this.pkg.addStaticImport(functionClassName + "." + functionDescr.getName());
}