本文整理汇总了Java中org.apache.commons.configuration2.Configuration.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setProperty方法的具体用法?Java Configuration.setProperty怎么用?Java Configuration.setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.configuration2.Configuration
的用法示例。
在下文中一共展示了Configuration.setProperty方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: savePropertyForStandaloneProfile
import org.apache.commons.configuration2.Configuration; //导入方法依赖的package包/类
/**
* Save property for standalone profile.
*
* @param pair the pair
*/
public void savePropertyForStandaloneProfile(final Pair<String, String> pair) {
try {
final File file = getStandaloneProfileConfigurationDirectory();
final Parameters params = new Parameters();
final FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
.configure(params.properties().setFile(new File(file, getApplicationName() + ".properties")));
final Configuration config = builder.getConfiguration();
config.setProperty(pair.getKey(), pair.getValue());
builder.save();
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
示例2: test
import org.apache.commons.configuration2.Configuration; //导入方法依赖的package包/类
@Test
public void test() throws ConfigurationException {
// Null input. (= Default value.)
assertEquals(VERSION.fetch(null), VERSION.getDefaultValue());
// Not found. (= Default value.)
Configuration conf = new MapConfiguration(new HashMap<>());
assertEquals(VERSION.fetch(conf), VERSION.getDefaultValue());
// Retrieved from properties. (Empty)
conf.setProperty(VERSION.getKey(), "");
assertNull(VERSION.fetch(conf));
// Retrieved from properties. (Configured)
conf.setProperty(VERSION.getKey(), "test");
assertEquals(VERSION.fetch(conf), "test");
}
示例3: testOverride
import org.apache.commons.configuration2.Configuration; //导入方法依赖的package包/类
@Test
public void testOverride() {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
.configure(params.properties()
.setFileName("file.properties"));
Configuration config = null;
try {
config = builder.getConfiguration();
config.setProperty("somekey", "somevalue");
builder.save();
} catch (ConfigurationException e) {
e.printStackTrace();
}
}
示例4: getClientConfiguration
import org.apache.commons.configuration2.Configuration; //导入方法依赖的package包/类
public Configuration getClientConfiguration() {
Configuration clientConfig = new CompositeConfiguration();
Iterator<String> iter = getKeys();
while (iter.hasNext()) {
String key = iter.next();
if (key.startsWith(CLIENT_PREFIX)) {
clientConfig.setProperty(key, getProperty(key));
}
}
return clientConfig;
}
示例5: setProperty
import org.apache.commons.configuration2.Configuration; //导入方法依赖的package包/类
public static void setProperty(final PropertyList property, final String value) {
try {
Configuration config = FILE_BASED_CONFIGURATION_BUILDER.getConfiguration();
config.setProperty(property.toString(), value);
FILE_BASED_CONFIGURATION_BUILDER.save();
} catch (ConfigurationException cex) {
LOGGER.error("\n" + cex.getCause());
cex.printStackTrace();
}
}
示例6: yajswInstall
import org.apache.commons.configuration2.Configuration; //导入方法依赖的package包/类
public boolean yajswInstall(String configuration)
{
WrappedService w = new WrappedService();
Configuration c = w.getLocalConfiguration();
c.setProperty("wrapper.config", configuration);
w.init();
return w.install();
}
示例7: main
import org.apache.commons.configuration2.Configuration; //导入方法依赖的package包/类
public static void main(String[] args)
{
WrappedRuntimeProcess p = new WrappedRuntimeProcess();
Configuration c = p.getLocalConfiguration();
c.setProperty("wrapper.image", "notepad");// "test.bat");//notepad");//"c:/temp/test.bat");//
c.setProperty("wrapper.working.dir", "c:/");
p.init();
p.start();
p.waitFor(10000);
System.out.println("stopping");
p.stop();
System.out.println("stopped " + p.getExitCode());
}
示例8: main
import org.apache.commons.configuration2.Configuration; //导入方法依赖的package包/类
/**
* The main method.
*
* @param args
* the arguments
*/
public static void main(String[] args)
{
Configuration conf = new BaseConfiguration();
conf.setProperty("wrapper.java.command", "java");
WindowsJavaHome javaHome = new WindowsJavaHome(conf);
System.out.println(javaHome.findJava(
conf.getString("wrapper.java.command"),
conf.getString("wrapper.java.command")));
conf.setProperty("wrapper.java.customProcName", "test");
javaHome = new WindowsJavaHome(conf);
System.out.println(javaHome.findJava(
conf.getString("wrapper.java.command"),
conf.getString("wrapper.java.command")));
conf.setProperty("wrapper.java.command", "javaw");
javaHome = new WindowsJavaHome(conf);
System.out.println(javaHome.findJava(
conf.getString("wrapper.java.command"),
conf.getString("wrapper.java.command")));
conf.clear();
conf.setProperty("wrapper.java.minversion", "1.5.0");
conf.setProperty("wrapper.java.maxversion", "1.5.99");
conf.setProperty("wrapper.java.customProcName", "test");
javaHome = new WindowsJavaHome(conf);
System.out.println(javaHome.findJava(
conf.getString("wrapper.java.command"),
conf.getString("wrapper.java.command")));
conf.clear();
conf.setProperty("wrapper.java.minversion", "1.6.0");
conf.setProperty("wrapper.java.customProcName", "test");
conf.setProperty("wrapper.java.preferJdk", true);
javaHome = new WindowsJavaHome(conf);
System.out.println(javaHome.findJava(
conf.getString("wrapper.java.command"),
conf.getString("wrapper.java.command")));
}
示例9: stopOsProcess
import org.apache.commons.configuration2.Configuration; //导入方法依赖的package包/类
private void stopOsProcess(int shutdownWaitTime)
{
boolean externalStop = false;
String stopConfigName = _config.getString("wrapper.stop.conf");
File stopConfigFile = null;
if (stopConfigName != null)
{
getWrapperLogger().info(
"using stop configuration " + stopConfigName);
stopConfigFile = new File(stopConfigName);
stopConfigName = stopConfigFile.getAbsolutePath();
externalStop = stopConfigFile.isFile() && stopConfigFile.exists();
if (!externalStop)
getWrapperLogger().severe(
"error accessing stop configuration " + stopConfigName);
}
WrappedProcess stopper = null;
if (externalStop)
{
getWrapperLogger().info("starting stop application");
Configuration stopLocalConf = new BaseConfiguration();
stopLocalConf.setProperty("wrapper.config", stopConfigName);
YajswConfigurationImpl stopConf = new YajswConfigurationImpl(
stopLocalConf, _useSystemProperties);
stopper = WrappedProcessFactory.createProcess(stopConf);
stopper.getLocalConfiguration().setProperty("wrapper.config",
stopConfigName);
stopper.setUseSystemProperties(_useSystemProperties);
stopper.setStopper(true);
// stopper.setDebug(true);
stopper.init();
stopper.start();
}
// else normally process is stopped by the controller
// _osProcess.stop(shutdownWaitTime, 999);
if (shutdownWaitTime > 0)
_osProcess.waitFor(shutdownWaitTime);
long remainStopWait = getRemainStopWaitTime();
while (_osProcess.isRunning() && remainStopWait > 0)
{
if (_debug > 1)
getAppLogger().info("extending wait time " + remainStopWait);
if (_service != null)
((StopableService) _service).signalStopping(remainStopWait);
_osProcess.waitFor(remainStopWait);
remainStopWait = getRemainStopWaitTime();
}
if (_osProcess.isRunning())
{
getWrapperLogger().info(
"process did not stop after " + shutdownWaitTime
+ " sec. -> hard kill");
}
_osProcess.kill(999);
if (stopper != null && stopper.getState() != STATE_IDLE)
stopper.stop();
// give the OS some time to clean up
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
Thread.currentThread().interrupt();
}
_osProcess.destroy();
// if (_debug > 0)
getWrapperLogger().info(
"process exit code: " + _osProcess.getExitCode());
}