Package org.drools.factmodel.traits

Examples of org.drools.factmodel.traits.TraitableBean



        Collection y = ksession2.getObjects();
        assertEquals( 3, 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.factmodel.traits.Thing" ) );
        assertNotNull( core.getTrait( "org.drools.trait.test.Mask" ) );

    }
View Full Code Here



    public <T, K> T don( K core, Class<T> trait, boolean logical ) {
        TraitFactory builder = new TraitFactory( this.getKnowledgeRuntime().getKnowledgeBase() );

        TraitableBean inner;
        if ( core instanceof TraitableBean) {
            inner = (TraitableBean) core;
        } else {
            CoreWrapper<K> wrapper = builder.getCoreWrapper( core.getClass() );
            if ( wrapper == null ) {
                throw new UnsupportedOperationException( "Error: cannot apply a trait to non-traitable class " + core.getClass() );
            }
            wrapper.init( core );
            inner = wrapper;
        }


        T thing = (T) builder.getProxy( inner, trait );

        if ( ! inner.hasTrait( Thing.class.getName() ) ) {
            insert( don( inner, Thing.class, false ) );
        }

        if ( logical ) {
            insertLogical( thing );
View Full Code Here


    public <T, K> T don( K core, Class<T> trait, boolean logical ) {
        TraitFactory builder = new TraitFactory( this.getKnowledgeRuntime().getKnowledgeBase() );

        TraitableBean inner;
        if ( core instanceof TraitableBean) {
            inner = (TraitableBean) core;
        } else {
            CoreWrapper<K> wrapper = builder.getCoreWrapper( core.getClass() );
            if ( wrapper == null ) {
                throw new UnsupportedOperationException( "Error: cannot apply a trait to non-traitable class " + core.getClass() );
            }
            wrapper.init( core );
            inner = wrapper;

            this.update( getFactHandle( core ), inner );
        }


        T thing;
        if ( inner.hasTrait( trait.getName() ) ) {
            return (T) inner.getTrait( trait.getName() );
        } else {
            thing = (T) builder.getProxy( inner, trait );
        }

        if ( ! inner.hasTrait( Thing.class.getName() ) ) {
            insert( don( inner, Thing.class, false ) );
        }

        if ( logical ) {
            insertLogical( thing );
View Full Code Here

TOP

Related Classes of org.drools.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.