1 /**
2 *
3 */
4 package ar.com.jiji.kaya.reports;
5
6 import ar.com.jiji.kaya.reflect.ReflectionService;
7 import ar.com.jiji.kaya.utils.ValidateUtils;
8
9 /**
10 * Crea un factory para obtener data sources para los reportes.
11 *
12 * TODO: documentar y hacer tests
13 *
14 * @author lparra
15 *
16 */
17 public class AbstractReportDSFactory {
18
19 private static Class<? extends ReportDSFactory> factoryClass;
20
21 private static ReportDSFactory factory;
22
23 private AbstractReportDSFactory() {
24 }
25
26 /**
27 * Devuelve la instancia del factory usado. Si nunca se llamo crea una nueva
28 * instancia de <code>factoryClass</code>.
29 *
30 * @return
31 * @see #setFactoryClass(Class)
32 */
33 public static synchronized ReportDSFactory getFactory() {
34 if (factory == null)
35 factory = createFactory();
36 return factory;
37 }
38
39 private static ReportDSFactory createFactory() {
40 ValidateUtils.notNull(factoryClass);
41 return (ReportDSFactory) ReflectionService.newInstance(factoryClass);
42 }
43
44 public static Class<? extends ReportDSFactory> getFactoryClass() {
45 return factoryClass;
46 }
47
48 /**
49 * Setea la clase del factory a usar.
50 *
51 * @param factoryClass
52 */
53 public static void setFactoryClass(
54 Class<? extends ReportDSFactory> factoryClass) {
55 AbstractReportDSFactory.factoryClass = factoryClass;
56 }
57 }