Java tutorial
/* * Copyrights 2002-2013 Webb Fontaine * Developer: Sargis Harutyunyan * Date: 11 avr. 2013 * This software is the proprietary information of Webb Fontaine. * Its use is subject to License terms. */ package com.webbfontaine.valuewebb.irms.core; import com.google.common.base.Function; import com.google.common.collect.FluentIterable; import com.google.common.collect.Maps; import com.webbfontaine.twm.urmcore.server.lang.Rule; import com.webbfontaine.twm.urmcore.server.repository.RepositoryConfiguration; import com.webbfontaine.twm.urmcore.server.repository.criterion.CriterionRepository; import com.webbfontaine.twm.urmcore.utils.Preconditions; import com.webbfontaine.valuewebb.irms.impl.risk.data.RiskColor; import com.webbfontaine.valuewebb.irms.tariff.TariffRangeFactory; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import javax.annotation.Nullable; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import static com.webbfontaine.twm.urmcore.server.repository.RepositoryConfiguration.CLASS_LOADER_ALLOWED_PACKAGES; import static com.webbfontaine.twm.urmcore.server.repository.RepositoryConfiguration.GROOVY_COMPILER_OPTIMISATIONS; @Name("irmsCriterionRepository") @Scope(ScopeType.APPLICATION) public class IrmsCriterionRepository { private final CriterionRepository<Rule> criterionRepository = createCriterionRepositoryInstance(); public CriterionRepository<Rule> getCriterionRepository() { return criterionRepository; } private static CriterionRepository<Rule> createCriterionRepositoryInstance() { RepositoryConfiguration repositoryConfiguration = new RepositoryConfiguration(repositoryConfigOptions()); CriterionRepository<Rule> criterionRepository = new CriterionRepository<>( IrmsCriterionRepository.class.getClassLoader(), repositoryConfiguration); return criterionRepository; } private static Map<String, Object> repositoryConfigOptions() { Map<String, Object> configuration = new HashMap<String, Object>(1); configuration.put(GROOVY_COMPILER_OPTIMISATIONS, getGroovyCompileOptimisationOptions()); configuration.put(CLASS_LOADER_ALLOWED_PACKAGES, allowedPackages(RiskColor.class, TariffRangeFactory.class)); return configuration; } private static List<String> allowedPackages(Class<?>... cls) { return FluentIterable.from(Arrays.asList(cls)).transform(new Function<Class<?>, String>() { @Override public String apply(@Nullable Class<?> cls) { Preconditions.checkNotNull(cls); return cls.getPackage().getName(); } }).toList(); } private static Object getGroovyCompileOptimisationOptions() { Map<String, Boolean> options = Maps.newHashMapWithExpectedSize(1); options.put("indy", false); return options; } }