org.apache.deltaspike.core.api.config.PropertyFileConfig Java Examples
The following examples show how to use
org.apache.deltaspike.core.api.config.PropertyFileConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigurationExtension.java From deltaspike with Apache License 2.0 | 6 votes |
/** * Add all registered PropertyFileConfigs which got picked up in a parent ClassLoader already */ private void addParentPropertyFileConfigs(ClassLoader currentClassLoader, Set<Class<? extends PropertyFileConfig>> propertyFileConfigClasses) { if (currentClassLoader.getParent() == null) { return; } for (Map.Entry<ClassLoader, List<Class<? extends PropertyFileConfig>>> classLoaderListEntry : detectedParentPropertyFileConfigs.entrySet()) { if (currentClassLoader.getParent().equals(classLoaderListEntry.getKey())) { // if this is the direct parent ClassLoader then lets add those PropertyFileConfigs. propertyFileConfigClasses.addAll(classLoaderListEntry.getValue()); // even check further parents addParentPropertyFileConfigs(classLoaderListEntry.getKey(), propertyFileConfigClasses); // and be done. There can only be a single parent CL... return; } } }
Example #2
Source File: ConfigPropertyEARTest.java From deltaspike with Apache License 2.0 | 6 votes |
@Deployment public static EnterpriseArchive deployEar() { JavaArchive ejbJar = ShrinkWrap .create(JavaArchive.class, "ejb-jar.jar") .addClasses(BaseTestConfigProperty.class, ConfigPropertyEARTest.class, MyBean.class, MyCustomEarPropertyFileConfig.class) .addAsResource(CONFIG_FILE_NAME) .addAsServiceProvider(PropertyFileConfig.class, MyCustomEarPropertyFileConfig.class) .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") .addAsManifestResource(new StringAsset("org.apache.deltaspike.ProjectStage = UnitTest"), "apache-deltaspike.properties"); WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war") .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); EnterpriseArchive enterpriseArchive = ShrinkWrap.create(EnterpriseArchive.class, "test.ear") .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive()) .addAsModule(ejbJar) .addAsModule(war) .setApplicationXML("application.xml"); return enterpriseArchive; }
Example #3
Source File: DefaultConfigSourceProvider.java From deltaspike with Apache License 2.0 | 5 votes |
/** * Load all {@link PropertyFileConfig}s which are registered via * {@code java.util.ServiceLoader}. */ private void registerPropertyFileConfigs() { List<? extends PropertyFileConfig> propertyFileConfigs = ServiceUtils.loadServiceImplementations(PropertyFileConfig.class); for (PropertyFileConfig propertyFileConfig : propertyFileConfigs) { EnvironmentPropertyConfigSourceProvider environmentPropertyConfigSourceProvider = new EnvironmentPropertyConfigSourceProvider(propertyFileConfig.getPropertyFileName(), propertyFileConfig.isOptional()); configSources.addAll(environmentPropertyConfigSourceProvider.getConfigSources()); } }
Example #4
Source File: ConfigurationExtension.java From deltaspike with Apache License 2.0 | 5 votes |
@SuppressWarnings("UnusedDeclaration") public void collectUserConfigSources(@Observes ProcessAnnotatedType<? extends PropertyFileConfig> pat) { if (!isActivated) { return; } Class<? extends PropertyFileConfig> pcsClass = pat.getAnnotatedType().getJavaClass(); if (pcsClass.isAnnotation() || pcsClass.isInterface() || pcsClass.isSynthetic() || pcsClass.isArray() || pcsClass.isEnum() ) { // we only like to add real classes return; } if (pat.getAnnotatedType().isAnnotationPresent(Exclude.class)) { // We only pick up PropertyFileConfigs if they are not excluded // This can be the case for PropertyFileConfigs which are registered via java.util.ServiceLoader return; } propertyFileConfigClasses.add(pcsClass); }
Example #5
Source File: ConfigurationExtension.java From deltaspike with Apache License 2.0 | 5 votes |
@SuppressWarnings("UnusedDeclaration") public void registerUserConfigSources(@Observes AfterBeanDiscovery abd) { if (!isActivated) { return; } // create a local copy with all the collected PropertyFileConfig Set<Class<? extends PropertyFileConfig>> allPropertyFileConfigClasses = new HashSet<Class<? extends PropertyFileConfig>>(this.propertyFileConfigClasses); // now add any PropertyFileConfigs from a 'parent BeanManager' // we start with the current TCCL ClassLoader currentClassLoader = ClassUtils.getClassLoader(null); addParentPropertyFileConfigs(currentClassLoader, allPropertyFileConfigClasses); // now let's add our own PropertyFileConfigs to the detected ones. // because maybe WE are a parent BeanManager ourselves! if (!this.propertyFileConfigClasses.isEmpty()) { detectedParentPropertyFileConfigs.put(currentClassLoader, this.propertyFileConfigClasses); } // collect all the ConfigSources from our PropertyFileConfigs List<ConfigSource> configSources = new ArrayList<ConfigSource>(); for (Class<? extends PropertyFileConfig> propertyFileConfigClass : allPropertyFileConfigClasses) { configSources.addAll(createPropertyConfigSource(propertyFileConfigClass)); } ConfigResolver.addConfigSources(configSources); registerConfigMBean(); logConfiguration(); }