0 Replies Latest reply on Apr 24, 2008 9:28 AM by Tom Baeyens

    stream handlling and parsing api

    Tom Baeyens Master

      I just committed the result of 3 tasks that got intermingled:

      a) While working on the deployment, I unified the stream handling.

      Package org.jbpm.stream contains classes to treat files, urls, resources and byte arrays in the same way: A new class StreamSource is created like this:

      public abstract class StreamSource {
      
       public abstract InputStream openStream();
      
       ...
      }


      So all the concrete StreamSource classes know how to convert files, urls, resources and byte arrays into an input stream.


      b) Cause of this work, I made sure that the class loader lookup was more unified the complete project. The strategy that now is implemented over the whole pvm project to look for a classloader is the following:

      1) if the user supplied a classloader in the object that you're working with, that is taken. for example a classloader can be provided in a parse operation, in a deploy command for finding the resource and so on.

      2) if there is a current environment and that environment has a (user supplied) classloader, then that one is taken

      3) the Thread.currentThread().getContextClassLoader() is taken.


      c) Last implication was that I revised the xml parsing API to be synchronized with the StreamSource architecture. In the course of that, I also improved the API a bit. Previously you had to maintain your own reference to the Parse object if you wanted something else then the document object. Now, the parser serves as a factory for parse's and consequetive method invocations on the parse will configure the parsing, execute it, optionally throw an exception if there are problems and then extract the desired result.

      For example:

       BusinessCalendar businessCalendar = (BusinessCalendar) businessCalendarParser
       .createParse()
       .setResource("business.calendar.xml")
       .execute()
       .checkProblems("business calendar string")
       .getDocumentObject();
      


      1) First the parser creates a Parse object with the createParse() method.
      2) Then there are a set of methods with which the stream source can be specified: setResource(...), setUrl(...), setFile(...), setString(...), ...
      3) Then the execute method will do the xml parsing (build the dom tree), close the inputstream (if one was opened) and walk the dom tree by delegating to the parseDocumentElement(Element) that all the parsers can override.
      4) checkProblems will see if there were any problems reported during parsing of the XML or during the walking of the dom tree. if there are problems of at least level ERROR, then a PvmException is thrown.
      5) getDocumentObject() retrieves the object that was the main result of the parsing

      hoe this gets you guys going... let me know if there is feedback or any other comments on these additions/changes

      regards, tom.