
com.centurylink.mdw.provider.ProviderRegistry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mdw-common Show documentation
Show all versions of mdw-common Show documentation
MDW is a microservices based workflow framework
/*
* Copyright (C) 2017 CenturyLink, Inc.
*
* 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 com.centurylink.mdw.provider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.centurylink.mdw.java.CompiledJavaCache;
import com.centurylink.mdw.util.log.LoggerUtil;
import com.centurylink.mdw.util.log.StandardLogger;
import com.centurylink.mdw.variable.VariableTranslator;
public class ProviderRegistry {
private static StandardLogger logger = LoggerUtil.getStandardLogger();
public static final List providerServices = new ArrayList(Arrays.asList(new String[] {ActivityProvider.class.getName(),
EventHandlerProvider.class.getName(), VariableTranslatorProvider.class.getName()}));
private Map>> providers = new HashMap>>();
private Map> dynamicProviders = new HashMap>();
@SuppressWarnings("unchecked")
public List> getProviders(Class extends Provider>> providerType) {
List> list = new ArrayList>();
for (Provider> provider : providers.get(providerType.getName())) {
list.add((Provider)provider);
}
return list;
}
protected ProviderRegistry() {
}
private static ProviderRegistry instance;
public static ProviderRegistry getInstance() {
if (instance == null) {
instance = new ProviderRegistry();
instance.providers.put(ActivityProvider.class.getName(), new ArrayList>());
instance.providers.put(EventHandlerProvider.class.getName(), new ArrayList>());
instance.providers.put(VariableTranslatorProvider.class.getName(), new ArrayList>());
}
return instance;
}
/**
* @param serviceInterface
* @param className
*/
public void addDynamicProvider(String serviceInterface, String className) {
if (dynamicProviders.containsKey(serviceInterface)) {
dynamicProviders.get(serviceInterface).add(className);
}
else {
Set classNamesSet = new HashSet();
classNamesSet.add(className);
dynamicProviders.put(serviceInterface, classNamesSet);
}
}
public void clearDynamicProviders() {
logger.mdwDebug("Clearing Dynamic providers cache in : " + getClass().getName());
dynamicProviders.clear();
}
public Map> getDynamicProviders() {
return dynamicProviders;
}
/**
* To get dynamic java variable translator
* @param translatorClass
* @param classLoader
* @return
*/
public VariableTranslator getDynamicVariableTranslator(String className, ClassLoader parentLoader) {
try {
Class> clazz = CompiledJavaCache.getClassFromAssetName(parentLoader, className);
if (clazz != null)
return (VariableTranslator) (clazz).newInstance();
}
catch (Exception ex) {
logger.trace("Dynamic VariableTranslatorProvider not found: " + className);
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy