| ConsumerRegistryAccess.java |
1 /*
2 * Copyright 2000-2001,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /*
18
19 */
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 /**
33 * This class provides a static method to access the ConsumerRegistry.
34 * Reads in the file "wsrp-services.properties".
35 *
36 * @author <a href="mailto:stefan.behl@de.ibm.com">Stefan Behl</a>
37 */
38 public class ConsumerRegistryAccess {
39
40 // the name of the .properties file
41 private static String WSRP_SERVICES = "wsrp-services.properties";
42
43 /** String representing a factory type */
44 public static String CONSUMER_REGISTRY_FACTORY = "consumer.registry.factory";
45
46 // the content of the properties file
47 private static Properties pFactories = null;
48
49 // holds an instance of a consumer registry
50 private static ConsumerRegistry consumerRegistry = null;
51
52 // log and trace support
53 private static Logger logger = LogManager.getLogManager().getLogger(
54 ConsumerRegistryAccess.class);
55
56 /**
57 * Fetches a ConsumerRegistry-instance utilizing the read
58 * ConsumerRegistryFactory and returns it.
59 *
60 * @return ConsumerRegistry-interface.
61 */
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 // get ConsumerRegistry
70 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 /**
83 Internal mehtod.
84 Returns a configured Factory class.
85 @param type java.lang.String representing the factory type.
86 @return java.lang.Object
87 */
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 }