Package org.drools.core.reteoo.builder

Examples of org.drools.core.reteoo.builder.BuildContext


        ObjectType objectType = kBase.getClassFieldAccessorCache().getClassObjectType( new ClassObjectType( clazz,
                                                                                                                                    isEvent ) );

        this.concreteObjectTypeNode = kBase.getRete().getObjectTypeNodes( entryPoint ).get( objectType );
        if ( this.concreteObjectTypeNode == null ) {
            BuildContext context = new BuildContext( kBase,
                                                     kBase.getReteooBuilder().getIdGenerator() );
            context.setCurrentEntryPoint( entryPoint );
            if ( DroolsQuery.class == clazz ) {
                context.setTupleMemoryEnabled( false );
                context.setObjectTypeNodeMemoryEnabled( false );
            } else if ( context.getKnowledgeBase().getConfiguration().isSequential() ) {
                // We are in sequential mode, so no nodes should have memory
//                context.setTupleMemoryEnabled( false );
//                context.setObjectTypeNodeMemoryEnabled( false );
                  context.setTupleMemoryEnabled( true );
                  context.setObjectTypeNodeMemoryEnabled( true );
            } else {
                context.setTupleMemoryEnabled( true );
                context.setObjectTypeNodeMemoryEnabled( true );
            }
            // there must exist an ObjectTypeNode for this concrete class
            this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( context,
                                                                               objectType );
        }
View Full Code Here


        this.factTemplate = factTemplate;
        this.entryPoint = entryPoint;
        ObjectType objectType = new FactTemplateObjectType( factTemplate );
        this.concreteObjectTypeNode = (ObjectTypeNode) kBase.getRete().getObjectTypeNodes( entryPoint ).get( objectType );
        if ( this.concreteObjectTypeNode == null ) {
            BuildContext context = new BuildContext( kBase,
                                                     kBase.getReteooBuilder().getIdGenerator() );
            if ( context.getKnowledgeBase().getConfiguration().isSequential() ) {
                // We are in sequential mode, so no nodes should have memory
                context.setTupleMemoryEnabled( false );
                context.setObjectTypeNodeMemoryEnabled( false );
            } else {
                context.setTupleMemoryEnabled( true );
                context.setObjectTypeNodeMemoryEnabled( true );
            }
            // there must exist an ObjectTypeNode for this concrete class
            this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( context,
                                                                               objectType );
        }
View Full Code Here

        final HashMap map = new HashMap();
        workingMemory.setGlobal( "map",
                                 map );

        final LeftTupleImpl tuple = new MockTuple( new HashMap() );
        tuple.setLeftTupleSink( new RuleTerminalNode(1, new CompositeObjectSinkAdapterTest.MockBetaNode(), rule,rule.getLhs(), 0,new BuildContext(kBase, null) )  );
        final Activation activation = new MockActivation( rule,
                                                          0,
                                                          rule.getLhs(),
                                                          tuple );
View Full Code Here

        workingMemory.setGlobal( "map",
                                 map );

        final LeftTupleImpl tuple = new MockTuple( new HashMap() );
        tuple.setLeftTupleSink( new RuleTerminalNode(1, new CompositeObjectSinkAdapterTest.MockBetaNode(), newRule,newRule.getLhs(), 0, new BuildContext(kBase, null) )  );
        final Activation activation = new MockActivation( newRule,
                                                          0,
                                                          newRule.getLhs(),
                                                          tuple );
View Full Code Here

    public RIANodeStep(ReteTesterHelper reteTesterHelper) {
    }

    public void execute(Map<String, Object> context,
                        List<String[]> args) {
        BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
        String name;
        String source;

        if ( args.size() == 1 ) {
            String[] c = args.get( 0 );
            name = c[0].trim();
            source = c[1].trim();
        } else {
            throw new IllegalArgumentException( "Cannot execute arguments " + args );
        }
        LeftTupleSource pnode = null;
        if( source.startsWith( "mock" ) ) {
            pnode = Mockito.mock( LeftTupleSource.class );
        } else {
            pnode = (LeftTupleSource) context.get( source );
        }

        RightInputAdapterNode riaNode = new RightInputAdapterNode( buildContext.getNextId(),
                                                                   pnode,
                                                                   null,
                                                                   buildContext );
        riaNode.attach(buildContext);
        context.put( name,
View Full Code Here

        this.reteTesterHelper = reteTesterHelper;
    }

    public void execute(Map<String, Object> context,
                        List<String[]> args) {
        BuildContext buildContext = (BuildContext) context.get( "BuildContext" );

        if ( args.size() != 0 ) {
            String[] a = args.get( 0 );
            String name = a[0].trim();
            String leftInput = a[1].trim();
            String rightInput = a[2].trim();

            Class cls = null;
                     
            LeftTupleSource leftTupleSource;
            if ( leftInput.startsWith( "mock" ) ) {
                leftTupleSource = new MockTupleSource( buildContext.getNextId() );               
            } else {
                leftTupleSource = (LeftTupleSource) context.get( leftInput );
            }

            ObjectSource rightObjectSource;
            if ( rightInput.startsWith( "mock" ) ) {
                String type = rightInput.substring( 5, rightInput.length() -1 );               
                try {
                    cls = reteTesterHelper.getTypeResolver().resolveType( type );
                } catch ( ClassNotFoundException e ) {
                    throw new RuntimeException( e );
                }
                rightObjectSource = new MockObjectSource( buildContext.getNextId() );
            } else {
                rightObjectSource = (ObjectSource) context.get( rightInput );
                ObjectSource source = rightObjectSource;
                while ( !( source instanceof ObjectTypeNode ) ) {
                    source = source.getParentObjectSource();
                }
                cls = ((ClassObjectType)((ObjectTypeNode)source).getObjectType()).getClassType();
            }
           
            List<BetaNodeFieldConstraint> list = new ArrayList<BetaNodeFieldConstraint>();
            for ( int i = 1; i < args.size(); i++ ) {
                a = args.get( i );
                String fieldName = a[0].trim();
                String operator = a[1].trim();
                String var = a[2].trim();

                Declaration declr = (Declaration) context.get( var );

                BetaNodeFieldConstraint betaConstraint;
                try {
                    betaConstraint = this.reteTesterHelper.getBoundVariableConstraint( cls,
                                                                                         fieldName,
                                                                                         declr,
                                                                                         operator );
                    list.add( betaConstraint );
                } catch ( IntrospectionException e ) {
                    throw new IllegalArgumentException();
                }
            }
           
            BetaConstraints constraints;
            switch ( list.size() ) {
                case 0:
                    constraints = new EmptyBetaConstraints();
                    break;
                case 1:
                  constraints = new SingleBetaConstraints( list.get(0),
                                                           buildContext.getRuleBase().getConfiguration() );                   
                  break;
                case 2:
                    constraints = new DoubleBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
                                                             buildContext.getRuleBase().getConfiguration() );                   
                    break;                   
                case 3:
                    constraints = new TripleBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
                                                             buildContext.getRuleBase().getConfiguration() );                   
                    break;                   
                case 4:
                    constraints = new QuadroupleBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
                                                                 buildContext.getRuleBase().getConfiguration() );                   
                    break;                                       
                default:
                    constraints = new DefaultBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
                                                              buildContext.getRuleBase().getConfiguration() );                   
                    break;                                       
                       
            }

            JoinNode joinNode = new JoinNode( buildContext.getNextId(),
                                              leftTupleSource,
                                              rightObjectSource,
                                              constraints,
                                              buildContext );
            joinNode.attach(buildContext);
View Full Code Here

        this.reteTesterHelper = reteTesterHelper;
    }

    public void execute(Map<String, Object> context,
                        List<String[]> args) {
        BuildContext buildContext = (BuildContext) context.get( "BuildContext" );
        String name;
        String type;

        if ( args.size() == 1 ) {
            String[] c = args.get( 0 );
            name = c[0].trim();
            type = c[1].trim();
        } else {
            throw new IllegalArgumentException( "Cannot execute arguments " + args );
        }
        ObjectTypeNode otn;
        try {
            EntryPointNode epn = new EntryPointNode( buildContext.getNextId(),
                                                     buildContext.getRuleBase().getRete(),
                                                     buildContext );
            epn.attach(buildContext);
           
            Class< ? > clazz = reteTesterHelper.getTypeResolver().resolveType( type );

            otn = new ObjectTypeNode( buildContext.getNextId(),
                                      epn,
                                      new ClassObjectType( clazz ),
                                      buildContext );
            // we don't attach, as we want to manually propagate and not
            // have the working memory propagate
View Full Code Here

        this.reteTesterHelper = reteTesterHelper;
    }

    public void execute(Map<String, Object> context,
                        List<String[]> args) {
        BuildContext buildContext = (BuildContext) context.get( "BuildContext" );

        if ( args.size() != 0 ) {
            String[] a = args.get( 0 );
            String name = a[0];
            String leftInput = a[1];
            String rightInput = a[2];

            Class cls = null;
           
            LeftTupleSource leftTupleSource;
            if ( leftInput.startsWith( "mock" ) ) {
                leftTupleSource = new MockTupleSource( buildContext.getNextId() );               
            } else {
                leftTupleSource = (LeftTupleSource) context.get( leftInput );
            }

            ObjectSource rightObjectSource;
            if ( rightInput.startsWith( "mock" ) ) {
                String type = rightInput.substring( 5, rightInput.length() -1 );               
                try {
                    cls = reteTesterHelper.getTypeResolver().resolveType( type );
                } catch ( ClassNotFoundException e ) {
                    throw new RuntimeException( e );
                }
                rightObjectSource = new MockObjectSource( buildContext.getNextId() );
            } else {
                rightObjectSource = (ObjectSource) context.get( rightInput );
                ObjectSource source = rightObjectSource;
                while ( !( source instanceof ObjectTypeNode ) ) {
                    source = source.getParentObjectSource();
                }
                cls = ((ClassObjectType)((ObjectTypeNode)source).getObjectType()).getClassType();
            }

            List<BetaNodeFieldConstraint> list = new ArrayList<BetaNodeFieldConstraint>();
            for ( int i = 1; i < args.size(); i++ ) {
                a = args.get( i );
                String fieldName = a[0].trim();
                String operator = a[1].trim();
                String var = a[2].trim();

                Declaration declr = (Declaration) context.get( var );

                BetaNodeFieldConstraint betaConstraint;
                try {
                    betaConstraint = this.reteTesterHelper.getBoundVariableConstraint( cls,
                                                                                         fieldName,
                                                                                         declr,
                                                                                         operator );
                    list.add( betaConstraint );
                } catch ( IntrospectionException e ) {
                    throw new IllegalArgumentException();
                }
            }
           
            BetaConstraints constraints;
            switch ( list.size() ) {
                case 0:
                    constraints = new EmptyBetaConstraints();
                    break;
                case 1:
                  constraints = new SingleBetaConstraints( list.get(0),
                                                           buildContext.getRuleBase().getConfiguration() );                   
                  break;
                case 2:
                    constraints = new DoubleBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
                                                             buildContext.getRuleBase().getConfiguration() );                   
                    break;                   
                case 3:
                    constraints = new TripleBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
                                                             buildContext.getRuleBase().getConfiguration() );                   
                    break;                   
                case 4:
                    constraints = new QuadroupleBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
                                                                 buildContext.getRuleBase().getConfiguration() );                   
                    break;                                       
                default:
                    constraints = new DefaultBetaConstraints( list.toArray( new BetaNodeFieldConstraint[2] ),
                                                              buildContext.getRuleBase().getConfiguration() );                   
                    break;                                       
                       
            }

            ExistsNode existsNode = new ExistsNode( buildContext.getNextId(),
                                                    leftTupleSource,
                                                    rightObjectSource,
                                                    constraints,
                                                    buildContext );
            existsNode.attach(buildContext);
View Full Code Here

        RuleBaseConfiguration conf = new RuleBaseConfiguration();

        ReteooRuleBase rbase = new ReteooRuleBase( "ID",
                                                   conf );
        BuildContext buildContext = new BuildContext( rbase,
                                                      rbase.getReteooBuilder().getIdGenerator() );

        Rule rule = new Rule("rule1", "org.pkg1", null);
        org.drools.core.rule.Package pkg = new org.drools.core.rule.Package( "org.pkg1" );
        pkg.getDialectRuntimeRegistry().setDialectData( "mvel", new MVELDialectRuntimeData() );
        pkg.addRule( rule );
       
        buildContext.setRule( rule );

        pctxFactory = conf.getComponentFactory().getPropagationContextFactory();
       
        rbase.addPackage( pkg );
        context.put( BUILD_CONTEXT,
View Full Code Here

        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
        pctxFactory = ruleBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
        this.context = pctxFactory.createPropagationContext(0, PropagationContext.INSERTION, null, null, null);

        BuildContext buildContext = new BuildContext(ruleBase,
                                                     ruleBase.getReteooBuilder().getIdGenerator());

        this.workingMemory = (AbstractWorkingMemory) ruleBase.newStatefulSession();

        this.tupleSource = new MockTupleSource(4);
View Full Code Here

TOP

Related Classes of org.drools.core.reteoo.builder.BuildContext

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.