001         package com.croftsoft.core.util.state;
002    
003         import java.io.Serializable;
004         import java.rmi.*;
005    
006         import com.croftsoft.core.lang.ex.*;
007    
008         /*********************************************************************
009         *
010         * An ambassador proxy for StateMulticasterRemote objects.
011         *
012         * @author
013         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
014         * @version
015         *   1998-12-05
016         *********************************************************************/
017    
018         public class  StateMulticasterAmbassador
019           implements StateMulticaster, Serializable
020         //////////////////////////////////////////////////////////////////////
021         //////////////////////////////////////////////////////////////////////
022         {
023    
024         private StateMulticasterRemote  stateMulticasterRemote;
025    
026         private transient ExceptionListener  exceptionListener;
027    
028         //////////////////////////////////////////////////////////////////////
029         //////////////////////////////////////////////////////////////////////
030    
031         public  StateMulticasterAmbassador (
032           StateMulticasterRemote  stateMulticasterRemote,
033           ExceptionListener       exceptionListener )
034         //////////////////////////////////////////////////////////////////////
035         {
036           this.stateMulticasterRemote = stateMulticasterRemote;
037           this.exceptionListener      = exceptionListener;
038         }
039    
040         public  StateMulticasterAmbassador (
041           StateMulticasterRemote  stateMulticasterRemote )
042         //////////////////////////////////////////////////////////////////////
043         {
044           this ( stateMulticasterRemote, new PrintExceptionListener ( ) );
045         }
046    
047         //////////////////////////////////////////////////////////////////////
048         //////////////////////////////////////////////////////////////////////
049    
050         public void  update ( State  state )
051         //////////////////////////////////////////////////////////////////////
052         {
053           try
054           {
055             stateMulticasterRemote.update ( state );
056           }
057           catch ( Exception  ex )
058           {
059             if ( exceptionListener != null )
060             {
061               exceptionListener.threwException ( this, ex );
062             }
063           }
064         }
065    
066         public boolean  addStateListener ( StateListener  stateListener )
067         //////////////////////////////////////////////////////////////////////
068         {
069           try
070           {
071             return stateMulticasterRemote.addStateListener ( stateListener );
072           }
073           catch ( Exception  ex )
074           {
075             if ( exceptionListener != null )
076             {
077               exceptionListener.threwException ( this, ex );
078             }
079             return false;
080           }
081         }
082    
083         public boolean  removeStateListener ( StateListener  stateListener )
084         //////////////////////////////////////////////////////////////////////
085         {
086           try
087           {
088             return
089               stateMulticasterRemote.removeStateListener ( stateListener );
090           }
091           catch ( Exception  ex )
092           {
093             if ( exceptionListener != null )
094             {
095               exceptionListener.threwException ( this, ex );
096             }
097             return false;
098           }
099         }
100    
101         //////////////////////////////////////////////////////////////////////
102         //////////////////////////////////////////////////////////////////////
103         }