Module Server : ajout de listeners à SaleService; Ajout d'un package contenant les clss et intrfc dédiées aux listeners du service

This commit is contained in:
Notmoo 2017-07-30 22:20:32 +02:00
parent f768082450
commit ee38eb5263
5 changed files with 76 additions and 1 deletions

View File

@ -2,6 +2,9 @@ package com.pqt.server.module.sale;
import com.pqt.core.entities.sale.Sale;
import com.pqt.server.exception.ServerQueryException;
import com.pqt.server.module.sale.listeners.ISaleFirerer;
import com.pqt.server.module.sale.listeners.ISaleListener;
import com.pqt.server.module.sale.listeners.SimpleSaleFirerer;
import com.pqt.server.module.stock.StockService;
//TODO écrire Javadoc
@ -9,17 +12,28 @@ import com.pqt.server.module.stock.StockService;
public class SaleService {
private ISaleDao dao;
private ISaleFirerer eventFirerer;
public SaleService(StockService stockService) {
dao = new NoRevertFileSaleDao(stockService);
eventFirerer = new SimpleSaleFirerer();
}
public long submitSale(Sale sale) throws ServerQueryException {
return dao.submitSale(sale);
long id = dao.submitSale(sale);
if(id!=-1) eventFirerer.fireSaleValidatedEvent(sale);
return id;
}
public void submitSaleRevert(long id) throws ServerQueryException {
dao.submitSaleRevert(id);
}
public void addListener(ISaleListener l) {
eventFirerer.addListener(l);
}
public void removeListener(ISaleListener l){
eventFirerer.addListener(l);
}
}

View File

@ -0,0 +1,11 @@
package com.pqt.server.module.sale.listeners;
import com.pqt.core.entities.sale.Sale;
public interface ISaleFirerer {
void addListener(ISaleListener l);
void removeListener(ISaleListener l);
void fireSaleValidatedEvent(Sale sale);
}

View File

@ -0,0 +1,9 @@
package com.pqt.server.module.sale.listeners;
import com.pqt.core.entities.sale.Sale;
import java.util.EventListener;
public interface ISaleListener extends EventListener{
void onSaleValidatedEvent(Sale sale);
}

View File

@ -0,0 +1,10 @@
package com.pqt.server.module.sale.listeners;
import com.pqt.core.entities.sale.Sale;
public class SaleListenerAdapter implements ISaleListener {
@Override
public void onSaleValidatedEvent(Sale sale) {
}
}

View File

@ -0,0 +1,31 @@
package com.pqt.server.module.sale.listeners;
import com.pqt.core.entities.sale.Sale;
import javax.swing.event.EventListenerList;
public class SimpleSaleFirerer implements ISaleFirerer {
private EventListenerList listeners;
public SimpleSaleFirerer() {
listeners = new EventListenerList();
}
@Override
public void addListener(ISaleListener l) {
listeners.add(ISaleListener.class, l);
}
@Override
public void removeListener(ISaleListener l) {
listeners.remove(ISaleListener.class, l);
}
@Override
public void fireSaleValidatedEvent(Sale sale) {
for(ISaleListener l : listeners.getListeners(ISaleListener.class)){
l.onSaleValidatedEvent(sale);
}
}
}