Hi Jason,
Given the current Javadoc, I think it's reasonable to expect that the Writer
you get back from getOutputRouter() will be the same one you passed to
addOutputRouter(). But in fact, it may or may not be, and it depends on what
you ask Jess to do with the router. In the case you've shown here, you should
actually get back the same object; if, on the other hand, you use "WSTDOUT"
or "WSTDERR" for the router name, or use the router as the watch router, then
you'll generally get back a PrintWriter wrapping your original stream. That's
why the return value is Writer -- precisely because you're not supposed to
know what you'll get back.
I can add something to the Javadoc to make this clear.
On Saturday 05 May 2007 2:47:11 pm Jason Morris wrote:
> Hi Ernest,
>
> In the documentation regarding I/O routers (Ch 10. p.66 in the PDF), it
> says:
>
> "...Note also that although these functions accept and return generic
> Reader and Writer objects, Jess internally uses java.io.PrintWriter and
> java.io.BufferedReader. If you pass in other types, Jess will construct one
> of these preferred classes to "wrap" the object you pass in..."
>
> OK, but that seems to create unexpected behavior for
> Rete.getOutputRouter(String
> s).
>
> For example, if I follow JIA p.320 and do something like...
>
> StringWriter sw = new StringWriter();
> engine.addOutputRouter("sw", sw);
>
> ...then later on, I code something like...
>
> StringWriter out = (StringWriter)(engine.getOutputWriter("sw"));
>
> Jess complains that I can't downcast java.io.PrintWriter to StringWriter.
> Upon inspection, it seems like Jess is returning the internally wrapped
> PrintWriter object rather than the StringWriter object that was originally
> assigned to the router. Jess's javadocs say that getOutputRouter() returns
> a java.io.Writer, which seems to hide the fact that it is really returning
> a java.io.PrintWriter. I note that getErrStream() and getOutStream() both
> explicitly return java.io.PrintWriter objects.
>
> What am I missing?
--
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------