1 | |
package org.apache.ojb.broker.core; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
import org.apache.ojb.broker.OJBRuntimeException; |
19 | |
import org.apache.ojb.broker.util.ClassHelper; |
20 | |
import org.apache.ojb.broker.util.configuration.Configuration; |
21 | |
import org.apache.ojb.broker.util.configuration.Configurator; |
22 | |
import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator; |
23 | |
import org.apache.ojb.broker.util.logging.Logger; |
24 | |
import org.apache.ojb.broker.util.logging.LoggerFactory; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class PersistenceBrokerFactoryFactory |
32 | |
{ |
33 | |
private static Logger log = LoggerFactory.getBootLogger(); |
34 | |
|
35 | |
private static final String PBF_KEY = "PersistenceBrokerFactoryClass"; |
36 | |
private static PersistenceBrokerFactoryIF singleton = init(); |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public static PersistenceBrokerFactoryIF instance() |
42 | |
{ |
43 | |
return singleton; |
44 | |
} |
45 | |
|
46 | |
private static PersistenceBrokerFactoryIF init() |
47 | |
{ |
48 | |
if (log.isDebugEnabled()) log.debug("Instantiate PersistenceBrokerFactory"); |
49 | |
Class pbfClass = null; |
50 | |
try |
51 | |
{ |
52 | |
Configurator configurator = OjbConfigurator.getInstance(); |
53 | |
Configuration config = configurator.getConfigurationFor(null); |
54 | |
pbfClass = config.getClass(PBF_KEY, null); |
55 | |
if(pbfClass == null) |
56 | |
{ |
57 | |
log.error("Creation of PersistenceBrokerFactory (PBF) instance failed, can't get PBF class object"); |
58 | |
throw new OJBRuntimeException("Property for key '" + PBF_KEY + "' can not be found in properties file"); |
59 | |
} |
60 | |
PersistenceBrokerFactoryIF result = (PersistenceBrokerFactoryIF) ClassHelper.newInstance(pbfClass); |
61 | |
configurator.configure(result); |
62 | |
log.info("PersistencebrokerFactory class instantiated: " + result); |
63 | |
return result; |
64 | |
} |
65 | |
catch (Exception e) |
66 | |
{ |
67 | |
if(e instanceof OJBRuntimeException) |
68 | |
{ |
69 | |
throw (OJBRuntimeException) e; |
70 | |
} |
71 | |
else |
72 | |
{ |
73 | |
throw new OJBRuntimeException("Error while instantiation of PersistenceBrokerFactory class", e); |
74 | |
} |
75 | |
} |
76 | |
} |
77 | |
} |