miércoles, diciembre 05, 2012

Unexpected global drools.common.AbstractWorkingMemory.

java.lang.RuntimeException: Unexpected global [testDao]
        at org.drools.common.AbstractWorkingMemory.setGlobal(AbstractWorkingMemory.java:588)

Este error no es facil de entender hasta que uno ve el codigo fuente.

http://www.docjar.com/html/api/org/drools/common/AbstractWorkingMemory.java.html

Mirando el codigo fuente se ve el motivo en la linea 363 y 367.

354     public void setGlobal(final String identifier,
355                           final Object value) {
356         // Cannot set null values
357         if ( value == null ) {
358             return;
359         }
360 
361         try {
362             this.lock.lock();
363             // Make sure the global has been declared in the RuleBase
364             final Map globalDefintions = this.ruleBase.getGlobals();
365             final Class type = (Class) globalDefintions.get( identifier );
366             if ( (type == null) ) {
367                 throw new RuntimeException( "Unexpected global [" + identifier + "]" );
368             } else if ( !type.isInstance( value ) ) {
369                 throw new RuntimeException( "Illegal class for global. " + "Expected [" + type.getName() + "], " + "found [" + value.getClass().getName() + "]." );
370 
371             } else {
372                 this.globalResolver.setGlobal( identifier,
373                                                value );
374             }
375         } finally {
376             this.lock.unlock();
377         }
378     }

Así que el problema es muy simple:

Se marca error si se trata de cargar una variable Global que no se haya declarado en el archivo DRL.  O sea que solo hay que incluir en la Regla de Negocio la linea:

global mx.t2i.gnosis.GenericDao testDao;

Eso es todo,