org.demoiselle.jee.configuration.ConfigurationBootstrap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of demoiselle-configuration Show documentation
Show all versions of demoiselle-configuration Show documentation
Demoiselle Configuration habilita os projetos a usarem configurações em arquivos .properties, .xml ou variáveis de ambiente.
/*
* Demoiselle Framework
*
* License: GNU Lesser General Public License (LGPL), version 3 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.demoiselle.jee.configuration;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import org.demoiselle.jee.configuration.extractor.ConfigurationValueExtractor;
/**
*
* Class responsible for loading all extractors classes that implement the
* {@link ConfigurationValueExtractor} interface.
*
* @author SERPRO
*
*/
public class ConfigurationBootstrap implements Extension {
private Set> cache;
protected Set> getCache() {
if (this.cache == null) {
this.cache = ConcurrentHashMap.newKeySet();
}
return this.cache;
}
/**
* Process all classes that extends {@link ConfigurationValueExtractor} and
* add the own class type on cache.
*
* @param pat
* ProcessAnnotatedType used by CDI
*/
public void processAnnotatedType(@Observes final ProcessAnnotatedType extends ConfigurationValueExtractor> pat) {
Class extends ConfigurationValueExtractor> pcsClass = pat.getAnnotatedType().getJavaClass();
if (pcsClass.isAnnotation() || pcsClass.isInterface() || pcsClass.isSynthetic() || pcsClass.isArray()
|| pcsClass.isEnum()) {
return;
}
this.getCache().add(pat.getAnnotatedType().getJavaClass());
}
}