00001 /* 00002 * ConnectionObserver.java 00003 * 00004 * Created on 14 giugno 2005, 22.48 00005 * 00006 * Rappresenta un Observer per la classe ConnectionSet, il pool di connessioni 00007 * attive sul Server. L'aggiunta o la rimozione di una connessione rappresenta 00008 * un "evento", che viene notificato a questa classe attraverso una chiamata al 00009 * suo metodo update. All'interno di update si identifica l'evento che ha 00010 * scatenato la notifica e si richiama l'opportuno handler, ossia, un metodo 00011 * dell'interfaccia ConnectionEventHandler 00012 */ 00013 00014 package org.jaebi.midlet.bt; 00015 00016 import org.jaebi.midlet.util.Observable; 00017 import org.jaebi.midlet.util.Observer; 00018 00023 public class ConnectionObserver implements Observer{ 00024 ConnectionEventHandler handler; 00025 00027 public ConnectionObserver(ConnectionEventHandler handler) { 00028 this.handler = handler; 00029 } 00030 00031 public void update(Observable o, Object arg){ 00032 ConnectionSet connectionSet = (ConnectionSet) o; 00033 ConnectionEvent event = (ConnectionEvent) arg; 00034 00035 switch(event.getEvent()){ 00036 case ConnectionEvent.CONNECTION_ADDED: 00037 handler.connectionAdded(event.getConnection()); 00038 break; 00039 00040 case ConnectionEvent.CONNECTION_REMOVED: 00041 handler.connectionRemoved(event.getConnection()); 00042 break; 00043 } 00044 00045 } 00046 00047 }