Commons JXPath
  1. Commons JXPath
  2. JXPATH-60

JXPathContext should allow creation of instances with no bean context associated


    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0 Final
    • Fix Version/s: None
    • Labels:
    • Environment:

      Operating System: All
      Platform: All


      The reason for this is to allow CompiledExpression objects to be created outside
      the context of any bean.

      Attached is a refresher conversation I had with Dmitri.


      The compilation process itself does not require a context at all. The
      only reason the context is involved is that JXPathContext is an
      abstract class that allows multiple implementations of JXPath. The
      actual implementation, along with the compiler is found dynamically.

      I ran into this issue myself when I was writing a Jex-JXPath adapter
      (see There I simply created a
      static context with null for a context node and was using it for all

      I'll add a newContext method without parameters. For that matter I
      don't see what would be wrong with an explicit setRootObject(...)
      method. I'll add that too.

      Could you submit this to Bugzilla so we could track it?


      • Dmitri

      — Ovidiu Predescu <> wrote:
      > Hi Dmitri,
      > I've finally managed to update my code to use your latest 1.0b1
      > release of JXPath: really good stuff, and the documentation is very
      > nice! Thanks a lot for the hard work you put in this, it's really
      > great!
      > I encountered one small problem with the API. In order to obtain
      > CompiledExpression, I need to create a JXPathContext. I want to
      > compile the XPath expressions and assign them to some instance
      > variables of a class, before I actually use them in my methods. There
      > doesn't seem to be a way however to obtain the compiled
      > representation
      > without providing a bean when creating the context. So the current
      > code I have reads like this:
      > JXPathContext jxpathContext = JXPathContext.newContext(new
      > Object());
      > CompiledExpression jxpath_a = jxpathContext.compile("a");
      > jxpath_a.getValue(someJXPathContext);
      > Would it be possible to eliminate the need to pass a bean context in
      > newContext()? I think the API for compiled expressions would be a bit
      > cleaner. I can live with it as it is, no problem, it's just that
      > would
      > be cleaner this way.


        Ovidiu Predescu created issue -
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 8924 12340221
        Henri Yandell made changes -
        Key COM-70 JXPATH-60
        Component/s JXPath [ 12311120 ]
        Affects Version/s 1.0 Beta 1 [ 12311649 ]
        Project Commons [ 12310458 ] Commons JXPath [ 12310480 ]
        Assignee Jakarta Commons Developers Mailing List [ ]
        Henri Yandell made changes -
        Affects Version/s 1.0 Beta 1 [ 12311816 ]


          • Assignee:
            Ovidiu Predescu
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: