Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1081 → Rev 1082

/hostadmiral/trunk/src/ak/hostadmiral/util/ConfigUtils.java
0,0 → 1,81
package ak.hostadmiral.util;
 
import java.util.Map;
 
public class ConfigUtils
{
private Map params;
protected boolean returnDefValue;
 
public ConfigUtils(Map params)
{
this.params = params;
}
 
public String getString(String key, String defValue,
boolean optional, boolean mayBeEmpty)
throws ModelException
{
String s = (String)getObject(key, defValue, optional);
 
if(returnDefValue) return s;
 
if(!mayBeEmpty && s.equals("")) {
throw new ModelException("Configuration parameter '" + key + "' may not be empty");
}
 
return s;
}
 
public Integer getInteger(String key, Integer defValue,
boolean optional)
throws ModelException
{
Object value = getObject(key, defValue, optional);
 
if(returnDefValue) return defValue;
 
return new Integer((String)value);
}
 
protected synchronized Object getObject(String key, Object defValue, boolean optional)
throws ModelException
{
returnDefValue = false;
 
Object obj = params.get(key);
 
if(obj == null) {
if(optional) {
returnDefValue = true;
return defValue;
}
else
throw new ModelException("Configuration parameter '" + key + "' must be present");
}
 
if(!(obj instanceof String[])) {
throw new ModelException("Configuration parameter '" + key
+ "' expected to be an array of strings");
}
 
String[] sa = (String[])obj;
 
if(sa.length == 0) {
if(optional) {
returnDefValue = true;
return defValue;
}
else
throw new ModelException("Value of configuration parameter '"
+ key + "' must be present");
}
 
if(sa.length > 1) {
throw new ModelException("Value of configuration parameter '"
+ key + "' may not be an array");
}
 
return sa[0];
}
}
/hostadmiral/trunk/src/ak/hostadmiral/util/ConfigInit.java
6,6 → 6,7
{
/**
* This method is called by initialization from config file.
* FIMXE give more powerful structure, not just a map
*
* @param params map String -> String[] with pairs of param name -> values
* from the initializaion file