if (_actions == null)
return candidate;
Object action;
OpenJPAStateManager sm;
Broker tmpBroker = null;
for (Iterator itr = _actions.iterator(); itr.hasNext();) {
action = itr.next();
// fail on null value
if (candidate == null) {
if (action instanceof Traversal
&& ((Traversal) action).nullTraversal)
return null;
throw new NullPointerException();
}
// check that the cast is valid
if (action instanceof Class) {
candidate = Filters.convert(candidate, (Class) action);
continue;
}
// make sure we can access the instance; even non-pc vals might
// be proxyable
sm = null;
tmpBroker = null;
if (ImplHelper.isManageable(candidate))
sm = (OpenJPAStateManager) (ImplHelper.toPersistenceCapable(
candidate, ctx.getConfiguration())).
pcGetStateManager();
if (sm == null) {
tmpBroker = ctx.getBroker();
tmpBroker.transactional(candidate, false, null);
sm = tmpBroker.getStateManager(candidate);
}
try {
// get the specified field value and switch candidate
Traversal traversal = (Traversal) action;
candidate = sm.fetchField(traversal.field.getIndex(), true);
} finally {
// transactional does not clear the state, which is
// important since tmpCandidate might be also managed by
// another broker if it's a proxied non-pc instance
if (tmpBroker != null)
tmpBroker.nontransactional(sm.getManagedInstance(), null);
}
}
return candidate;
}