Details
-
Improvement
-
Resolution: Fixed
-
Minor
-
2.1 Final
-
None
-
n/a
Description
This idiom crops up quite a lot in client code:
HierarchyManager hm = new HierarchyManager(request);
try
{ Session t = SessionAccessControl.getSession(request,repository); Node rootNode = t.getRootNode(); hm.init(rootNode); }catch (Exception e) {}
It would be easier on clients if one had something like:
// plus, xf http://jira.magnolia.info/browse/MAGNOLIA-316
public static HierarchyManager acquire(HttpServletRequest request, String repositoryId)
{ Session t = SessionAccessControl.getSession(request,repository); return acquire(request, t); }public static HierarchyManager acquire(HttpServletRequest request, Session t)
{ requrn acquire(request, t.getRootNode()); }public static HierarchyManager acquire(HttpServletRequest request, Node n)
{ return new HierarchyManager(request, n); }In such a way, the idiom could be simplified to:
HierarchyManager hm = HierarchyManager.acquire(req, "website");
One issue here is what to do with exceptions ... the old idiom swallows them, yielding a partially-initialized HierarchyManager which would NullPointer for some future requests (eg. createContent) but succeed for others (eg. setMetaData). It is probably best to throw exceptions from the factory methods.