Package org.drools.spi

Examples of org.drools.spi.Importer


                cl = getClass( ).getClassLoader( );
                context.put( "smf-classLoader",
                             cl );
            }

            Importer importer = rule.getImporter( );
            clazz = importer.importClass( cl,
                                          className );

            // make sure field getter exists
            clazz.getMethod( "get" + fieldName.toUpperCase( ).charAt( 0 ) + fieldName.substring( 1 ),
                             (Class[]) null );
View Full Code Here


                cl = getClass( ).getClassLoader( );
                context.put( "smf-classLoader",
                             cl );
            }

            Importer importer = rule.getImporter( );
            clazz = importer.importClass( cl,
                                          className );
        }
        catch ( ClassNotFoundException e )
        {
            throw new FactoryException( e.getMessage( ) );
View Full Code Here

        super( name );
    }

    public void setUp() throws Exception
    {
        Importer importer = new DefaultImporter( );
        importer.addImport( new BaseImportEntry( "from java.math import *" ) );
        importer.addImport( new BaseImportEntry( "from org.drools.smf import SMFTestFrameWork" ) );
        importer.addImport( new BaseImportEntry( "from org.drools.smf.SMFTestFrameWork import Cheese" ) );
        super.setUp( "python",
                     importer );
    }
View Full Code Here

                cl = getClass( ).getClassLoader( );
                context.put( "smf-classLoader",
                             cl );
            }

            Importer importer = ruleSet.getImporter( );
            clazz = importer.importClass( cl,
                                          className );
        }
        catch ( ClassNotFoundException e )
        {
            throw new FactoryException( e.getMessage( ) );
View Full Code Here

public class DefaultImporterTest extends TestCase
{

    public void testStaticImport()
    {
        Importer importer = new DefaultImporter( );
        importer.addImport( new DefaultImportEntry( "java.util.HashMap" ) );

        /* static import, should work */
        ClassLoader cl = getClass( ).getClassLoader( );
        try
        {
            Class clazz = importer.importClass( cl,
                                                "HashMap" );
            assertSame( java.util.HashMap.class,
                        clazz );
        }
        catch ( ClassNotFoundException e )
        {
            fail( e.getMessage( ) );
        }
        catch ( Error e )
        {
            fail( e.getMessage( ) );
        }

        /* static import, should fail */
        try
        {
            Class clazz = importer.importClass( cl,
                                                "ArrayList" );
            fail( "Class ArrayList should not be found" );
        }
        catch ( ClassNotFoundException e )
        {
View Full Code Here

        }
    }

    public void testDynamicImport()
    {
        Importer importer = new DefaultImporter( );
        importer.addImport( new DefaultImportEntry( "java.util.*" ) );

        ClassLoader cl = getClass( ).getClassLoader( );

        /* dynamic import, should work */
        try
        {
            Class clazz = importer.importClass( cl,
                                                "HashMap" );
            assertSame( java.util.HashMap.class,
                        clazz );
        }
        catch ( ClassNotFoundException e )
        {
            fail( e.getMessage( ) );
        }
        catch ( Error e )
        {
            fail( e.getMessage( ) );
        }

        /* dynamic import, should throw ClassNotFoundException */
        try
        {
            Class clazz = importer.importClass( cl,
                                                "NoneExistingClass" );
            fail( "Class NoneExistingClass should not be found" );
        }
        catch ( ClassNotFoundException e )
        {
            // correct exception, so pass
        }
        catch ( Error e )
        {
            fail( "Incorrect Error exception, should have been ClassNotFound" );
        }

        /* dynamic import, should fail and throw Error */
        importer.addImport( new DefaultImportEntry( "java.awt.*" ) );
        try
        {
            Class clazz = importer.importClass( cl,
                                                "List" );
            fail( "Should fail as imports are ambiguous for List" );
        }
        catch ( ClassNotFoundException e )
        {
            fail( "Incorrect ClassNotFoundException exception, should have been Error" );
        }
        catch ( Error e )
        {
            // correct exception, so pass
        }

        /* recheck that HashMap still works */
        try
        {
            Class clazz = importer.importClass( cl,
                                                "HashMap" );
            assertSame( java.util.HashMap.class,
                        clazz );
        }
        catch ( ClassNotFoundException e )
View Full Code Here

    }

    public void testgetImports()
    {
        Importer importer = new DefaultImporter( );

        // assertSame(importer.)

        importer.addImport( new DefaultImportEntry( "java.awt.*" ) );
        importer.addImport( new DefaultImportEntry( "java.util.Map" ) );

        Set set;
        set = importer.getImports( );
        assertTrue( set.contains( "java.awt.*" ) );
        assertTrue( set.contains( "java.util.Map" ) );
        assertEquals( 2,
                      set.size( ) );
    }
View Full Code Here

        ImportEntryFactory factory = module.getImportEntryFactory( localName );

        Configuration config = ruleSetReader.endConfiguration( );
        ImportEntry importEntry;
        Importer importer = ruleSetReader.getRuleSet().getImporter();
        try
        {
            importEntry = factory.newImportEntry( this.ruleSetReader.getRuleSet( ),
                                                  this.ruleSetReader.getFactoryContext( ),
                                                  config );
            importer.addImport( importEntry );
        }
        catch ( FactoryException e )
        {
            throw new SAXParseException( "error constructing import",
                    ruleSetReader.getLocator( ), e );
View Full Code Here

                                    "map" );

        final RuleSet ruleSet = new RuleSet( "test RuleSet",
                                             ruleBaseContext );

        Importer importer = new DefaultImporter( );
        ruleSet.setImporter( importer );

        ApplicationDataFactory factory = new BaseApplicationDataFactory( );

        ApplicationData applicationData = factory.newApplicationData( ruleSet,
View Full Code Here

                                    "map" );

        final RuleSet ruleSet = new RuleSet( "test RuleSet",
                                             ruleBaseContext );

        Importer importer = new DefaultImporter( );
        importer.addImport( new DefaultImportEntry( "java.util.HashMap" ) );
        ruleSet.setImporter( importer );

        ApplicationDataFactory factory = new BaseApplicationDataFactory( );

        ApplicationData applicationData = factory.newApplicationData( ruleSet,
View Full Code Here

TOP

Related Classes of org.drools.spi.Importer

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.