⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workingmemoryimpl.java

📁 rule engine drools-2.0-beta-18
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        while ( objIter.hasNext( ) )        {            obj = objIter.next( );            if ( objectClass.isInstance( obj ) )            {                matching.add( obj );            }        }        return matching;    }    /**     * @see WorkingMemory     */    public boolean containsObject(FactHandle handle)    {        return this.objects.containsKey( ((FactHandleImpl) handle).getId( ) );    }    /**     * @see WorkingMemory     */    public FactHandle assertObject( Object object ) throws FactException    {        return assertObject( object, /*Not-Dynamic*/false );    }    public synchronized FactHandle assertObject( Object object,                                                 boolean dynamic )        throws FactException    {        FactHandle handle = ( FactHandle ) handles.get( object );        if ( handle != null )        {            return handle;        }        handle = newFactHandle( );        putObject( handle,                   object );        if ( dynamic )        {            addPropertyChangeListener( object );        }        ruleBase.assertObject( handle,                               object,                               this );        eventSupport.fireObjectAsserted( handle,                                         object );        return handle;    }    private void addPropertyChangeListener( Object object )    {        try {            Method method = object.getClass( ).getMethod( "addPropertyChangeListener",                                                          ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES );            method.invoke( object, addRemovePropertyChangeListenerArgs );        }        catch ( NoSuchMethodException e )        {            // Method addPropertyChangeListener not found,            // so Drools will be unable to process JavaBean            // PropertyChangeEvents on the asserted Object        }        catch ( IllegalArgumentException e )        {            System.err.println(                "Warning: The addPropertyChangeListener method" +                " on the class " + object.getClass() +                " does not take" +                " a simple PropertyChangeListener argument" +                " so Drools will be unable to process JavaBean" +                " PropertyChangeEvents on the asserted Object" );        }        catch ( IllegalAccessException e )        {            System.err.println(                "Warning: The addPropertyChangeListener method" +                " on the class " + object.getClass() +                " is not public" +                " so Drools will be unable to process JavaBean" +                " PropertyChangeEvents on the asserted Object" );        }        catch ( InvocationTargetException e )        {            System.err.println(                "Warning: The addPropertyChangeListener method" +                " on the class " + object.getClass() +                " threw an InvocationTargetException" +                " so Drools will be unable to process JavaBean" +                " PropertyChangeEvents on the asserted Object: " +                e.getMessage( ) );        }        catch ( SecurityException e )        {            System.err.println(                "Warning: The SecurityManager controlling the class " +                object.getClass() + " did not allow the lookup of a" +                " addPropertyChangeListener method" +                " so Drools will be unable to process JavaBean" +                " PropertyChangeEvents on the asserted Object: " +                e.getMessage( ) );        }    }    private void removePropertyChangeListener( FactHandle handle ) throws NoSuchFactObjectException    {        Object object = null;        try {            object = getObject( handle );            Method mehod = handle.getClass( ).getMethod( "removePropertyChangeListener",                                                         ADD_REMOVE_PROPERTY_CHANGE_LISTENER_ARG_TYPES );            mehod.invoke( handle,                          addRemovePropertyChangeListenerArgs );        }        catch ( NoSuchMethodException e )        {            // The removePropertyChangeListener method on the class            // was not found so Drools will be unable to            // stop processing JavaBean PropertyChangeEvents            // on the retracted Object        }        catch ( IllegalArgumentException e )        {            System.err.println(                "Warning: The removePropertyChangeListener method" +                " on the class " + object.getClass( ) +                " does not take" +                " a simple PropertyChangeListener argument" +                " so Drools will be unable to stop processing JavaBean" +                " PropertyChangeEvents on the retracted Object" );        }        catch ( IllegalAccessException e )        {            System.err.println(                "Warning: The removePropertyChangeListener method" +                " on the class " + object.getClass( ) +                " is not public" +                " so Drools will be unable to stop processing JavaBean" +                " PropertyChangeEvents on the retracted Object" );        }        catch ( InvocationTargetException e )        {            System.err.println(                "Warning: The removePropertyChangeL istener method" +                " on the class " + object.getClass() +                " threw an InvocationTargetException" +                " so Drools will be unable to stop processing JavaBean" +                " PropertyChangeEvents on the retracted Object: " +                e.getMessage( ) );        }        catch ( SecurityException e )        {            System.err.println(                "Warning: The SecurityManager controlling the class " +                object.getClass() + " did not allow the lookup of a" +                " removePropertyChangeListener method" +                " so Drools will be unable to stop processing JavaBean" +                " PropertyChangeEvents on the retracted Object: " +                e.getMessage( ) );        }    }    /**     * Associate an object with its handle.     *     * @param handle     *            The handle.     * @param object     *            The object.     */    Object putObject(FactHandle handle,                     Object object)    {        Object oldValue = this.objects.put( ( ( FactHandleImpl ) handle ).getId( ),                                            object );        this.handles.put( object,                          handle );        return oldValue;    }    Object removeObject(FactHandle handle)    {        Object object = this.objects.remove( ( ( FactHandleImpl ) handle ).getId( ) );        this.handles.remove( object  );        return object;    }    /**     * @see WorkingMemory     */    public synchronized void retractObject( FactHandle handle )        throws FactException    {        removePropertyChangeListener( handle );        ruleBase.retractObject( handle, this );        removeObject( handle );        factHandlePool.push( ( ( FactHandleImpl ) handle ).getId( ) );        eventSupport.fireObjectRetracted( handle );        ( ( FactHandleImpl ) handle ).invalidate( );    }    /**     * @see WorkingMemory     */    public synchronized void modifyObject(FactHandle handle,                                          Object object) throws FactException    {        Object originalObject = removeObject(handle);        if ( originalObject == null )        {            throw new NoSuchFactObjectException( handle );        }        putObject( handle,                    object );        this.ruleBase.modifyObject( handle,                                    object,                                    this );        this.eventSupport.fireObjectModified( handle,                                              object );    }    /**     * Retrieve the <code>JoinMemory</code> for a particular     * <code>JoinNode</code>.     *     * @param node     *            The <code>JoinNode</code> key.     *     * @return The node's memory.     */    public JoinMemory getJoinMemory(JoinNode node)    {        JoinMemory memory = (JoinMemory) this.joinMemories.get( node );        if ( memory == null )        {            memory = new JoinMemory( node.getTupleDeclarations( ),                                     node.getCommonDeclarations( ) );            this.joinMemories.put( node,                                   memory );        }        return memory;    }    public WorkingMemoryEventSupport getEventSupport()    {        return eventSupport;    }    public void dumpMemory()    {        Iterator it = this.joinMemories.keySet( ).iterator( );        while ( it.hasNext( ) )        {            ( (JoinMemory) this.joinMemories.get( it.next( ) ) ).dump( );        }    }    public void propertyChange( PropertyChangeEvent event )    {        Object object = event.getSource( );        try        {            modifyObject( getFactHandle( object ),                          object );        }        catch ( NoSuchFactHandleException e )        {            // Not a fact so unable to process the chnage event        }        catch ( FactException e )        {            throw new RuntimeException( e.getMessage( ) );        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -