jdic
  1. jdic
  2. JDIC-167

Refactoring browser package; introducing Factory pattern

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: current
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      167

      Description

      Jdic is great, but currently there is an implicit assumption, that there are
      only two potential embedded browsers (IE and Mozilla) and that embedding one of
      them will be successful.

      This is a problem for cross-platform applications that want to use Jdic. They
      may need to fall back on other browsers (e.g. a pure Java Browser, some other
      embedded browser, a JEditorPane, or a custom solution) for cases where Jdic
      provides no browser or where Jdic is not able to launch the presumably existing
      default browser. Thus cross-platform applications need to add their own logic
      for deciding when to use Jdic and for checking whether Jdic is successful.

      To eliminate these problems, I would like to propose a refactoring of the
      current browser package. It is not hard and I would be willing to do this.

      The basic approach would be as follows:
      Use a factory pattern. Introduce a
      BrowserFactory interface and default implementation.
      The BrowserFactory would be responsible for creating a Browser instance by
      delegating to a BrowserEngine. Each browser type (Mozilla, IE, or others) would
      have their respective engine. BrowserEngines can be registered and unregistered
      from the BrowserFactory. BrowserEngine instances are able to determine whether
      their browser component is available in the current environment, they have
      specific information about that BrowserComponent (e.g. binary file, version,
      etc.) and they can create a browser instance.

      When a BrowserFactory is created, it loads its list of BrowserEngines. An
      application can add its own engines to the factory or replace engines with newer
      versions. When a new web browser instance needs to be created, the
      BrowserFactory queries its registered BrowserEngines as to whether they are
      available (this happens only the first time). The default implementation of
      BrowserFactory would determine the default browser, check if an associated
      BrowserEngine is available and then ask that BrowserEngine to return a new
      browser instance. If the default browser engine is not available it would use
      the first other BrowserEngine for which a browser component is available. But
      other implementations might use different approaches.

      The WebFactory could also be used to query the different BrowserEngines to see
      which is/are available before actually instantiating a browser.

      Using a factory approach simplifies many things. It would make Jdic even more
      open, more flexible and would make it much easier to add support for more
      browser components.

      1. issue167_patch_1.diff
        30 kB
        georgez
      2. issue167_patch_2.diff
        12 kB
        georgez
      3. issue167_patch_3.diff
        17 kB
        georgez
      4. issue167.zip
        38 kB
        georgez
      5. UTCases.doc
        23 kB
        michael_shan

        Issue Links

          Activity

          Hide
          alexanderhars added a comment -

          Created an attachment (id=168)
          Source file changes

          Show
          alexanderhars added a comment - Created an attachment (id=168) Source file changes
          Hide
          georgez added a comment -

          Created an attachment (id=170)
          Patch based on Issue167.zip (Thu Mar 10 14:42:00 +0000 2005)

          Show
          georgez added a comment - Created an attachment (id=170) Patch based on Issue167.zip (Thu Mar 10 14:42:00 +0000 2005)
          Hide
          georgez added a comment -

          Patch issue167_patch_3.diff was made based on Issue167.zip (Thu Mar 10 14:42:00
          +0000 2005), and checked into the CVS tree.

          Show
          georgez added a comment - Patch issue167_patch_3.diff was made based on Issue167.zip (Thu Mar 10 14:42:00 +0000 2005), and checked into the CVS tree.
          Hide
          michael_shan added a comment -

          Created an attachment (id=230)
          UT cases for issue167

          Show
          michael_shan added a comment - Created an attachment (id=230) UT cases for issue167
          Hide
          michael_shan added a comment -

          Hi,

          Finised this issue.

          New introduced classes(Mainly by alexanderhars):
          1 org.jdesktop.jdic.browser.BrowserEngineManager

          • Factory pattern used to maintain instances of <code>IBrowserEngine</code>.
          • Could specify which engine to use

          2 org.jdesktop.jdic.browser.IBrowserEngine
          This class represents a wrapper around an embedded browser engine. It returns

          information about the browser type being used, the availability of the
          embedded browser engine on the current system.

          3 org.jdesktop.jdic.browser.InternetExplorerEngine
          Engine for IE, handles the communication with Internet Explorer

          4 org.jdesktop.jdic.browser.MozillaEngine
          Engine for Mozilla, handles the communication with Internet Explorer

          5 org.jdesktop.jdic.browser.IWebBrowser
          An interface defines common actions for a IWebBrowser to obey. Any extended
          web browser should implement this interface.

          Moves:
          1 MsgClient goto internal
          2 NativeEventData goto internal
          3 NativeEventThread goto internal
          4 Merge WebBrowserUtil and goto internal

          Mainly Code Changes:
          1 org.jdesktop.jdic.browser.WebBrowser

          • Implement methods of IWebBrowser
          • Delegate initialize actions to activeEngine not by JDICManager's
            initNativeBrowser.
            2 org.jdesktop.jdic.init.JdicManager
          • Removed initShareNative(), deletge this function to IBrowserEngines.

          Please refer test cases as the attchment.

          Show
          michael_shan added a comment - Hi, Finised this issue. New introduced classes(Mainly by alexanderhars): 1 org.jdesktop.jdic.browser.BrowserEngineManager Factory pattern used to maintain instances of <code>IBrowserEngine</code>. Could specify which engine to use 2 org.jdesktop.jdic.browser.IBrowserEngine This class represents a wrapper around an embedded browser engine. It returns information about the browser type being used, the availability of the embedded browser engine on the current system. 3 org.jdesktop.jdic.browser.InternetExplorerEngine Engine for IE, handles the communication with Internet Explorer 4 org.jdesktop.jdic.browser.MozillaEngine Engine for Mozilla, handles the communication with Internet Explorer 5 org.jdesktop.jdic.browser.IWebBrowser An interface defines common actions for a IWebBrowser to obey. Any extended web browser should implement this interface. Moves: 1 MsgClient goto internal 2 NativeEventData goto internal 3 NativeEventThread goto internal 4 Merge WebBrowserUtil and goto internal Mainly Code Changes: 1 org.jdesktop.jdic.browser.WebBrowser Implement methods of IWebBrowser Delegate initialize actions to activeEngine not by JDICManager's initNativeBrowser. 2 org.jdesktop.jdic.init.JdicManager Removed initShareNative(), deletge this function to IBrowserEngines. Please refer test cases as the attchment.

            People

            • Assignee:
              alexanderhars
              Reporter:
              alexanderhars
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: