1 |
| package com.sourceforge.jpatterns.core.configuration; |
2 |
| |
3 |
| import com.sourceforge.jpatterns.core.configuration.exceptions.JPInitializationException; |
4 |
| import com.sourceforge.jpatterns.core.configuration.model.IJPatternsConfigBeansBuilder; |
5 |
| import com.sourceforge.jpatterns.patterns.factory.IJPFactory; |
6 |
| import com.sourceforge.jpatterns.utils.JPatternsPropsUtils; |
7 |
| import com.zmicer.utils.LoggingUtils; |
8 |
| import org.apache.log4j.Logger; |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| public class PropertiesBasedFactory |
25 |
| { |
26 |
| |
27 |
| |
28 |
| |
29 |
| final public static Logger LOG = Logger.getLogger(PropertiesBasedFactory.class); |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| private static PropertiesBasedFactory FACTORY; |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| private IJPConfigurator m_jpConfigurator = null; |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| private static IPropertiesManager propertiesManager; |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
1
| private PropertiesBasedFactory()
|
54 |
| { |
55 |
1
| super();
|
56 |
| } |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
880
| public synchronized static PropertiesBasedFactory getInstance()
|
62 |
| { |
63 |
880
| if (null != FACTORY )
|
64 |
| { |
65 |
879
| return FACTORY;
|
66 |
| } |
67 |
1
| try
|
68 |
| { |
69 |
1
| FACTORY = new PropertiesBasedFactory();
|
70 |
1
| return FACTORY;
|
71 |
| } |
72 |
| catch (Throwable t) |
73 |
| { |
74 |
0
| LoggingUtils.logException(LOG, t, null, PropertiesBasedFactory.class);
|
75 |
0
| throw new JPInitializationException("Cannot retreive instance of PropertyBasedFactory class: " +t.getMessage());
|
76 |
| } |
77 |
| } |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
689
| public IPropertiesManager getPropertiesManager()
|
83 |
| { |
84 |
689
| if (null != propertiesManager)
|
85 |
| { |
86 |
688
| return propertiesManager;
|
87 |
| } |
88 |
| else |
89 |
| { |
90 |
1
| try
|
91 |
| { |
92 |
1
| propertiesManager = JPatternsPropsUtils.getPropertiesManagerImplementation();
|
93 |
1
| return propertiesManager;
|
94 |
| } |
95 |
| catch (Throwable t) |
96 |
| { |
97 |
0
| LoggingUtils.logException(LOG, t, null, PropertiesBasedFactory.class);
|
98 |
0
| throw new JPInitializationException("Cannot instantiate IPropertiesManager implementation: " +t.getMessage());
|
99 |
| } |
100 |
| } |
101 |
| } |
102 |
| |
103 |
| |
104 |
| |
105 |
| |
106 |
| |
107 |
| |
108 |
37
| public IJPConfigurator getJPConfigurator() throws JPInitializationException
|
109 |
| { |
110 |
37
| if (null == m_jpConfigurator)
|
111 |
| { |
112 |
18
| m_jpConfigurator = (IJPConfigurator) getPropertiesManager().getBundledObject(IJPConfigurator.class);
|
113 |
| } |
114 |
37
| return m_jpConfigurator;
|
115 |
| } |
116 |
| |
117 |
| |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
| |
123 |
191
| public IJPatternsConfigBeansBuilder getJPatternsConfigBaseBeanBuilder() throws JPInitializationException
|
124 |
| { |
125 |
191
| return (IJPatternsConfigBeansBuilder) getPropertiesManager().getBundledObject(IJPatternsConfigBeansBuilder.class);
|
126 |
| } |
127 |
| |
128 |
| |
129 |
| |
130 |
| |
131 |
166
| public void cleanImplementations()
|
132 |
| { |
133 |
166
| m_jpConfigurator = null;
|
134 |
| } |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
14
| public IJPFactory instantiateFactory()
|
140 |
| { |
141 |
14
| return (IJPFactory) getPropertiesManager().getBundledObject(IJPFactory.class);
|
142 |
| } |
143 |
| } |