1
16
17
20
21 package org.apache.wsrp4j.producer;
22
23 import java.util.Properties;
24
25 import org.apache.wsrp4j.exception.ErrorCodes;
26 import org.apache.wsrp4j.exception.WSRPException;
27 import org.apache.wsrp4j.exception.WSRPXHelper;
28 import org.apache.wsrp4j.log.LogManager;
29 import org.apache.wsrp4j.log.Logger;
30 import org.apache.wsrp4j.util.Utility;
31
32
38 public class ConsumerRegistryAccess {
39
40 private static String WSRP_SERVICES = "wsrp-services.properties";
42
43
44 public static String CONSUMER_REGISTRY_FACTORY = "consumer.registry.factory";
45
46 private static Properties pFactories = null;
48
49 private static ConsumerRegistry consumerRegistry = null;
51
52 private static Logger logger = LogManager.getLogManager().getLogger(
54 ConsumerRegistryAccess.class);
55
56
62 public static ConsumerRegistry getConsumerRegistry() throws WSRPException {
63 String MN = "getConsumerRegistry";
64 if (logger.isLogging(Logger.TRACE_HIGH)) {
65 logger.entry(Logger.TRACE_HIGH, MN);
66 }
67
68 if (consumerRegistry == null) {
69 ConsumerRegistryFactory factory = (ConsumerRegistryFactory) getFactory(CONSUMER_REGISTRY_FACTORY);
71 consumerRegistry = factory.getConsumerRegistry(ProviderAccess
72 .getProvider());
73 }
74
75 if (logger.isLogging(Logger.TRACE_HIGH)) {
76 logger.exit(Logger.TRACE_HIGH, MN);
77 }
78
79 return consumerRegistry;
80 }
81
82
88 private static Object getFactory(String type) throws WSRPException {
89 String MN = "getFactory";
90 if (logger.isLogging(Logger.TRACE_HIGH)) {
91 logger.entry(Logger.TRACE_HIGH, MN);
92 }
93
94 Object obj = null;
95
96 try {
97 pFactories = Utility.loadPropertiesFromFile(WSRP_SERVICES);
98 String factoryName = (String) pFactories.get(type);
99 Class cl = Class.forName(factoryName);
100
101 if (logger.isLogging(Logger.TRACE_HIGH)) {
102 logger.exit(Logger.TRACE_HIGH, MN);
103 }
104
105 obj = cl.newInstance();
106
107 }
108 catch (Exception e) {
109
110 WSRPXHelper.throwX(logger, Logger.ERROR, MN,
111 ErrorCodes.CONSUMER_REGISTRY_FACTORY_NOT_FOUND);
112
113 }
114
115 return obj;
116 }
117 }