Package org.drools.rule

Examples of org.drools.rule.FactType


        return false;
    }

    public FactType getFactType(final String name) {
        for ( Package pkg : this.pkgs.values() ) {
            FactType type = pkg.getFactType( name );
            if ( type != null ) {
                return type;
            }
        }
        return null;
View Full Code Here


        return false;
    }

    public FactType getFactType(final String name) {
        for ( Package pkg : this.pkgs.values() ) {
            FactType type = pkg.getFactType( name );
            if ( type != null ) {
                return type;
            }
        }
        return null;
View Full Code Here

        // test rulebase serialization
        ruleBase = SerializationHelper.serializeObject( ruleBase );

        // Retrieve the generated fact type
        FactType cheeseFact = ruleBase.getFactType( "org.drools.generatedbeans.Cheese" );

        // Create a new Fact instance
        Object cheese = cheeseFact.newInstance();

        // Set a field value using the more verbose method chain...
        // should we add short cuts?
        //        cheeseFact.getField( "type" ).getFieldAccessor().setValue( cheese,
        //                                                             "stilton" );

        cheeseFact.set( cheese,
                        "type",
                        "stilton" );
        assertEquals( "stilton",
                      cheeseFact.get( cheese,
                                      "type" ) );



        FactType personType = ruleBase.getFactType( "org.drools.generatedbeans.Person" );

        Object ps = personType.newInstance();
        personType.set( ps,
                        "age",
                        42 );

        Map<String, Object> personMap = personType.getAsMap( ps );
        assertEquals( 42,
                      personMap.get( "age" ) );

        personMap.put( "age",
                       43 );
        personType.setFromMap( ps,
                               personMap );

        assertEquals( 43,
                      personType.get( ps,
                                      "age" ) );

        // just documenting toString() result:
        //        assertEquals( "Cheese( type=stilton )",
        //                      cheese.toString() );

        // reading the field attribute, using the method chain
        assertEquals( "stilton",
                      cheeseFact.getField( "type" ).getFieldAccessor().getValue( cheese ) );

        // creating a stateful session
        StatefulSession wm = ruleBase.newStatefulSession();
        Object cg = cheeseFact.newInstance();
        wm.setGlobal("cg", cg);
        List result = new ArrayList();
        wm.setGlobal( "list",
                      result );

        // inserting fact
        wm.insert( cheese );

        // firing rules
        wm.fireAllRules();

        // checking results
        assertEquals( 1,
                      result.size() );
        assertEquals( new Integer( 5 ),
                      result.get( 0 ) );

        // creating a person that likes the cheese:
        // Retrieve the generated fact type
        FactType personFact = ruleBase.getFactType( "org.drools.generatedbeans.Person" );

        // Create a new Fact instance
        Object person = personFact.newInstance();

        // Set a field value using the more verbose method chain...
        // should we add short cuts?
        personFact.getField( "likes" ).getFieldAccessor().setValue( person,
                                                                    cheese );
        // demonstrating primitive type support
        personFact.getField( "age" ).getFieldAccessor().setIntValue( person,
                                                                     7 );

        // just documenting toString() result:
        //        assertEquals( "Person( age=7, likes=Cheese( type=stilton ) )",
        //                      person.toString() );
View Full Code Here

        // test rulebase serialization
        ruleBase = SerializationHelper.serializeObject( ruleBase );

        // Retrieve the generated fact type
        FactType pf = ruleBase.getFactType( "mortgages.Applicant" );
        FactType af = ruleBase.getFactType( "mortgages.LoanApplication" );

        Object person = pf.newInstance();
        pf.set(person, "creditRating", "OK");

        Object application = af.newInstance();
        StatefulSession sess = ruleBase.newStatefulSession();
        sess.insert(person);
        sess.insert(application);

        sess.fireAllRules();
View Full Code Here

        // test rulebase serialization
        ruleBase = SerializationHelper.serializeObject( ruleBase );

        // Retrieve the generated fact type
        FactType cheeseFact = ruleBase.getFactType( "org.drools.generatedbeans.Cheese" );

        // Create a new Fact instance
        Object cheese = cheeseFact.newInstance();

        cheeseFact.set( cheese,
                        "type",
                        "stilton" );
        assertEquals( "stilton",
                      cheeseFact.get( cheese,
                                      "type" ) );

        // testing equals method
        Object cheese2 = cheeseFact.newInstance();
        cheeseFact.set( cheese2,
                        "type",
                        "stilton" );
        assertEquals( cheese,
                      cheese2 );


        FactType personType = ruleBase.getFactType( "org.drools.generatedbeans.Person" );

        Object ps = personType.newInstance();
        personType.set( ps,
                        "name",
                        "mark" );
        personType.set( ps,
                        "last",
                        "proctor" );
        personType.set( ps,
                        "age",
                        42 );

        Object ps2 = personType.newInstance();
        personType.set( ps2,
                        "name",
                        "mark" );
        personType.set( ps2,
                        "last",
                        "proctor" );
        personType.set( ps2,
                        "age",
                        30 );

        assertEquals( ps, ps2);

        personType.set( ps2,
                        "last",
                        "little" );

        assertFalse( ps.equals( ps2 ) );

        // creating a stateful session
        StatefulSession wm = ruleBase.newStatefulSession();
        Object cg = cheeseFact.newInstance();
        wm.setGlobal("cg", cg);
        List result = new ArrayList();
        wm.setGlobal( "list",
                      result );

        // inserting fact
        wm.insert( cheese );

        // firing rules
        wm.fireAllRules();

        // checking results
        assertEquals( 1,
                      result.size() );
        assertEquals( new Integer( 5 ),
                      result.get( 0 ) );

        // creating a person that likes the cheese:
        // Retrieve the generated fact type
        FactType personFact = ruleBase.getFactType( "org.drools.generatedbeans.Person" );

        // Create a new Fact instance
        Object person = personFact.newInstance();

        // Set a field value using the more verbose method chain...
        // should we add short cuts?
        personFact.getField( "likes" ).getFieldAccessor().setValue( person,
                                                                    cheese );
        // demonstrating primitive type support
        personFact.getField( "age" ).getFieldAccessor().setIntValue( person,
                                                                     7 );

        // just documenting toString() result:
        //        assertEquals( "Person( age=7, likes=Cheese( type=stilton ) )",
        //                      person.toString() );
View Full Code Here

TOP

Related Classes of org.drools.rule.FactType

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.