* </ul>
* @throws XPathExpressionException XPath module exception.
*/
Branch convertElementToBranch(final Element branchElement, final long parentId) throws XPathExpressionException
{
final BranchDAO branchDao = getDaoFacade().getBranchDAO();
final Branch parent = branchDao.read(parentId);
if (parent == null || branchElement == null) {
throw JournalException.wrapperException(new IllegalArgumentException(Messages.Error.IAE_NULL));
}
Branch targetBranch = new Branch();
final String[] branchProperties = BeanUtils.getProperties(targetBranch, EXCLUDED_PROPS);
for (final String property : branchProperties) {
final Object val = getElementPropValue(branchElement, BeanUtils.getPropertyType(targetBranch, property),
property);
if (val != null) {
try {
org.apache.commons.beanutils.BeanUtils.setProperty(targetBranch, property, val);
} catch (final Exception e) {
throw new JournalException(e.getMessage(), e);
}
}
}
targetBranch.setParent(parent);
final Branch storedBranch = branchDao.readByName(targetBranch.getName(), parentId);
if (storedBranch == null) {
targetBranch.setBranchId(0);
branchDao.save(targetBranch);
} else {
targetBranch = storedBranch;
}
return targetBranch;
}