Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-317

Idiom for acquiring a HierarchyManager could be simplified.

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Minor
    • 3.0 RC1
    • 2.1 Final
    • core
    • 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.

      Checklists

        Acceptance criteria

        Attachments

          Activity

            People

              kraft Boris Kraft
              db@dawnbreaks.net David Bullock
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Checklists

                  Task DoD