<commit_before>package org.cache2k.xmlConfig;

/*
 * #%L
 * cache2k XML configuration
 * %%
 * Copyright (C) 2000 - 2016 headissue GmbH, Munich
 * %%
 * 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.
 * #L%
 */

import org.cache2k.CacheException;
import org.cache2k.CacheManager;
import org.cache2k.CacheMisconfigurationException;
import org.cache2k.configuration.Cache2kConfiguration;
import org.cache2k.configuration.ConfigurationSection;
import org.cache2k.configuration.ConfigurationWithSections;
import org.cache2k.core.spi.CacheConfigurationProvider;
import org.cache2k.core.util.Log;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Hooks into cache2k and provides the additional configuration data.
 *
 * @author <NAME>
 */
public class CacheConfigurationProviderImpl implements CacheConfigurationProvider {

  private static final String DEFAULT_CONFIGURATION_FILE = "cache2k.xml";
  private PropertyParser propertyParser = new StandardPropertyParser();
  private TokenizerFactory tokenizerFactory = new FlexibleXmlTokenizerFactory();
  private volatile Map<Class<?>, BeanPropertyMutator> type2mutator = new HashMap<Class<?>, BeanPropertyMutator>();
  private final Log log = Log.getLog(this.getClass());
  private volatile ConfigurationContext defaultManagerContext = null;
  private volatile Map<CacheManager, ConfigurationContext> manager2defaultConfig = new HashMap<CacheManager, ConfigurationContext>();
  private final Map<String, String> standardSectionTypes = new HashMap<String, String>();

  {
    standardSectionTypes.put("jcache", "org.cache2k.jcache.JCacheConfiguration");
  }

  @Override
  public String getDefaultManagerName(ClassLoader cl) {
    synchronized (this) {
      defaultManagerContext = createContext(cl, null, DEFAULT_CONFIGURATION_FILE);
    }
    return defaultManagerContext.getManagerName();
  }

  @Override
  public Cache2kConfiguration getDefaultConfiguration(final CacheManager mgr) {
    Cache2kConfiguration cfg = getManagerContext(mgr).getDefaultManagerConfiguration();
    try {
      return copyViaSerialization(mgr, cfg);
    } catch (Exception ex) {
      throw new CacheMisconfigurationException(
        "Copying default cache configuration for manager '" + mgr.getName() + "'", ex);
    }
  }

  @Override
  public <K, V> void augmentConfiguration(final CacheManager mgr, final Cache2kConfiguration<K, V> _bean) {
    ConfigurationContext ctx =  getManagerContext(mgr);
    final String _cacheName = _bean.getName();
    if (_cacheName == null) {
      if (ctx.isIgnoreAnonymousCache()) {
        return;
      }
      if (!ctx.isConfigurationPresent()) {
        return;
      }
      throw new CacheMisconfigurationException("Cache name missing, cannot apply XML configuration");
    }
    ParsedConfiguration pc;
    pc = readManagerConfigurationWithExceptionHandling(mgr.getClassLoader(), getFileName(mgr));
    ParsedConfiguration _cacheCfg = extractCacheSection(pc);
    if (_cacheCfg != null) { _cacheCfg = _cacheCfg.getSection(_cacheName); }
    if (_cacheCfg == null) {
      if (ctx.isIgnoreMissingCacheConfiguration()) {
        return;
      }
      throw new ConfigurationException("Configuration for cache '" + _cacheName + "' is missing", pc.getSource());
    }
    apply(_cacheCfg, extractTemplates(pc), _bean);<commit_msg>be friendly and give a hint on the right parameters.<commit_after>package org.cache2k.xmlConfig;

/*
 * #%L
 * cache2k XML configuration
 * %%
 * Copyright (C) 2000 - 2016 headissue GmbH, Munich
 * %%
 * 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.
 * #L%
 */

import org.cache2k.CacheException;
import org.cache2k.CacheManager;
import org.cache2k.CacheMisconfigurationException;
import org.cache2k.configuration.Cache2kConfiguration;
import org.cache2k.configuration.ConfigurationSection;
import org.cache2k.configuration.ConfigurationWithSections;
import org.cache2k.core.spi.CacheConfigurationProvider;
import org.cache2k.core.util.Log;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Hooks into cache2k and provides the additional configuration data.
 *
 * @author <NAME>
 */
public class CacheConfigurationProviderImpl implements CacheConfigurationProvider {

  private static final String DEFAULT_CONFIGURATION_FILE = "cache2k.xml";
  private PropertyParser propertyParser = new StandardPropertyParser();
  private TokenizerFactory tokenizerFactory = new FlexibleXmlTokenizerFactory();
  private volatile Map<Class<?>, BeanPropertyMutator> type2mutator = new HashMap<Class<?>, BeanPropertyMutator>();
  private final Log log = Log.getLog(this.getClass());
  private volatile ConfigurationContext defaultManagerContext = null;
  private volatile Map<CacheManager, ConfigurationContext> manager2defaultConfig = new HashMap<CacheManager, ConfigurationContext>();
  private final Map<String, String> standardSectionTypes = new HashMap<String, String>();

  {
    standardSectionTypes.put("jcache", "org.cache2k.jcache.JCacheConfiguration");
  }

  @Override
  public String getDefaultManagerName(ClassLoader cl) {
    synchronized (this) {
      defaultManagerContext = createContext(cl, null, DEFAULT_CONFIGURATION_FILE);
    }
    return defaultManagerContext.getManagerName();
  }

  @Override
  public Cache2kConfiguration getDefaultConfiguration(final CacheManager mgr) {
    Cache2kConfiguration cfg = getManagerContext(mgr).getDefaultManagerConfiguration();
    try {
      return copyViaSerialization(mgr, cfg);
    } catch (Exception ex) {
      throw new CacheMisconfigurationException(
        "Copying default cache configuration for manager '" + mgr.getName() + "'", ex);
    }
  }

  @Override
  public <K, V> void augmentConfiguration(final CacheManager mgr, final Cache2kConfiguration<K, V> _bean) {
    ConfigurationContext ctx =  getManagerContext(mgr);
    final String _cacheName = _bean.getName();
    if (_cacheName == null) {
      if (ctx.isIgnoreAnonymousCache()) {
        return;
      }
      if (!ctx.isConfigurationPresent()) {
        return;
      }
      throw new CacheMisconfigurationException(
        "Cache name missing, cannot apply XML configuration. " +
        "Consider parameter: ignoreAnonymousCache");
    }
    ParsedConfiguration pc;
    pc = readManagerConfigurationWithExceptionHandling(mgr.getClassLoader(), getFileName(mgr));
    ParsedConfiguration _cacheCfg = extractCacheSection(pc);
    if (_cacheCfg != null) { _cacheCfg = _cacheCfg.getSection(_cacheName); }
    if (_cacheCfg == null) {
      if (ctx.isIgnoreMissingCacheConfiguration()) {
        return;
      }
      throw new ConfigurationException(
        "Configuration for cache '" + _cacheName + "' is missing. " +
        "Consider parameter: ignoreMissingCacheConfiguration", pc.getSource());
    }
    apply(_cacheCfg, extractTemplates(pc), _bean);
{'fraction_non_alphanumeric': 0.09180687637161668, 'fraction_numerical': 0.007559131919044135, 'mean_word_length': 4.606971975393028, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1894567', 'n_tokens_mistral': 2174, 'n_tokens_neox': 2144, 'n_words': 618}