we have the following problem with code. Our code must make lots of decision according to the fields of some object, and sometimes the fields are accessed through a complex path:
public void perform(OurBean bean) {
if (bean != null
&& bean.getWaybill() != null
&& bean.getWaybill().getTransaction() != null
&& bean.getWaybill().getTransaction().getGuid() != null) {
// Do some action with the guid - a string
}
}
What I would like to have is to do something like this:
public void perform(OurBean bean) {
if (notEmpty(bean, "waybill.transaction.guid")) {
// Do some action with the guid - a string
}
}
Right now we have such a function implemented on our own, using a Reflection mechanism. Is there a better way to do it? JSP EL has exactly what we need - expressions using getter and setter methods. But how can I use that inside a Java code, not a JSP page, for some object? Could not find any good samples so far.