本文整理汇总了Java中org.apache.deltaspike.core.api.config.ConfigResolver类的典型用法代码示例。如果您正苦于以下问题:Java ConfigResolver类的具体用法?Java ConfigResolver怎么用?Java ConfigResolver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigResolver类属于org.apache.deltaspike.core.api.config包,在下文中一共展示了ConfigResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hola
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@GET
@Path("/hola")
@Produces("text/plain")
@ApiOperation("Returns the greeting in Spanish")
public String hola() {
String hostname = System.getenv().getOrDefault("HOSTNAME", "unknown");
String translation = ConfigResolver
.resolve("hello")
.withDefault("Hola de %s")
.logChanges(true)
// 5 Seconds cache only for demo purpose
.cacheFor(TimeUnit.SECONDS, 5)
.getValue();
return String.format(translation, hostname);
}
示例2: setServletConfig
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
private void setServletConfig(ServletConfigSource configSource, ServletContextEvent sce)
{
ServletContext servletContext = sce.getServletContext();
String servletContextName = servletContext.getServletContextName();
if (servletContextName != null && servletContextName.length() > 0)
{
String oldAppName = ConfigResolver.getPropertyValue(ConfigResolver.DELTASPIKE_APP_NAME_CONFIG);
// we first need to unregister the old MBean
// as we don't know whether the CDI Extension or the Servlet Listener comes first.
// It's simply not defined by the spec :/
ConfigurationExtension.unRegisterConfigMBean(oldAppName);
configSource.setPropertyValue(ConfigResolver.DELTASPIKE_APP_NAME_CONFIG, servletContextName);
// and as we now did set the new name -> register again:
ConfigurationExtension.registerConfigMBean();
}
}
示例3: getEntityManagerFactoryConfiguration
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Override
public Properties getEntityManagerFactoryConfiguration(String persistenceUnitName)
{
Properties unitProperties = PropertyLoader.getProperties("persistence-" + persistenceUnitName);
if (unitProperties == null)
{
unitProperties = new Properties();
}
// apply ConfigFilters to the configured values.
for (Map.Entry entry : unitProperties.entrySet())
{
String key = (String) entry.getKey();
String value = (String) entry.getValue();
entry.setValue(ConfigResolver.filterConfigValue(key, value));
}
unitProperties = addConfigProperties(unitProperties, persistenceUnitName);
// add spec expected attributes
unitProperties.put("javax.persistence.bean.manager", BeanManagerProvider.getInstance().getBeanManager());
return unitProperties;
}
示例4: addConfigProperties
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
/**
* Load additional configuration from the Configuration system
* and overload the basic settings with that info.
*
* The key is deltaspike.persistence.config.${persistenceUnitName}.${originalKey}
*
* @see #CONFIG_PREFIX
* @since 1.8.0
*/
protected Properties addConfigProperties(Properties unitProperties, String persistenceUnitName)
{
// we start with a copy of the original properties
Properties mergedConfig = new Properties();
mergedConfig.putAll(unitProperties);
Set<String> allConfigKeys = ConfigResolver.getAllProperties().keySet();
String unitPrefix = CONFIG_PREFIX + persistenceUnitName + ".";
for (String configKey : allConfigKeys)
{
if (configKey.startsWith(unitPrefix))
{
mergedConfig.put(configKey.substring(unitPrefix.length()),
ConfigResolver.getProjectStageAwarePropertyValue(configKey));
}
}
return mergedConfig;
}
示例5: evaluateExpression
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
private String evaluateExpression(Scheduled scheduled)
{
String expression = scheduled.cronExpression();
if (expression.startsWith("{") && expression.endsWith("}"))
{
String configKey = expression.substring(1, expression.length() - 1);
expression = ConfigResolver.getProjectStageAwarePropertyValue(configKey, null);
if (expression == null)
{
throw new IllegalStateException("No config-value found for config-key: " + configKey);
}
}
return expression;
}
示例6: asResolver
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
public <T> ConfigResolver.TypedResolver<T> asResolver(final String key, final String stringDefault,
final Type ipCls,
final Class<? extends ConfigResolver.Converter> converterType,
final String parameterizedBy,
final boolean projectStageAware, final boolean evaluate)
{
final ConfigResolver.UntypedResolver<String> untypedResolver = ConfigResolver.resolve(key);
final ConfigResolver.TypedResolver<T> resolver =
(ConfigResolver.Converter.class == converterType ?
untypedResolver.as(Class.class.cast(ipCls)) :
untypedResolver.as(ipCls, BeanProvider.getContextualReference(converterType)))
.withCurrentProjectStage(projectStageAware);
if (!ConfigProperty.NULL.equals(stringDefault))
{
resolver.withStringDefault(stringDefault);
}
if (!ConfigProperty.NULL.equals(parameterizedBy))
{
resolver.parameterizedBy(parameterizedBy);
}
return resolver.evaluateVariables(evaluate);
}
示例7: resolveProjectStage
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
/**
* Resolves the project-stage configured for DeltaSpike
* @return the resolved {@link ProjectStage} or <code>null</code> if none defined.
*/
protected ProjectStage resolveProjectStage()
{
for (String configLocation : CONFIG_SETTING_KEYS)
{
String stageName = ConfigResolver.getPropertyValue(configLocation);
if (stageName != null && !stageName.isEmpty())
{
return ProjectStage.valueOf(stageName);
}
}
return null;
}
示例8: testValidTypes
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testValidTypes()
{
Assert.assertEquals("configured", ConfigResolver.resolve("deltaspike.test.string-value").getValue());
Assert.assertEquals(Boolean.FALSE, ConfigResolver.resolve("deltaspike.test.boolean-value").as(Boolean.class)
.getValue());
Assert.assertEquals(TestConfigSource.class, ConfigResolver.resolve("deltaspike.test.class-value").as(Class
.class).getValue());
Assert.assertEquals(5l, (int) ConfigResolver.resolve("deltaspike.test.integer-value").as(Integer.class)
.getValue());
Assert.assertEquals(8589934592l, (long) ConfigResolver.resolve("deltaspike.test.long-value").as(Long.class)
.getValue());
Assert.assertEquals(-1.1f, (float) ConfigResolver.resolve("deltaspike.test.float-value").as(Float.class)
.getValue(), 0);
Assert.assertEquals(4e40d, (double) ConfigResolver.resolve("deltaspike.test.double-value").as(Double.class)
.getValue(), 0);
}
示例9: testProjectStageAware
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testProjectStageAware()
{
Assert.assertEquals("unittestvalue",
ConfigResolver.resolve("testkey")
.withCurrentProjectStage(true)
.getValue());
Assert.assertEquals("testvalue",
ConfigResolver.resolve("testkey")
.withCurrentProjectStage(false)
.getValue());
// property without PS, with PS-aware
Assert.assertEquals("testvalue",
ConfigResolver.resolve("testkey2")
.withCurrentProjectStage(true)
.getValue());
}
示例10: testStrict
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testStrict()
{
Assert.assertEquals("TestDataSource",
ConfigResolver.resolve("dataSource")
.withCurrentProjectStage(true)
.parameterizedBy("dbvendor")
.strictly(true)
.getValue());
// no base.param, no value for base.param.ps
Assert.assertEquals(null,
ConfigResolver.resolve("dataSource")
.withCurrentProjectStage(true)
.parameterizedBy("dbvendor3")
.strictly(true)
.getValue());
// valid base.param, but no base.param.ps
Assert.assertEquals(null,
ConfigResolver.resolve("dataSource")
.withCurrentProjectStage(true)
.parameterizedBy("dbvendor2")
.strictly(true)
.getValue());
}
示例11: testGets
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testGets()
{
ConfigResolver.TypedResolver<String> resolver = ConfigResolver.resolve("dataSource")
.withCurrentProjectStage(true)
.parameterizedBy("dbvendor")
.withDefault("TESTDEFAULT");
Assert.assertEquals("TestDataSource", resolver.getValue());
Assert.assertEquals("dataSource", resolver.getKey());
Assert.assertEquals("TESTDEFAULT", resolver.getDefaultValue());
Assert.assertEquals("dataSource.mysql.UnitTest", resolver.getResolvedKey());
ConfigResolver.TypedResolver<String> resolver2 = ConfigResolver.resolve("testkey2")
.withCurrentProjectStage(true)
.parameterizedBy("INVALIDPARAMETER");
Assert.assertEquals("testvalue", resolver2.getValue());
Assert.assertEquals("testkey2", resolver2.getResolvedKey());
}
示例12: testWithCacheTime
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testWithCacheTime() throws Exception
{
ConfigResolver.TypedResolver<String> resolver = ConfigResolver.resolve("dataSource")
.withCurrentProjectStage(true)
.parameterizedBy("dbvendor")
.cacheFor(TimeUnit.MILLISECONDS, 5)
.withDefault("TESTDEFAULT");
Assert.assertEquals("TestDataSource", resolver.getValue());
Assert.assertEquals("TestDataSource", resolver.getValue());
Assert.assertEquals("dataSource", resolver.getKey());
Assert.assertEquals("TESTDEFAULT", resolver.getDefaultValue());
Assert.assertEquals("dataSource.mysql.UnitTest", resolver.getResolvedKey());
// because the clock steps in certain OS is only 16ms
Thread.sleep(35L);
Assert.assertEquals("TestDataSource", resolver.getValue());
}
示例13: testGetProjectStageAwarePropertyValue
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testGetProjectStageAwarePropertyValue()
{
ProjectStageProducer.setProjectStage(ProjectStage.UnitTest);
Assert.assertNull(ConfigResolver.getProjectStageAwarePropertyValue("notexisting", null));
Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey"));
Assert.assertEquals("unittestvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey"));
Assert.assertEquals("unittestvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey", null));
Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey2"));
Assert.assertEquals("testvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey2"));
Assert.assertEquals("testvalue", ConfigResolver.getProjectStageAwarePropertyValue("testkey2", null));
Assert.assertEquals("testvalue", ConfigResolver.getPropertyValue("testkey3"));
Assert.assertEquals("", ConfigResolver.getProjectStageAwarePropertyValue("testkey3"));
Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.getProjectStageAwarePropertyValue("testkey3", DEFAULT_VALUE));
Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.getProjectStageAwarePropertyValue("deltaspike.test.projectstagefallback", DEFAULT_VALUE));
Assert.assertEquals("", ConfigResolver.getProjectStageAwarePropertyValue("deltaspike.test.projectstagefallback"));
Assert.assertEquals(DEFAULT_VALUE, ConfigResolver.resolve("deltaspike.test.projectstagefallback").as(String.class).withDefault(DEFAULT_VALUE).withCurrentProjectStage(true).getValue());
Assert.assertEquals("", ConfigResolver.resolve("deltaspike.test.projectstagefallback").as(String.class).withCurrentProjectStage(true).getValue());
}
示例14: testConfigFilter
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testConfigFilter()
{
ConfigFilter configFilter = new TestConfigFilter();
Assert.assertEquals("shouldGetDecrypted: value", configFilter.filterValue("somekey.encrypted", "value"));
Assert.assertEquals("**********", configFilter.filterValueForLog("somekey.password", "value"));
ConfigResolver.addConfigFilter(configFilter);
Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getPropertyValue("testkey4.encrypted"));
Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getProjectStageAwarePropertyValue("testkey4.encrypted"));
Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getProjectStageAwarePropertyValue("testkey4.encrypted", null));
Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getPropertyAwarePropertyValue("testkey4.encrypted", "dbvendor"));
Assert.assertEquals("shouldGetDecrypted: value", ConfigResolver.getPropertyAwarePropertyValue("testkey4.encrypted", "dbvendor", null));
List<String> allPropertyValues = ConfigResolver.getAllPropertyValues("testkey4.encrypted");
Assert.assertNotNull(allPropertyValues);
Assert.assertEquals(1, allPropertyValues.size());
Assert.assertEquals("shouldGetDecrypted: value", allPropertyValues.get(0));
}
示例15: testTypedResolver_NonExistingValue
import org.apache.deltaspike.core.api.config.ConfigResolver; //导入依赖的package包/类
@Test
public void testTypedResolver_NonExistingValue()
{
final String key = "non.existing.key";
ConfigResolver.TypedResolver<String> resolver = ConfigResolver.resolve(key)
.logChanges(true);
Assert.assertNull(resolver.getValue());
setTestConfigSourceValue(key, "somevalue");
Assert.assertEquals("somevalue", resolver.getValue());
setTestConfigSourceValue(key, null);
Assert.assertNull(resolver.getValue());
}