mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-12-22 23:41:09 +00:00
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:
parent
f768082450
commit
ee38eb5263
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user