Eclipse templates 2
Most of these are dynamo specific, but they work well for setting up preconditions and code idioms. Notably, I stick a dld at the beginning of every method so I can have a good idea of the incoming state. For form handlers, I fake it by pulling in the properties and treating them like the method arguments, but it’s the same idea.
dld:
if (isLoggingDebug()) {
String msg = "${enclosing_method}: ${enclosing_method_arguments}";
Object[] params = { ${enclosing_method_arguments} };
msg = java.text.MessageFormat.format(msg, params);
logDebug(msg);
}
getprop:
${type} ${propertyName} = (${type}) ${item}.getPropertyValue("${propertyName}");setprop:
${item}.setPropertyValue("${propertyName}", ${propertyValue});valueof:
String.valueOf(${word_selection})isempty:
if (StringUtils.isEmpty(${variable})) {
String msg = "empty ${variable}";
throw new InvalidParameterException(msg);
}
isnull:
if (${parameter} == null) {
String msg = "null ${parameter}";
throw new InvalidParameterException(msg);
}
const:
public static final String ${constant_name} = "${constant_value}";dhandle:
public boolean handle${method}(DynamoHttpServletRequest pRequest,
DynamoHttpServletResponse pResponse)
throws ServletException, IOException {
String successURL = get${method}SuccessURL();
String errorURL = get${method}ErrorURL();
if (getFormError()) {
if (isLoggingDebug()) {
String msg = "handle${method}: form errors found, aborting";
logDebug(msg);
}
return checkFormRedirect(successURL, errorURL, pRequest, pResponse);
}
${cursor}
}
demarc (explained here):
try
{
TransactionManager tm = getTransactionManager();
TransactionDemarcation td = new TransactionDemarcation();
boolean rollback = true;
try
{
td.begin(tm);
${line_selection}
// TODO check logic to make sure rollback == false before any returns.
rollback = false;
} finally {
td.end(rollback);
}
} catch (TransactionDemarcationException tde) {
// TODO specific functionality.
throw new CommerceException(tde);
}
formerror:
if (getFormError()) {
if (isLoggingDebug()) {
String msg = "${enclosing_method}: form errors found, aborting";
logDebug(msg);
}
return checkFormRedirect(${successURL}, ${errorURL}, pRequest, pResponse);
}
I fear the template named dld doesn’t work properly… It doesn’t prints parameter values…
thanks… mircmirc indirmirc yükle