use of henplus.property.PropertyHolder in project henplus by neurolabs.
the class AbstractPropertyCommand method execute.
/**
* execute the command given.
*/
@Override
public int execute(final SQLSession currentSession, final String cmd, final String param) {
final StringTokenizer st = new StringTokenizer(param);
final int argc = st.countTokens();
if (cmd.startsWith("re")) {
// 'reset-property'
if (argc == 1) {
final String name = st.nextToken();
PropertyHolder holder;
holder = getRegistry().getPropertyMap().get(name);
if (holder == null) {
return EXEC_FAILED;
}
final String defaultValue = holder.getDefaultValue();
try {
holder.setValue(defaultValue);
} catch (final Exception e) {
HenPlus.msg().println("setting to default '" + defaultValue + "' failed.");
return EXEC_FAILED;
}
return SUCCESS;
}
return SYNTAX_ERROR;
} else {
/*
* no args. show available properties
*/
if (argc == 0) {
PROP_META[0].resetWidth();
PROP_META[1].resetWidth();
final TableRenderer table = new TableRenderer(PROP_META, HenPlus.out());
for (Map.Entry<String, PropertyHolder> entry : getRegistry().getPropertyMap().entrySet()) {
final Column[] row = new Column[3];
final PropertyHolder holder = entry.getValue();
row[0] = new Column(entry.getKey());
row[1] = new Column(holder.getValue());
row[2] = new Column(holder.getShortDescription());
table.addRow(row);
}
table.closeTable();
return SUCCESS;
} else if (argc == 1) {
/*
* one arg: show help
*/
final String name = st.nextToken();
PropertyHolder holder;
holder = getRegistry().getPropertyMap().get(name);
if (holder == null) {
return EXEC_FAILED;
}
printDescription(name, holder);
return SUCCESS;
} else if (argc >= 2) {
/*
* more than one arg
*/
final String varname = (String) st.nextElement();
int pos = 0;
final int paramLength = param.length();
// skip whitespace after 'set'
while (pos < paramLength && Character.isWhitespace(param.charAt(pos))) {
++pos;
}
// skip non-whitespace after 'set ': variable name
while (pos < paramLength && !Character.isWhitespace(param.charAt(pos))) {
++pos;
}
// skip whitespace before vlue..
while (pos < paramLength && Character.isWhitespace(param.charAt(pos))) {
++pos;
}
String value = param.substring(pos);
if (value.startsWith("\"") && value.endsWith("\"")) {
value = value.substring(1, value.length() - 1);
} else if (value.startsWith("\'") && value.endsWith("\'")) {
value = value.substring(1, value.length() - 1);
}
try {
getRegistry().setProperty(varname, value);
} catch (final Exception e) {
HenPlus.msg().println(e.getMessage());
return EXEC_FAILED;
}
return SUCCESS;
}
}
return SUCCESS;
}
use of henplus.property.PropertyHolder in project henplus by neurolabs.
the class PropertyRegistry method setProperty.
/**
* sets the Property to the given value. This throws an Exception, if the PropertyHolder vetoes this attempt or if there is
* simply no Property bound to the given name.
*
* @param name
* the name the property is bound to.
* @param value
* the new value of the property to be set.
* @throws Exception
* , if the property does not exist or throws an Exception to veto the new value.
*/
public void setProperty(final String name, final String value) throws Exception {
final PropertyHolder holder = _namedProperties.get(name);
if (holder == null) {
throw new IllegalArgumentException("unknown property '" + name + "'");
}
holder.setValue(value);
}
use of henplus.property.PropertyHolder in project henplus by neurolabs.
the class AbstractPropertyCommand method complete.
/**
* complete property names.
*/
@Override
public Iterator<String> complete(final CommandDispatcher disp, final String partialCommand, final String lastWord) {
final StringTokenizer st = new StringTokenizer(partialCommand);
final String cmd = st.nextToken();
final int argc = st.countTokens();
if (argc > ("".equals(lastWord) ? 0 : 1)) {
/* one arg given */
if (getSetCommand().equals(cmd)) {
final String name = st.nextToken();
PropertyHolder holder;
holder = getRegistry().getPropertyMap().get(name);
if (holder == null) {
return null;
}
return holder.completeValue(lastWord);
}
return null;
}
return new SortedMatchIterator(lastWord, getRegistry().getPropertyMap());
}
use of henplus.property.PropertyHolder in project henplus by neurolabs.
the class PropertyCommand method shutdown.
@Override
public void shutdown() {
final Map<String, String> writeMap = new HashMap<String, String>();
for (Map.Entry<String, PropertyHolder> entry : _registry.getPropertyMap().entrySet()) {
final PropertyHolder holder = entry.getValue();
writeMap.put(entry.getKey(), holder.getValue());
}
_config.storeProperties(writeMap, true, "user properties");
}
Aggregations