public BeanDefinition parse(Element element, ParserContext parserContext) {
String targetEnvironmentsCsv = element.getAttribute("environments");
String resourcePath = element.getAttribute("resource");
List<String> targetEnvironments = ConstrettoUtils.fromCSV(targetEnvironmentsCsv);
AssemblyContextResolver assemblyContextResolver;
if (parserContext.getRegistry().containsBeanDefinition(ENVIRONMENT_CONTEXT_RESOLVER_NAME)) {
BeanDefinition environmentContextResolverBeanDefinition = parserContext.getRegistry().getBeanDefinition(ENVIRONMENT_CONTEXT_RESOLVER_NAME);
String environmentResolverClassName = environmentContextResolverBeanDefinition.getBeanClassName();
try {
assemblyContextResolver = (AssemblyContextResolver) Class.forName(environmentResolverClassName).newInstance();
} catch (Exception e) {
throw new IllegalStateException("Could not instansiate assembly context resolver with class [" + environmentResolverClassName + "]", e);
}
} else {
assemblyContextResolver = new DefaultAssemblyContextResolver();
}
List<String> assemblyContext = assemblyContextResolver.getAssemblyContext();
targetEnvironments.retainAll(assemblyContext);
boolean include = !targetEnvironments.isEmpty();
if (include) {
parserContext.getReaderContext().getReader().loadBeanDefinitions(resourcePath);
}