All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.configuration.parsing.ConfigurationBuilderHolder Maven / Gradle / Ivy

There is a newer version: 9.1.7.Final
Show newest version
package org.infinispan.configuration.parsing;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;

public class ConfigurationBuilderHolder {

   private final GlobalConfigurationBuilder globalConfigurationBuilder;
   private final ConfigurationBuilder defaultConfigurationBuilder;
   private final Map namedConfigurationBuilders;
   private ConfigurationBuilder currentConfigurationBuilder;
   private final Map, ParserContext> parserContexts;
   private final WeakReference classLoader;
   private String defaultCacheName;

   public ConfigurationBuilderHolder() {
      this(Thread.currentThread().getContextClassLoader());
   }

   public ConfigurationBuilderHolder(ClassLoader classLoader) {
      this.globalConfigurationBuilder = new GlobalConfigurationBuilder();
      this.defaultConfigurationBuilder = new ConfigurationBuilder();
      this.namedConfigurationBuilders = new HashMap();
      this.currentConfigurationBuilder = defaultConfigurationBuilder;
      this.parserContexts = new HashMap, ParserContext>();
      this.classLoader = new WeakReference(classLoader);
   }

   public GlobalConfigurationBuilder getGlobalConfigurationBuilder() {
      return globalConfigurationBuilder;
   }

   public ConfigurationBuilder newConfigurationBuilder(String name) {
      ConfigurationBuilder builder = new ConfigurationBuilder();
      //no need to validate default config again
      //https://issues.jboss.org/browse/ISPN-1938
      builder.read(getDefaultConfigurationBuilder().build(false));
      namedConfigurationBuilders.put(name, builder);
      currentConfigurationBuilder = builder;
      return builder;
   }

   public ConfigurationBuilder getDefaultConfigurationBuilder() {
      ConfigurationBuilder builder = namedConfigurationBuilders.get(defaultCacheName);
      return builder == null ? defaultConfigurationBuilder : builder;
   }

   public Map getNamedConfigurationBuilders() {
      return namedConfigurationBuilders;
   }

   public ConfigurationBuilder getCurrentConfigurationBuilder() {
      return currentConfigurationBuilder;
   }

   @SuppressWarnings("unchecked")
   public  T getParserContext(Class parserClass) {
      return (T) parserContexts.get(parserClass);
   }

   public void setParserContext(Class parserClass, ParserContext context) {
      parserContexts.put(parserClass, context);
   }

   public ClassLoader getClassLoader() {
      return classLoader.get();
   }

   Map, ParserContext> getParserContexts() {
      return parserContexts;
   }

   public void setDefaultCacheName(String defaultCacheName) {
      this.defaultCacheName = defaultCacheName;
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy