Package org.drools.core.factmodel.traits

Examples of org.drools.core.factmodel.traits.TraitableBean


            if ( cachedValue != literal) {
                cachedValue = literal;
                cacheLiteral( literal, workingMemory );
            }

            TraitableBean core;
            if ( objectValue == null ) {
                return this.getOperator().isNegated();
            } if ( objectValue instanceof Thing ) {
                Thing thing = (Thing) objectValue;
                core = (TraitableBean) thing.getCore();
                BitSet code = core.getCurrentTypeCode();
                if ( code != null ) {
                    return this.getOperator().isNegated() ^ isA( code, cachedLiteral );
                } else {
                    return this.getOperator().isNegated() ^ hasTrait( core, literal );
                }
            } else if ( objectValue instanceof TraitableBean ) {
                core = (TraitableBean) objectValue;
                BitSet code = core.getCurrentTypeCode();
                if ( code != null ) {
                    return this.getOperator().isNegated() ^ isA( code, cachedLiteral );
                } else {
                    return this.getOperator().isNegated() ^ hasTrait( core, literal );
                }
            } else {
                core = lookForWrapper( objectValue, workingMemory );
                if ( core == null ) {
                    return this.getOperator().isNegated();
                }
                BitSet code = core.getCurrentTypeCode();
                if ( code != null ) {
                    return this.getOperator().isNegated() ^ isA( code, cachedLiteral );
                } else {
                    return this.getOperator().isNegated() ^ hasTrait( core, literal );
                }
View Full Code Here


                        // property reactivity may block trait proxies which have been asserted and then immediately updated because of another "don"
                        // however, PR must be disabled only once for each OTN: that is, a proxy will not pass an OTN if one of its ancestors can also pass it

                        // Example: given classes A <- B <-C, at OTN A, a proxy c can only pass if no proxy b exists

                        TraitableBean txBean = (TraitableBean) proxy.getObject();
                        TraitTypeMap tMap = (TraitTypeMap) txBean._getTraitMap();
                        Collection<Thing> x = tMap.immediateParents( this.typeMask );
                        Thing k = x.iterator().next();

                        long originalMask = context.getModificationMask();
                        if ( ! k.isTop() ) {
View Full Code Here


        Collection x = ksession2.getObjects();
        assertEquals( 3, x.size() );

        TraitableBean core = null;
        for ( Object o : x ) {
            if ( o instanceof TraitableBean ) {
                core = (TraitableBean) o;
                break;
            }
        }
        assertNotNull( core );
        assertEquals( 2, core._getDynamicProperties().size() );
        assertNotNull( core.getTrait( "org.drools.trait.test.Mask" ) );
        assertNotNull( core.getTrait( "org.drools.trait.test.Cloak" ) );

    }
View Full Code Here


        Collection x = ksession2.getObjects();
        assertEquals( 3, x.size() );

        TraitableBean core = null;
        for ( Object o : x ) {
            if ( o instanceof TraitableBean ) {
                core = (TraitableBean) o;
                break;
            }
        }
        assertNotNull( core );
        assertEquals( 2, core._getDynamicProperties().size() );
        assertNotNull( core.getTrait( "org.drools.trait.test.Mask2" ) );
        assertNotNull( core.getTrait( "org.drools.trait.test.Cloak2" ) );

    }
View Full Code Here

                list.size() );
        int id = ksession.getId();


        Collection yOld = ksession.getObjects();
        TraitableBean coreOld = null;
        for ( Object o : yOld ) {
            if ( o instanceof TraitableBean ) {
                coreOld = (TraitableBean) o;
                break;
            }
        }
        assertNotNull( coreOld );


        StatefulKnowledgeSession ksession2 = JPAKnowledgeService.loadStatefulKnowledgeSession( id, kbase, null, env );

        ksession2.fireAllRules();


        Collection y = ksession2.getObjects();
        assertEquals( 2, y.size() );

        TraitableBean core = null;
        for ( Object o : y ) {
            if ( o instanceof TraitableBean ) {
                core = (TraitableBean) o;
                break;
            }
        }
        assertNotNull( core );
        assertEquals( 1, core._getDynamicProperties().size() );
        assertNotNull( core.getTrait( "org.drools.trait.test.Mask" ) );

    }
View Full Code Here

            }
        }
    }

    private void updateTraits( Object object, long mask, Thing originator, Class<?> modifiedClass ) {
        TraitableBean txBean = (TraitableBean) object;

        Collection<Thing> px = txBean.getMostSpecificTraits();
        BitSet veto = null;
        if ( originator != null ) {
            veto = (BitSet) ((TraitProxy) originator).getTypeCode().clone();
        }
View Full Code Here

            }
        }
    }

    private void updateTraits( Object object, long mask, Thing originator, Class<?> modifiedClass ) {
        TraitableBean txBean = (TraitableBean) object;

        Collection<Thing> px = txBean.getMostSpecificTraits();
        BitSet veto = null;
        if ( originator != null ) {
            veto = (BitSet) ((TraitProxy) originator).getTypeCode().clone();
        }
View Full Code Here

        TraitFactory tFactory = ((ReteooRuleBase) ((KnowledgeBaseImpl) kb).getRuleBase()).getConfiguration().getComponentFactory().getTraitFactory();

        try {
            FactType impClass = kb.getFactType( "org.drools.compiler.trait.test",
                                                "Imp" );
            TraitableBean imp = (TraitableBean) impClass.newInstance();
            Class trait = kb.getFactType( "org.drools.compiler.trait.test",
                                          "Student" ).getFactClass();

            TraitProxy proxy = (TraitProxy) tFactory.getProxy( imp,
                                                               trait );

            Map<String, Object> virtualFields = imp._getDynamicProperties();
            Map<String, Object> wrapper = proxy.getFields();

            wrapper.put( "name",
                         "john" );
View Full Code Here

        TraitFactory tFactory = ((ReteooRuleBase) ((KnowledgeBaseImpl) kb).getRuleBase()).getConfiguration().getComponentFactory().getTraitFactory();

        try {
            FactType impClass = kb.getFactType( "org.drools.compiler.trait.test",
                                                "Imp" );
            TraitableBean imp = (TraitableBean) impClass.newInstance();
            impClass.set( imp,
                          "name",
                          "aaa" );

            Class trait = kb.getFactType( "org.drools.compiler.trait.test",
                                          "Student" ).getFactClass();
            Class trait2 = kb.getFactType( "org.drools.compiler.trait.test",
                                           "Role" ).getFactClass();

            assertNotNull( trait );
            TraitProxy proxy = (TraitProxy) tFactory.getProxy( imp,
                                                               trait );
            proxy.getFields().put( "field",
                                   "xyz" );
            //            proxy.getFields().put("name", "aaa");

            assertNotNull( proxy );

            TraitProxy proxy2 = (TraitProxy) tFactory.getProxy( imp,
                                                                trait );
            assertSame( proxy2,
                        proxy );

            TraitProxy proxy3 = (TraitProxy) tFactory.getProxy( imp,
                                                                trait2 );
            assertNotNull( proxy3 );
            assertEquals( "xyz",
                          proxy3.getFields().get( "field" ) );
            assertEquals( "aaa",
                          proxy3.getFields().get( "name" ) );

            TraitableBean imp2 = (TraitableBean) impClass.newInstance();
            impClass.set( imp2,
                          "name",
                          "aaa" );
            TraitProxy proxy4 = (TraitProxy) tFactory.getProxy( imp2,
                                                                trait );
View Full Code Here


        try {
            FactType impClass = kb.getFactType( "org.drools.compiler.trait.test",
                                                "Imp" );
            TraitableBean imp = (TraitableBean) impClass.newInstance();
            FactType traitClass = kb.getFactType( "org.drools.compiler.trait.test",
                                                  "Student" );
            Class trait = traitClass.getFactClass();
            TraitProxy proxy = (TraitProxy) tFactory.getProxy( imp,
                                                               trait );

            Map<String, Object> virtualFields = imp._getDynamicProperties();
            Map<String, Object> wrapper = proxy.getFields();
            assertEquals( 3,
                          wrapper.size() );
            assertEquals( 1,
                          virtualFields.size() );

            impClass.set(imp,
                         "name",
                         "john");
            assertEquals( 3,
                          wrapper.size() );
            assertEquals( 1,
                          virtualFields.size() );

            proxy.getFields().put( "school",
                                   "skol" );
            assertEquals( 3,
                          wrapper.size() );
            assertEquals( 1,
                          virtualFields.size() );

            proxy.getFields().put( "surname",
                                   "xxx" );
            assertEquals( 4,
                          wrapper.size() );
            assertEquals( 2,
                          virtualFields.size() );

            //            FactType indClass = kb.getFactType("org.drools.compiler.trait.test","Entity");
            //            TraitableBean ind = (TraitableBean) indClass.newInstance();
            TraitableBean ind = new Entity();

            TraitProxy proxy2 = (TraitProxy) tFactory.getProxy( ind,
                                                                trait );

            Map virtualFields2 = ind._getDynamicProperties();
            Map wrapper2 = proxy2.getFields();
            assertEquals( 3,
                          wrapper2.size() );
            assertEquals( 3,
                          virtualFields2.size() );

            traitClass.set( proxy2,
                            "name",
                            "john" );
            assertEquals( 3,
                          wrapper2.size() );
            assertEquals( 3,
                          virtualFields2.size() );

            proxy2.getFields().put( "school",
                                    "skol" );
            assertEquals( 3,
                          wrapper2.size() );
            assertEquals( 3,
                          virtualFields2.size() );

            proxy2.getFields().put( "surname",
                                    "xxx" );
            assertEquals( 4,
                          wrapper2.size() );
            assertEquals( 4,
                          virtualFields2.size() );

            FactType traitClass2 = kb.getFactType( "org.drools.compiler.trait.test",
                                                   "Role" );
            Class trait2 = traitClass2.getFactClass();
            //            TraitableBean ind2 = (TraitableBean) indClass.newInstance();
            TraitableBean ind2 = new Entity();

            TraitProxy proxy99 = (TraitProxy) tFactory.getProxy( ind2,
                                                                 trait2 );

            proxy99.getFields().put( "surname",
View Full Code Here

TOP

Related Classes of org.drools.core.factmodel.traits.TraitableBean

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.