Examples of RuleDescr


Examples of org.drools.compiler.lang.descr.RuleDescr

     * 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.getInvokerLookups().get( className );
            if ( invoker != null ) {
                data.putInvoker( className,
                                 invoker );
            }
            final String text = invokers.getValue();

            final BaseDescr descr = (BaseDescr) context.getDescrLookups().get( 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 );

    }
View Full Code Here

Examples of org.drools.compiler.lang.descr.RuleDescr

        return result;
    }

    public void buildAttributes(final RuleBuildContext context) {
        final Rule rule = context.getRule();
        final RuleDescr ruleDescr = context.getRuleDescr();
        boolean enforceEager = false;

        for ( final AttributeDescr attributeDescr : ruleDescr.getAttributes().values() ) {
            final String name = attributeDescr.getName();
            if ( name.equals( "no-loop" ) ) {
                rule.setNoLoop( getBooleanValue( attributeDescr,
                                                 true ) );
                enforceEager = true;
            } else if ( name.equals( "auto-focus" ) ) {
                rule.setAutoFocus( getBooleanValue( attributeDescr,
                                                    true ) );
            } else if ( name.equals( "agenda-group" ) ) {
                if ( StringUtils.isEmpty(rule.getRuleFlowGroup())) {
                    rule.setAgendaGroup( attributeDescr.getValue() ); // don't override if RFG has already set this
                }
            } else if ( name.equals( "activation-group" ) ) {
                rule.setActivationGroup( attributeDescr.getValue() );
            } else if ( name.equals( "ruleflow-group" ) ) {
                rule.setRuleFlowGroup( attributeDescr.getValue() );
                rule.setAgendaGroup( attributeDescr.getValue() ); // assign AG to the same name as AG, as they are aliased to AGs anyway
            } else if ( name.equals( "lock-on-active" ) ) {
                boolean lockOnActive = getBooleanValue( attributeDescr, true );
                rule.setLockOnActive( lockOnActive );
                enforceEager |= lockOnActive;
            } else if ( name.equals( DroolsSoftKeywords.DURATION ) || name.equals( DroolsSoftKeywords.TIMER ) ) {
                String duration = attributeDescr.getValue();
                buildTimer( rule, duration, context);
            else if ( name.equals( "calendars" ) ) {
                buildCalendars( rule, attributeDescr.getValue(), context );
            } else if ( name.equals( "date-effective" ) ) {
                try {
                    Date date = DateUtils.parseDate( attributeDescr.getValue(),
                                                     context.getPackageBuilder().getDateFormats()  );
                    final Calendar cal = Calendar.getInstance();
                    cal.setTime( date );
                    rule.setDateEffective( cal );
                } catch (Exception e) {
                    DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                          "Wrong date-effective value: " + e.getMessage() );
                    context.addError( err  );
                }
            } else if ( name.equals( "date-expires" ) ) {
                try {
                    Date date = DateUtils.parseDate( attributeDescr.getValue(),
                                                     context.getPackageBuilder().getDateFormats()  );
                    final Calendar cal = Calendar.getInstance();
                    cal.setTime( date );
                    rule.setDateExpires( cal );
                } catch (Exception e) {
                    DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
                                                          "Wrong date-expires value: " + e.getMessage() );
                    context.addError( err  );
                }
            }
        }

        buildSalience( context );

        buildEnabled( context );
       
        AnnotationDescr ann = ruleDescr.getAnnotation( "activationListener" );
        if ( ann != null && !StringUtils.isEmpty( ann.getSingleValue() ) ) {
            rule.setActivationListener( MVELSafeHelper.getEvaluator().evalToString( ann.getSingleValue() ) );
        }

        ann = ruleDescr.getAnnotation( "Eager" );
        if ( enforceEager || ( ann != null && trueOrDefault( ann.getSingleValue() ) ) ) {
            rule.setEager( true );
        }

        ann = ruleDescr.getAnnotation( "Direct" );
        if ( ann != null && trueOrDefault( ann.getSingleValue() ) ) {
            rule.setActivationListener( "direct" );
        }

        //        buildDuration( context );
View Full Code Here

Examples of org.drools.compiler.lang.descr.RuleDescr

                    pkgcs.getLoadOrder().add(new ResourceChangeSet.RuleLoadOrder(pkgName, crd.getName(), crd.getLoadOrder() ) );

                    // unfortunately have to iterate search for a rule with the same name
                    boolean found = false;
                    for( Iterator<RuleDescr> it = orules.iterator(); it.hasNext(); ) {
                        RuleDescr ord = it.next();
                        if( ord.getName().equals( crd.getName() ) ) {
                            found = true;
                            it.remove();
                           
                            // using byte[] comparison because using the descriptor equals() method
                            // is brittle and heavier than iterating an array
                            if( !segmentEquals(ob, ord.getStartCharacter(), ord.getEndCharacter(),
                                    cb, crd.getStartCharacter(), crd.getEndCharacter() ) ) {
                                pkgcs.getChanges().add( new ResourceChange( ChangeType.UPDATED,
                                                                            ResourceChange.Type.RULE,
                                                                            crd.getName() ) );
                            }
                            break;
                        }
                    }
                    if( !found ) {
                        pkgcs.getChanges().add( new ResourceChange( ChangeType.ADDED,
                                                                    ResourceChange.Type.RULE,
                                                                    crd.getName() ) );
                    }
                }
               
                for( RuleDescr ord : orules ) {
                    pkgcs.getChanges().add( new ResourceChange( ChangeType.REMOVED,
                                                                ResourceChange.Type.RULE,
                                                                ord.getName() ) );
                }
            } catch ( Exception e ) {
                logger.error( "Error analyzing the contents of "+file+". Skipping.", e );
            }
        }
View Full Code Here

Examples of org.drools.compiler.lang.descr.RuleDescr

    public RuleBuilder() {
    }


    public void preProcess(final RuleBuildContext context) {
        RuleDescr ruleDescr = context.getRuleDescr();

        //Query and get object instead of using String
        if ( null != ruleDescr.getParentName() && null != context.getPkg().getRule( ruleDescr.getParentName() ) ) {
            context.getRule().setParent( context.getPkg().getRule( ruleDescr.getParentName() ) );
        }
        // add all the rule's meta attributes
        buildMetaAttributes( context );

        if ( context.getRuleDescr() instanceof QueryDescr ) {
View Full Code Here

Examples of org.drools.compiler.lang.descr.RuleDescr

     * Build the give rule into the
     * @param context
     * @return
     */
    public void build(final RuleBuildContext context) {
        RuleDescr ruleDescr = context.getRuleDescr();

        final RuleConditionBuilder builder = (RuleConditionBuilder) context.getDialect().getBuilder( ruleDescr.getLhs().getClass() );
        if ( builder != null ) {
            Pattern prefixPattern = context.getPrefixPattern(); // this is established during pre-processing, if it's query
            final GroupElement ce = (GroupElement) builder.build( context,
                                                                  ruleDescr.getLhs(),
                                                                  prefixPattern );

            context.getRule().setLhs( ce );
        } else {
            throw new RuntimeDroolsException( "BUG: builder not found for descriptor class " + ruleDescr.getLhs().getClass() );
        }

        // build all the rule's attributes
        // must be after building LHS because some attributes require bindings from the LHS
        buildAttributes( context );

        // Build the consequence and generate it's invoker/s
        // generate the main rule from the previously generated s.
        if ( !(ruleDescr instanceof QueryDescr) ) {
            // do not build the consequence if we have a query

            ConsequenceBuilder consequenceBuilder = context.getDialect().getConsequenceBuilder();
            consequenceBuilder.build( context, Rule.DEFAULT_CONSEQUENCE_NAME );
           
            for ( String name : ruleDescr.getNamedConsequences().keySet() ) {
                consequenceBuilder.build( context, name );
            }
        }
    }
View Full Code Here

Examples of org.drools.compiler.lang.descr.RuleDescr

            }
            return;
        }

        while (!roots.isEmpty()) {
            RuleDescr root = roots.remove(0);
            sorted.put(root.getName(), root);
            List<RuleDescr> childz = children.remove(root.getName());
            if (childz != null) {
                roots.addAll(childz);
            }
        }
View Full Code Here

Examples of org.drools.compiler.lang.descr.RuleDescr

            // TODO: process annotations

            // process pattern
            InternalKnowledgePackage pkg = pkgRegistry.getPackage();
            DialectCompiletimeRegistry ctr = pkgRegistry.getDialectCompiletimeRegistry();
            RuleDescr dummy = new RuleDescr(wd.getName() + " Window Declaration");
            dummy.addAttribute(new AttributeDescr("dialect", "java"));
            RuleBuildContext context = new RuleBuildContext(this,
                                                            dummy,
                                                            ctr,
                                                            pkg,
                                                            ctr.getDialect(pkgRegistry.getDialect()));
View Full Code Here

Examples of org.drools.compiler.lang.descr.RuleDescr

        return map;
    }

    private void addRule(RuleBuildContext context) {
        final RuleDescr ruleDescr = context.getRuleDescr();

        InternalKnowledgePackage pkg = context.getPkg();

        ruleBuilder.build(context);

        this.results.addAll(context.getErrors());
        this.results.addAll(context.getWarnings());

        context.getRule().setResource(ruleDescr.getResource());

        context.getDialect().addRule(context);

        if (context.needsStreamMode()) {
            pkg.setNeedStreamMode();
View Full Code Here

Examples of org.drools.compiler.lang.descr.RuleDescr

            }
            return;
        }

        while (!roots.isEmpty()) {
            RuleDescr root = roots.remove(0);
            sorted.put(root.getName(), root);
            List<RuleDescr> childz = children.remove(root.getName());
            if (childz != null) {
                roots.addAll(childz);
            }
        }
View Full Code Here

Examples of org.drools.compiler.lang.descr.RuleDescr

            // TODO: process annotations

            // process pattern
            Package pkg = pkgRegistry.getPackage();
            DialectCompiletimeRegistry ctr = pkgRegistry.getDialectCompiletimeRegistry();
            RuleDescr dummy = new RuleDescr(wd.getName() + " Window Declaration");
            dummy.addAttribute(new AttributeDescr("dialect", "java"));
            RuleBuildContext context = new RuleBuildContext(this,
                    dummy,
                    ctr,
                    pkg,
                    ctr.getDialect(pkgRegistry.getDialect()));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.