ItEr20S04ArquitecturaServidorItEr19S04: Removing WorkReportsDAORegistry and creating a general Registry intended to replace all Registries.

This commit is contained in:
Óscar González Fernández 2009-08-07 17:06:15 +02:00
parent c183170dda
commit 078009217b
3 changed files with 52 additions and 48 deletions

View file

@ -0,0 +1,48 @@
package org.navalplanner.business.common;
import org.navalplanner.business.workreports.daos.IWorkReportDAO;
import org.navalplanner.business.workreports.daos.IWorkReportLineDAO;
import org.navalplanner.business.workreports.daos.IWorkReportTypeDAO;
import org.springframework.beans.factory.annotation.Autowired;
/**
* A registry, AKA service locator, for objects in which dependency injection
* (DI) is not directly supported by Spring (e.g. entities) must use this class
* to access DAOs. For the rest of classes (e.g. services, tests, etc.), Spring
* DI is a more convenient option.
* @author Óscar González Fernández <ogonzalez@igalia.com>
*/
public class Registry {
private static final Registry singleton = new Registry();
@Autowired
private IWorkReportDAO workReport;
@Autowired
private IWorkReportTypeDAO workReportType;
@Autowired
private IWorkReportLineDAO workReportLine;
private Registry() {
}
public static Registry getInstance() {
return singleton;
}
public static IWorkReportDAO getWorkReportDao() {
return getInstance().workReport;
}
public static IWorkReportTypeDAO getWorkReportTypeDao() {
return getInstance().workReportType;
}
public static IWorkReportLineDAO getWorkReportLineDao() {
return getInstance().workReportLine;
}
}

View file

@ -1,44 +0,0 @@
package org.navalplanner.business.workreports.daos;
import org.springframework.beans.factory.annotation.Autowired;
/**
* A registry of WorkReports DAOs. Classes in which dependency injection (DI) is
* not directly supported by Spring (e.g. entities) must use this class to
* access resource DAOs. For the rest of classes (e.g. services, tests, etc.),
* Spring DI is a more convenient option.
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
public final class WorkReportsDAORegistry {
private static WorkReportsDAORegistry instance = new WorkReportsDAORegistry();
@Autowired
private IWorkReportDAO workReport;
@Autowired
private IWorkReportTypeDAO workReportType;
@Autowired
private IWorkReportLineDAO workReportLine;
private WorkReportsDAORegistry() {
}
public static WorkReportsDAORegistry getInstance() {
return instance;
}
public static IWorkReportDAO getWorkReportDao() {
return getInstance().workReport;
}
public static IWorkReportTypeDAO getWorkReportTypeDao() {
return getInstance().workReportType;
}
public static IWorkReportLineDAO getWorkReportLineDao() {
return getInstance().workReportLine;
}
}

View file

@ -75,12 +75,12 @@
class="org.navalplanner.business.planner.daos.PlannerDAORegistry"
factory-method="getInstance" />
<bean id="workReportsDaoRegistry"
class="org.navalplanner.business.workreports.daos.WorkReportsDAORegistry"
factory-method="getInstance" />
<bean id="advanceDaoRegistry"
class="org.navalplanner.business.advance.daos.AdvanceDAORegistry"
factory-method="getInstance" />
<bean id="registry"
class="org.navalplanner.business.common.Registry"
factory-method="getInstance" />
</beans>