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( );
nestedClassPosition = type.indexOf( '$' );
if ( nestedClassPosition != -1 )
{
type = type.substring( 0,
nestedClassPosition );
clazz = cl.loadClass( type );
}
if ( type.indexOf( "java.lang" ) == -1 )
{
dotPosition = type.lastIndexOf( '.' );
if ( dotPosition != -1 )
{
type = type.substring( dotPosition + 1 );
}
dict.setdefault( new PyString( type.intern( ) ),
Py.java2py( clazz ) );
}
}
WorkingMemory workingMemory = tuple.getWorkingMemory( );
dict.setdefault( new PyString( "drools".intern( ) ),
Py.java2py( new DefaultKnowledgeHelper( this.rule,
tuple ) ) );
Map appDataMap = workingMemory.getApplicationDataMap( );
for ( Iterator keyIter = appDataMap.keySet( ).iterator( ); keyIter.hasNext( ); )
{
String key = (String) keyIter.next( );
Object value = appDataMap.get( key );
dict.setdefault( new PyString( key.intern( ) ),
Py.java2py( value ) );
clazz = value.getClass( );
type = clazz.getName( );
nestedClassPosition = type.indexOf( '$' );
if ( nestedClassPosition != -1 )
{
type = type.substring( 0,
nestedClassPosition );
clazz = cl.loadClass( type );
}
if ( type.indexOf( "java.lang" ) == -1 )
{
dotPosition = type.lastIndexOf( '.' );
if ( dotPosition != -1 )
{
type = type.substring( dotPosition + 1 );
}
dict.setdefault( new PyString( type.intern( ) ),
Py.java2py( clazz ) );
}
}
}