Package org.drools.rule.builder.dialect.java

Examples of org.drools.rule.builder.dialect.java.JavaDialect


        ReturnValueDescr descr = new ReturnValueDescr();
        descr.setText( "return value;" );

        PackageBuilder pkgBuilder = new PackageBuilder( pkg );
        DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry( pkg.getName() ).getDialectCompiletimeRegistry();
        JavaDialect javaDialect = (JavaDialect) dialectRegistry.getDialect( "java" );

        ProcessBuildContext context = new ProcessBuildContext( pkgBuilder,
                                                               pkg,
                                                               process,
                                                               processDescr,
                                                               dialectRegistry,
                                                               javaDialect );

        pkgBuilder.addPackageFromDrl( new StringReader( "package pkg1;\nglobal Boolean value;" ) );

        ReturnValueConstraintEvaluator node = new ReturnValueConstraintEvaluator();

        final JavaReturnValueEvaluatorBuilder builder = new JavaReturnValueEvaluatorBuilder();
        builder.build( context,
                       node,
                       descr,
                       null );

        ProcessDialectRegistry.getDialect(JavaDialect.ID).addProcess( context );
        javaDialect.compileAll();
        assertEquals( 0, javaDialect.getResults().size() );

        final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        List<KnowledgePackage> packages = new ArrayList<KnowledgePackage>();
        packages.add( new KnowledgePackageImp(pkgBuilder.getPackage()) );
        kbase.addKnowledgePackages( packages );
View Full Code Here


        ActionDescr actionDescr = new ActionDescr();
        actionDescr.setText( "list.add( \"hello world\" );" );      

        PackageBuilder pkgBuilder = new PackageBuilder( pkg );
        DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry( pkg.getName() ).getDialectCompiletimeRegistry();
        JavaDialect javaDialect = ( JavaDialect ) dialectRegistry.getDialect( "java" );

        ProcessDescr processDescr = new ProcessDescr();
        processDescr.setClassName( "Process1" );
        processDescr.setName( "Process1" );
       
        WorkflowProcessImpl process = new WorkflowProcessImpl();
        process.setName( "Process1" );
        process.setPackageName( "pkg1" );

        ProcessBuildContext context = new ProcessBuildContext(pkgBuilder, pkgBuilder.getPackage(), null, processDescr, dialectRegistry, javaDialect);
       
        context.init( pkgBuilder, pkg, null, dialectRegistry, javaDialect, null);
       
        pkgBuilder.addPackageFromDrl( new StringReader("package pkg1;\nglobal java.util.List list;\n") );       
       
        ActionNode actionNode = new ActionNode();
        DroolsAction action = new DroolsConsequenceAction("java", null);
        actionNode.setAction(action);
       
        ProcessDialect dialect = ProcessDialectRegistry.getDialect( "java" );           
        dialect.getActionBuilder().build( context, action, actionDescr, actionNode );
        dialect.addProcess( context );
        javaDialect.compileAll();           
        assertEquals( 0, javaDialect.getResults().size() );

        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
        ruleBase.addPackage( pkgBuilder.getPackage() );
        final WorkingMemory wm = ruleBase.newStatefulSession();
View Full Code Here

                      final ActionDescr actionDescr,
                      final ContextResolver contextResolver) {

        final String className = "action" + context.getNextId();              

        JavaDialect dialect = (JavaDialect) context.getDialect( "java" );
       
        Map<String, Class<?>> variables = new HashMap<String,Class<?>>();
        BoundIdentifiers boundIdentifiers = new BoundIdentifiers(variables, context.getPackageBuilder().getGlobals());
        AnalysisResult analysis = dialect.analyzeBlock( context,
                                                        actionDescr,
                                                        actionDescr.getText(),
                                                        boundIdentifiers);

        if ( analysis == null ) {
View Full Code Here

  private static final ActionBuilder actionBuilder = new JavaActionBuilder();
  private static final ProcessClassBuilder processClassBuilder = new JavaProcessClassBuilder();
  private static final ReturnValueEvaluatorBuilder returnValueBuilder = new JavaReturnValueEvaluatorBuilder();
 
  public void addProcess(final ProcessBuildContext context) {
    JavaDialect javaDialect = (JavaDialect) context.getDialectRegistry().getDialect("java");
    String processClass = processClassBuilder.buildRule(context);
    if (processClass == null) {
      // nothing to compile.
      return;
    }

    final Process process = context.getProcess();
    final ProcessDescr processDescr = context.getProcessDescr();

    // The compilation result is for the entire rule, so difficult to
    // associate with any descr
    javaDialect.addClassCompileTask(context.getPkg().getName() + "."
        + processDescr.getClassName(), processDescr, processClass,
        null, new ProcessErrorHandler(processDescr, process,
            "Process Compilation error"));

    JavaDialectRuntimeData data = (JavaDialectRuntimeData) context.getPkg()
      .getDialectRuntimeRegistry().getDialectData(javaDialect.getId());

    for (final Iterator it = context.getInvokers().keySet().iterator(); it
        .hasNext();) {
      final String className = (String) it.next();

      // Check if an invoker - Action has been associated
      // If so we add it to the PackageCompilationData as it will get
      // wired up on compilation
      final Object invoker = context.getInvokerLookups().get(className);
      if (invoker != null) {
        data.putInvoker(className, invoker);
      }
      final String text = (String) context.getInvokers().get(className);

      final BaseDescr descr = (BaseDescr) context.getDescrLookups().get(
          className);
      javaDialect.addClassCompileTask(className, descr, text, null,
          new ProcessInvokerErrorHandler(processDescr, process,
              "Unable to generate action invoker."));

    }
View Full Code Here

                      final ReturnValueDescr descr,
                      final ContextResolver contextResolver) {

        final String className = "returnValueEvaluator" + context.getNextId();

        JavaDialect dialect = (JavaDialect) context.getDialect( "java" );
       
        Map<String, Class<?>> variables = new HashMap<String,Class<?>>();
        BoundIdentifiers boundIdentifiers = new BoundIdentifiers(variables, context.getPackageBuilder().getGlobals());
        AnalysisResult analysis = dialect.analyzeBlock( context,
                                                        descr,
                                                        descr.getText(),
                                                        boundIdentifiers);

        if ( analysis == null ) {
View Full Code Here

        }

        String source = compiler.generateSource();
        String generatedSourceName = compiler.getName();

        JavaDialect dialect = (JavaDialect) pkgReg.getDialectCompiletimeRegistry().getDialect("java");
        dialect.addSrc(compiler.getBinaryName(), source.getBytes());
        pkgBuilder.compileAll();
        pkgBuilder.updateResults();

        CompiledNetwork network;
        try {
View Full Code Here

            if ( pkgReg == null ) {
                pkgBuilder.addPackage( new PackageDescr( pkgName ) );
                pkgReg = pkgBuilder.getPackageRegistry( pkgName );
            }

            JavaDialect dialect = (JavaDialect) pkgReg.getDialectCompiletimeRegistry().getDialect( "java" );
            dialect.addSrc( convertToResource( entry.getKey() ),
                            entry.getValue() );
        }

        pkgBuilder.compileAll();
        pkgBuilder.updateResults();
View Full Code Here

            if ( pkgReg == null ) {
                pkgBuilder.addPackage( new PackageDescr( pkgName ) );
                pkgReg = pkgBuilder.getPackageRegistry( pkgName );
            }

            JavaDialect dialect = (JavaDialect) pkgReg.getDialectCompiletimeRegistry().getDialect( "java" );
            dialect.addSrc( convertToResource( entry.getKey() ),
                            entry.getValue() );
        }

        pkgBuilder.compileAll();
        pkgBuilder.updateResults();
View Full Code Here

            if ( pkgReg == null ) {
                pkgBuilder.addPackage( new PackageDescr( pkgName ) );
                pkgReg = pkgBuilder.getPackageRegistry( pkgName );
            }

            JavaDialect dialect = (JavaDialect) pkgReg.getDialectCompiletimeRegistry().getDialect( "java" );
            dialect.addSrc( convertToResource( entry.getKey() ),
                            entry.getValue() );
        }

        pkgBuilder.compileAll();
        pkgBuilder.updateResults();
View Full Code Here

            if ( pkgReg == null ) {
                pkgBuilder.addPackage( new PackageDescr( pkgName ) );
                pkgReg = pkgBuilder.getPackageRegistry( pkgName );
            }

            JavaDialect dialect = (JavaDialect) pkgReg.getDialectCompiletimeRegistry().getDialect( "java" );
            dialect.addSrc( convertToResource( entry.getKey() ),
                            entry.getValue() );
        }

        pkgBuilder.compileAll();
        pkgBuilder.updateResults();
View Full Code Here

TOP

Related Classes of org.drools.rule.builder.dialect.java.JavaDialect

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.