Package org.drools.rule

Examples of org.drools.rule.Declaration


    }
   
    private boolean checkProcessInstance(Activation activation) {
      final Map<?, ?> declarations = activation.getSubRule().getOuterDeclarations();
        for ( Iterator<?> it = declarations.values().iterator(); it.hasNext(); ) {
            Declaration declaration = (Declaration) it.next();
            if ("processInstance".equals(declaration.getIdentifier())) {
              Object value = declaration.getValue(
              ((StatefulKnowledgeSessionImpl) getProcessInstance().getKnowledgeRuntime()).session,
              ((InternalFactHandle) activation.getTuple().get(declaration)).getObject());
              if (value instanceof ProcessInstance) {
                return ((ProcessInstance) value).getId() == getProcessInstance().getId();
              }
View Full Code Here


    }
   
    private boolean checkProcessInstance(Activation activation) {
      final Map<?, ?> declarations = activation.getSubRule().getOuterDeclarations();
        for ( Iterator<?> it = declarations.values().iterator(); it.hasNext(); ) {
            Declaration declaration = (Declaration) it.next();
            if ("processInstance".equals(declaration.getIdentifier())) {
              Object value = declaration.getValue(
              ((StatefulKnowledgeSessionImpl) getProcessInstance().getKnowledgeRuntime()).session,
              ((InternalFactHandle) activation.getTuple().get(declaration)).getObject());
              if (value instanceof ProcessInstance) {
                return ((ProcessInstance) value).getId() == getProcessInstance().getId();
              }
View Full Code Here

        this.rules = ruleSet.getRules( );
    }

    public RuleBase buildRuleBase()
    {
        Declaration declaration;
        Rule rule;
        ParameterNode parameterNode;
        for ( int i = 0; i < rules.length; i++ )
        {
            rule = rules[i];
            for ( Iterator j = rule.getParameterDeclarations( ).iterator( ); j.hasNext( ); )
            {
                declaration = ( Declaration ) j.next();

                parameterNode = new ParameterNode( rete.getOrCreateObjectTypeNode( declaration.getObjectType( ) ),
                                                   declaration );

                parameterNode.attach( );

                List conditions = rule.getConditions( );
View Full Code Here

        Set refs = visitor.getVariables( );

        List decls = new LinkedList( );
        for ( Iterator declIter = availDecls.iterator( ); declIter.hasNext( ); )
        {
            Declaration eachDecl = ( Declaration ) declIter.next( );

            if ( refs.contains( eachDecl.getIdentifier( ) ) )
            {
                decls.add( eachDecl );
                refs.remove( eachDecl.getIdentifier( ) );
            }
        }

        return ( Declaration[] ) decls.toArray( new Declaration[ decls.size( ) ] );
    }
View Full Code Here

     * @return The dictionary
     */
    protected PyDictionary setUpDictionary(Tuple tuple,
                                           Iterator declIter) throws Exception
    {
        Declaration eachDecl;

        ObjectType objectType;
        String type;
        Class clazz;
        int nestedClassPosition;
        int dotPosition;

        PyDictionary dict = new PyDictionary( );

        // dict.setdefault( new PyString( "q" ), qFunc ); //add tenerary
        // function

        RuleBaseContext ruleBaseContext = rule.getRuleSet( ).getRuleBaseContext( );
        ClassLoader cl = (ClassLoader) ruleBaseContext.get( "smf-classLoader" );
        if ( cl == null )
        {
            cl = Thread.currentThread( ).getContextClassLoader( );
            ruleBaseContext.put( "smf-classLoader",
                                 cl );
        }

        if ( cl == null )
        {
            cl = getClass( ).getClassLoader( );
            ruleBaseContext.put( "smf-classLoader",
                                 cl );
        }
       

        while ( declIter.hasNext( ) )
        {
            eachDecl = (Declaration) declIter.next( );

            dict.setdefault( new PyString( eachDecl.getIdentifier( ).intern( ) ),
                             Py.java2py( tuple.get( eachDecl ) ) );

            objectType = eachDecl.getObjectType( );

            if ( objectType instanceof ClassObjectType )
            {
                clazz = ((ClassObjectType) objectType).getType( );
                type = clazz.getName( );
View Full Code Here

        List decls = new ArrayList( );

        Set refs = ( Set ) visitor.eval_input( expr );

        Iterator declIter = availDecls.iterator( );
        Declaration eachDecl;

        while ( declIter.hasNext( ) )
        {
            eachDecl = ( Declaration ) declIter.next( );

            if ( refs.contains( eachDecl.getIdentifier( ) ) )
            {
                decls.add( eachDecl );
                refs.remove( eachDecl.getIdentifier( ) );
            }
        }

        return ( Declaration[] ) decls.toArray( new Declaration[ decls.size( ) ] );
    }
View Full Code Here

    public void testGetRequiredTupleMembers() throws Exception {
        Rule rule = new Rule("for-test.declaration-factory");
        Argument[] parameterValues = new Argument[3];
        MockControl controlObjectType_1 = mocks.createControl(ObjectType.class);
        MockControl controlObjectType_2 = mocks.createControl(ObjectType.class);
        Declaration expectedDeclaration_1 = rule.addParameterDeclaration(
                "id-1", (ObjectType) controlObjectType_1.getMock());
        Declaration expectedDeclaration_2 = rule.addParameterDeclaration(
                "id-2", (ObjectType) controlObjectType_2.getMock());

        parameterValues[0] = new ApplicationDataArgument("name", Object.class);
        parameterValues[1] = new FactArgument(expectedDeclaration_1);
        parameterValues[2] = new FactArgument(expectedDeclaration_2);
View Full Code Here

        // identifiers based on the parameter class (ie, all identifiers for a given type
        // will be identical).
        List parameterDeclarations = rule.getParameterDeclarations();
        assertEquals(expectedDeclarationObjectTypes.size(), parameterDeclarations.size());
        for (Iterator iter = parameterDeclarations.iterator(); iter.hasNext();) {
            Declaration declaration = (Declaration) iter.next();
            if (!expectedDeclarationObjectTypes.contains(declaration.getObjectType())) {
                fail("Unexpected rule declaration object-type: " + declaration.getObjectType());
            }
        }

        List conditions = rule.getConditions();
        assertEquals(2, conditions.size());
View Full Code Here

                                   rule ) ); // 3
        assertTrue( testCondition( testNumber++,
                                   tuple,
                                   rule ) ); // 4

        Declaration camembertDecl = rule.addParameterDeclaration( "camembert",
                                                                  cheeseType );
        Declaration stiltonDecl = rule.addParameterDeclaration( "stilton",
                                                                cheeseType );
        rule.setImporter( this.importer );
        // condition check with a single declaration
        tuple.put( camembertDecl,
                   new Cheese( "camembert" ) );
        assertTrue( testCondition( testNumber++,
                                   tuple,
                                   rule ) ); // 5
        assertFalse( testCondition( testNumber++,
                                    tuple,
                                    rule ) ); // 6

        // condition check with a single declaration
        tuple = new MockTuple( );
        rule.setImporter( this.importer );
        tuple.setRule( rule );
        tuple.setWorkingMemory( new MockWorkingMemory( ) );
        tuple.put( stiltonDecl,
                   new Cheese( "stilton" ) );
        assertTrue( testCondition( testNumber++,
                                   tuple,
                                   rule ) ); // 7
        assertFalse( testCondition( testNumber++,
                                    tuple,
                                    rule ) ); // 8

        // condition check with two declarations
        tuple = new MockTuple( );
        rule.setImporter( this.importer );
        tuple.setRule( rule );
        tuple.setWorkingMemory( new MockWorkingMemory( ) );
        tuple.put( stiltonDecl,
                   new Cheese( "stilton" ) );
        tuple.put( camembertDecl,
                   new Cheese( "camembert" ) );
        assertFalse( testCondition( testNumber++,
                                    tuple,
                                    rule ) ); // 9
        assertTrue( testCondition( testNumber++,
                                   tuple,
                                   rule ) ); // 10
        assertTrue( testCondition( testNumber++,
                                   tuple,
                                   rule ) ); // 11
        assertFalse( testCondition( testNumber++,
                                    tuple,
                                    rule ) ); // 12

        // condition check with 2 declarations and application data
        WorkingMemory workingMemory = new MockWorkingMemory( );
        workingMemory.setApplicationData( "bites",
                                          new Integer( 3 ) );
        workingMemory.setApplicationData( "favouriteCheese",
                                          new Cheese( "camembert" ) );
        tuple.setWorkingMemory( workingMemory );

        HashMap applicationData = new HashMap( );
        applicationData.put( "bites",
                             Integer.class );
        applicationData.put( "favouriteCheese",
                             Cheese.class );

        rule.setApplicationData( applicationData );

        assertTrue( testCondition( testNumber++,
                                   tuple,
                                   rule ) ); // 13
        assertFalse( testCondition( testNumber++,
                                    tuple,
                                    rule ) ); // 14
        assertTrue( testCondition( testNumber++,
                                   tuple,
                                   rule ) ); // 15

        // test code works no matter what the order of decl are
        tuple = new MockTuple( );
        rule.setImporter( this.importer );
        rule.setApplicationData( new HashMap( ) );
        tuple.setRule( rule );
        workingMemory = new MockWorkingMemory( );
        tuple.setWorkingMemory( workingMemory );

        DefaultConfiguration stringConfiguration = new DefaultConfiguration( "test2" );
        stringConfiguration.setText( String.class.getName( ) );
        ObjectType stringType = objectTypeFactory.newObjectType( rule,
                                                                 this.ruleBaseContext,
                                                                 stringConfiguration );
        Declaration favouriteCheeseDecl = rule.addParameterDeclaration( "favouriteCheese",
                                                                        stringType );

        tuple.put( favouriteCheeseDecl,
                   "camembert" );
        tuple.put( camembertDecl,
View Full Code Here

                         tuple,
                         rule );

        // need to declare so that the tests have SMFTestFrameWork.Cheese
        // imported
        Declaration camembertDecl = rule.addParameterDeclaration( "camembert",
                                                                  cheeseType );
        Declaration stiltonDecl = rule.addParameterDeclaration( "stilton",
                                                                cheeseType );

        Cheese camembert = new Cheese( "camembert" );
        Cheese stilton = new Cheese( "stilton" );
        tuple.put( camembertDecl,
View Full Code Here

TOP

Related Classes of org.drools.rule.Declaration

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.