You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrp4j-dev@portals.apache.org by dl...@apache.org on 2005/08/29 22:40:09 UTC
cvs commit: ws-wsrp4j/sandbox/wsrp4j/commons-producer/src/java/org/apache/wsrp4j/commons/producer/interfaces ProviderAccess.java ConsumerRegistryAccess.java
dlouzan 2005/08/29 13:40:09
Added: sandbox/wsrp4j/commons-producer/src/java/org/apache/wsrp4j/commons/producer/interfaces
ProviderAccess.java ConsumerRegistryAccess.java
Log:
Initial commit.
Revision Changes Path
1.1 ws-wsrp4j/sandbox/wsrp4j/commons-producer/src/java/org/apache/wsrp4j/commons/producer/interfaces/ProviderAccess.java
Index: ProviderAccess.java
===================================================================
/*
* Copyright 2003-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wsrp4j.commons.producer.interfaces;
import java.util.Properties;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.apache.wsrp4j.commons.producer.provider.interfaces.Provider;
import org.apache.wsrp4j.commons.producer.provider.interfaces.ProviderFactory;
import org.apache.wsrp4j.commons.util.Utility;
/**
* This class provides a static method to access the Provider component.
* Reads in the file "WSRPServices.properties".
*
* @author <a href="mailto:stefan.behl@de.ibm.com">Stefan Behl</a>
* @version $Id: ProviderAccess.java,v 1.1 2005/08/29 20:40:09 dlouzan Exp $
*/
public class ProviderAccess {
// the name of the .properties file
private static String WSRP_SERVICES = "WSRPServices.properties";
// property name of the provider factory
private static String PROVIDER_FACTORY = "provider.factory";
// the content of the properties file
private static Properties pFactories;
// holds the instance of the provider after initializing
private static Provider provider;
// log and trace support
private static Logger logger =
LogManager.getLogManager().getLogger(ProviderAccess.class);
/**
* Fetches a Provider-instance utilizing the read ProviderFactory and
* returns it.
*
* @return A Provider-interface.
*/
public static Provider getProvider() throws WSRPException {
String MN = "getProvider";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
if (provider == null) {
// get provider
ProviderFactory factory =
(ProviderFactory) getFactory(PROVIDER_FACTORY);
provider = factory.getProvider();
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return provider;
}
/**
* Internal mehtod.
* Returns a configured Factory class.
* @param type java.lang.String representing the factory type.
* @return java.lang.Object
*/
private static Object getFactory(String type) throws WSRPException {
String MN = "getFactory";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
Object obj = null;
try {
pFactories = Utility.loadPropertiesFromFile(
ProviderAccess.WSRP_SERVICES);
String factoryName = (String)pFactories.get(type);
Class cl = Class.forName(factoryName);
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
obj = cl.newInstance();
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.PROVIDER_FACTORY_NOT_FOUND);
}
return obj;
}
}
1.1 ws-wsrp4j/sandbox/wsrp4j/commons-producer/src/java/org/apache/wsrp4j/commons/producer/interfaces/ConsumerRegistryAccess.java
Index: ConsumerRegistryAccess.java
===================================================================
/*
* Copyright 2003-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wsrp4j.commons.producer.interfaces;
import java.util.Properties;
import org.apache.wsrp4j.commons.exception.ErrorCodes;
import org.apache.wsrp4j.commons.exception.WSRPException;
import org.apache.wsrp4j.commons.exception.WSRPXHelper;
import org.apache.wsrp4j.commons.log.LogManager;
import org.apache.wsrp4j.commons.log.Logger;
import org.apache.wsrp4j.commons.util.Utility;
/**
* This class provides a static method to access the ConsumerRegistry.
* Reads in the file "WSRPServices.properties".
*
* @author <a href="mailto:stefan.behl@de.ibm.com">Stefan Behl</a>
* @version $Id: ConsumerRegistryAccess.java,v 1.1 2005/08/29 20:40:09 dlouzan Exp $
*/
public class ConsumerRegistryAccess {
// the name of the .properties file
private static String WSRP_SERVICES = "WSRPServices.properties";
/** String representing a factory type */
public static String CONSUMER_REGISTRY_FACTORY =
"consumer.registry.factory";
// the content of the properties file
private static Properties pFactories;
// holds an instance of a consumer registry
private static ConsumerRegistry consumerRegistry;
// log and trace support
private static Logger logger =
LogManager.getLogManager().getLogger(ConsumerRegistryAccess.class);
/**
* Fetches a ConsumerRegistry-instance utilizing the read
* ConsumerRegistryFactory and returns it.
*
* @return ConsumerRegistry-interface.
*/
public static ConsumerRegistry getConsumerRegistry() throws WSRPException {
String MN = "getConsumerRegistry";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
if (consumerRegistry == null) {
// get ConsumerRegistry
ConsumerRegistryFactory factory =
(ConsumerRegistryFactory) getFactory(
CONSUMER_REGISTRY_FACTORY);
consumerRegistry = factory.getConsumerRegistry(
ProviderAccess.getProvider());
}
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
return consumerRegistry;
}
/**
* Internal mehtod.
* Returns a configured Factory class.
* @param type java.lang.String representing the factory type.
* @return java.lang.Object
*/
private static Object getFactory(String type) throws WSRPException {
String MN = "getFactory";
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.entry(Logger.TRACE_HIGH, MN);
}
Object obj = null;
try {
pFactories = Utility.loadPropertiesFromFile(WSRP_SERVICES);
String factoryName = (String)pFactories.get(type);
Class cl = Class.forName(factoryName);
if (logger.isLogging(Logger.TRACE_HIGH)) {
logger.exit(Logger.TRACE_HIGH, MN);
}
obj = cl.newInstance();
} catch (Exception e) {
WSRPXHelper.throwX(logger, Logger.ERROR, MN,
ErrorCodes.CONSUMER_REGISTRY_FACTORY_NOT_FOUND);
}
return obj;
}
}