[jdom-interest] MORE ABOUT: Problem with Jdom8 - getChildren() on root ...

Tom Preston tpreston at amadeusboston.com
Fri Mar 29 09:12:51 PST 2002


There IS more to the story.  We are using EJB.  When we get rid of the EJB
aspect the problem goes away.  So, we find that the problem is returning a
jdom 8 Document from EJB.  Something in the marshalling process is messing
up the document so that root.hasChildren() returns true while
root.getChildren returns a zero sized list after ANY Document has been
returned from ANY EJB method.  Here is the trivial example for reproduction:
 
Make an EJB which has this signature in the RemoteInterface:
 
  public Document getSimpleDoc() throws Exception, RemoteException;
 
In the EJBean class implement the remote interface:
 
  public Document getSimpleDoc() throws Exception {
    Element theRoot = new Element("Root");
    Element levelA = new Element("A");
    Element levelB = new Element("B");
    levelB.addContent(new Element("levelB").addContent("5"));
    theRoot.addContent(levelA.addContent(levelB));
    Document doc = new Document(theRoot);
Element root = doc.getRootElement();
System.out.println("Inside of the EJB Method: root.hasChildren(): " +
root.hasChildren() + " root.getChildren().size(): " +
root.getChildren().size() );
    return doc;
  }

 
Now make a trivial JSP to call the EJB getSimpleDoc() method:
 
<%@ page import="
  javax.naming.*;
  com.mycompany.ejb.session.productdisplay.*;
  org.jdom.*;
  org.jdom.output.XMLOutputter;
  com.mycompany.utilities.*;"    
  errorPage="/components/common/ErrorPage.jsp"
%>
<%
  Context ctx = Utils.getServerInitialContext();
  ProductDisplayHome productDisplayHome =
(ProductDisplayHome)ctx.lookup("ProductDisplayHome");
  ProductDisplay productDisplay = productDisplayHome.create();
  Document doc = productDisplay.getSimpleDoc();
Element root = doc.getRootElement();
out.print("Inside of the JSP (the Caller) Method: root.hasChildren(): " +
root.hasChildren() + " root.getChildren().size(): " +
root.getChildren().size() );
//  XMLOutputter xo = new XMLOutputter("  ", true);
//  xo.output(doc,System.out);

%>
 
You will see that the System.out.println from WITHIN the EJB (before the
Document gets returned -- and therefore, before it gets marshalled and
unmarshalled) prints out:
 
   Inside of the EJB Method: root.hasChildren(): true
root.getChildren().size(): 1
 
But inside of the JSP when dealing with the Document that has gone thru
serialization (marshalling and unmarshalling) you get:
 
  Inside of the JSP (the Caller) Method: root.hasChildren(): true
root.getChildren().size(): 0 
 
For the very same Document...the only difference being that the Document was
passed thru EJB Marshalling and Unmarshalling, you have two different
getChildren() of root results.  
 
My theory is that something in JDOM version 8 RC has made some field
"transient" that shouldn't be and therefore the Document object is different
before serialization than it is after serialization.
 
I think that this is a major problem for anyone returning Document objects
from EJB methods (like we were).
 
Thanks
 
Tom Preston

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20020329/4ed926e2/attachment.htm


More information about the jdom-interest mailing list