Search in sources :

Example 1 with Jsr107Configuration

use of org.ehcache.jsr107.config.Jsr107Configuration in project ehcache3 by ehcache.

the class Jsr107ServiceConfigurationParser method parse.

@Override
public Jsr107Configuration parse(final Element fragment, ClassLoader classLoader) {
    boolean jsr107CompliantAtomics = true;
    ConfigurationElementState enableManagementAll = ConfigurationElementState.UNSPECIFIED;
    ConfigurationElementState enableStatisticsAll = ConfigurationElementState.UNSPECIFIED;
    if (fragment.hasAttribute(JSR_107_COMPLIANT_ATOMICS_ATTRIBUTE)) {
        jsr107CompliantAtomics = parseBoolean(fragment.getAttribute(JSR_107_COMPLIANT_ATOMICS_ATTRIBUTE));
    }
    if (fragment.hasAttribute(ENABLE_MANAGEMENT_ALL_ATTRIBUTE)) {
        enableManagementAll = parseBoolean(fragment.getAttribute(ENABLE_MANAGEMENT_ALL_ATTRIBUTE)) ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
    }
    if (fragment.hasAttribute(ENABLE_STATISTICS_ALL_ATTRIBUTE)) {
        enableStatisticsAll = parseBoolean(fragment.getAttribute(ENABLE_STATISTICS_ALL_ATTRIBUTE)) ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
    }
    final String defaultTemplate = fragment.getAttribute(DEFAULT_TEMPLATE_ATTRIBUTE);
    final HashMap<String, String> templates = new HashMap<>();
    final NodeList childNodes = fragment.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        final Node node = childNodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            final Element item = (Element) node;
            templates.put(item.getAttribute(CACHE_NAME_ATTRIBUTE), item.getAttribute(TEMPLATE_NAME_ATTRIBUTE));
        }
    }
    return new Jsr107Configuration(defaultTemplate, templates, jsr107CompliantAtomics, enableManagementAll, enableStatisticsAll);
}
Also used : Jsr107Configuration(org.ehcache.jsr107.config.Jsr107Configuration) HashMap(java.util.HashMap) ConfigurationElementState(org.ehcache.jsr107.config.ConfigurationElementState) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 2 with Jsr107Configuration

use of org.ehcache.jsr107.config.Jsr107Configuration in project cas by apereo.

the class Ehcache3TicketRegistryConfiguration method ehcache3TicketCacheManager.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "ehcache3TicketCacheManager")
public CacheManager ehcache3TicketCacheManager(final ConfigurableApplicationContext applicationContext, @Qualifier("ehcache3CacheManagerConfiguration") final ServiceCreationConfiguration ehcache3CacheManagerConfiguration, final CasConfigurationProperties casProperties) {
    return BeanSupplier.of(CacheManager.class).when(CONDITION.given(applicationContext.getEnvironment())).supply(() -> {
        val ehcacheProperties = casProperties.getTicket().getRegistry().getEhcache3();
        val ehcacheProvider = (EhcacheCachingProvider) Caching.getCachingProvider(EhcacheCachingProvider.class.getName());
        val statisticsAllEnabled = ehcacheProperties.isEnableStatistics() ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
        val managementEnabled = ehcacheProperties.isEnableManagement() ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
        val jsr107Config = new Jsr107Configuration(null, new HashMap<>(), false, managementEnabled, statisticsAllEnabled);
        val configuration = new DefaultConfiguration(ehcacheProvider.getDefaultClassLoader(), ehcache3CacheManagerConfiguration, jsr107Config);
        return ehcacheProvider.getCacheManager(ehcacheProvider.getDefaultURI(), configuration);
    }).otherwiseProxy().get();
}
Also used : lombok.val(lombok.val) Jsr107Configuration(org.ehcache.jsr107.config.Jsr107Configuration) DefaultConfiguration(org.ehcache.core.config.DefaultConfiguration) EhcacheCachingProvider(org.ehcache.jsr107.EhcacheCachingProvider) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with Jsr107Configuration

use of org.ehcache.jsr107.config.Jsr107Configuration in project ehcache3 by ehcache.

the class DefaultJsr107Service method getTemplateNameForCache.

@Override
public String getTemplateNameForCache(String cacheAlias) {
    final Jsr107Configuration cfg = configuration;
    if (cfg == null) {
        return null;
    }
    String template = cfg.getTemplates().get(cacheAlias);
    if (template != null) {
        return template;
    }
    return cfg.getDefaultTemplate();
}
Also used : Jsr107Configuration(org.ehcache.jsr107.config.Jsr107Configuration)

Example 4 with Jsr107Configuration

use of org.ehcache.jsr107.config.Jsr107Configuration in project ehcache3 by ehcache.

the class Jsr107ServiceConfigurationParserTest method testTranslateServiceCreationConfiguration.

@Test(expected = XmlConfigurationException.class)
public void testTranslateServiceCreationConfiguration() throws IOException, ParserConfigurationException, SAXException {
    Jsr107ServiceConfigurationParser configTranslator = new Jsr107ServiceConfigurationParser();
    Map<String, String> templateMap = new HashMap<>();
    templateMap.put("testCache", "simpleCacheTemplate");
    templateMap.put("testCache1", "simpleCacheTemplate1");
    boolean jsr107CompliantAtomics = true;
    Jsr107Configuration serviceCreationConfiguration = new Jsr107Configuration("tiny-template", templateMap, jsr107CompliantAtomics, ConfigurationElementState.ENABLED, ConfigurationElementState.DISABLED);
    configTranslator.unparse(createDocumentRoot(configTranslator.getSchema().values()), serviceCreationConfiguration);
}
Also used : Jsr107Configuration(org.ehcache.jsr107.config.Jsr107Configuration) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Jsr107Configuration (org.ehcache.jsr107.config.Jsr107Configuration)4 HashMap (java.util.HashMap)2 lombok.val (lombok.val)1 DefaultConfiguration (org.ehcache.core.config.DefaultConfiguration)1 EhcacheCachingProvider (org.ehcache.jsr107.EhcacheCachingProvider)1 ConfigurationElementState (org.ehcache.jsr107.config.ConfigurationElementState)1 Test (org.junit.Test)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1