I discovered the problem, and it was actually not to do with the Castor
library itself but in the way the class loader was being used by the Mapping
object and the instance of Xalan that was used by Castor.

My class was running within a Web application running in JBoss, and I
figured out that a different version of Xalan was being used than the one I
thought and also JBoss uses different class loaders for different
applications running on the same server which caused problems until I
configured it properly. The results of this was very slow execution of the
marshal() method.

Anyhow all is working fine now. Many thanks.

Oisin.


On 15/11/2007, Werner Guttmann <[EMAIL PROTECTED]> wrote:
>
> Looking at the code (fragments) supplied, I cannot see anything that is
> obviously wrong. In other words, we need to have a more detailed look at
> this. Can I please ask you to crete a new JIra issue and attach a fully
> fledged JUnit test case that highlights the issue. Please do not forget
> to attach all relevant files, incl. mapping file, Java classes, etc.
>
> Please have a look at
>
> http://castor.org/how-to-submit-an-xml-bug.html
>
> for guidelines on how to create such a test case.
>
> Regards
> Werner
>
>
> Oisin Boydell wrote:
> > Hi,
> >
> > I'm having a problem with the speed of marshalling objects to XML, and
> > it seems strange to me that when I supply a mapping file to the
> > marshaller the marshal(Object) method actually takes longer to execute
> > than when I don't supply a mapping (so it marshals by introspection).
> >
> > Here is my code with the timing of the .marshal(Object) method:
> >
> > StringWriter sw = new StringWriter();
> >
> > Marshaller marshaller = new Marshaller(sw);
> >
> > marshaller.setMarshalAsDocument(false);
> > marshaller.setSuppressXSIType (true);
> > marshaller.setValidation(false);
> > marshaller.setMapping(mapping);
> >
> > Date then = new Date();
> > marshaller.marshal(this);
> > long ms = new Date().getTime() - then.getTime();
> >
> > However if I replace " marshaller.marshal(this);" with
> > "Marshaller.marshal(this, sw);" so it uses introspection instead of the
> > specified mapping then the method completes way quicker. In fact it
> > takes up to a second to marshal the object and they are not very large
> > or complex objects so I suspect something is wrong. I would have thought
> > that introspection would be slower. I've tried all the techniques such
> > as caching a ClassDescriptorResolver but the slow execution is actually
> > when marshalling with the marshal(Object) method and not the loading of
> > the mapping file etc.
> >
> > Maybe there is something wrong with the mapping file I'm using? Here is
> is:
> >
> > <?xml version="1.0"?>
> > <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version
> > 1.0//EN" " http://castor.org/mapping.dtd";>
> >
> > <mapping>
> >     <description>Mapping of CwsResult and associated
> classes</description>
> >
> >     <class name=" util.result.SelectionData">
> >
> >          <map-to xml="SELECTION_DATA" />
> >
> >         <field name="query" set-method="setQuery" get-method="getQuery"
> > type="string" >
> >               <bind-xml name="QUERY" node="element" />
> >           </field>
> >
> >           <field name="snippet" set-method="setSnippet"
> > get-method="getSnippet" type="string">
> >               <bind-xml name="SNIPPET" node="element" />
> >           </field>
> >
> >           <field name="timestamp" set-method="setTimestamp"
> > get-method="getTimestamp" type="date" >
> >               <bind-xml name="TIMESTAMP" node="attribute" />
> >           </field>
> >
> >     </class>
> >
> >     <class name="util.result.RecommenderSelectionData ">
> >
> >          <map-to xml="RECOMMENDER_SELECTION_DATA" />
> >
> >         <field name="score" set-method="setScore" get-method="getScore"
> > type="double" >
> >               <bind-xml name="SCORE" node="element" />
> >           </field>
> >
> >           <field name="selections" set-method="setSelections"
> > get-method="getSelections" type=" util.result.SelectionData"
> > collection="arraylist">
> >               <bind-xml name="SELECTIONS" node="element" />
> >           </field>
> >
> >           <field name="userId" set-method="setUserId"
> > get-method="getUserId" type="long" >
> >               <bind-xml name="USERID" node="attribute" />
> >           </field>
> >
> >     </class>
> >
> >     <class name=" util.result.CwsResult">
> >
> >         <map-to xml="RESULT" />
> >
> >         <field name="title" set-method="setTitle" get-method="getTitle"
> > type="string" >
> >               <bind-xml name="TITLE" node="element" />
> >           </field>
> >
> >           <field name="displaySnippet" set-method="setDisplaySnippet"
> > get-method="getDisplaySnippet" type="string" >
> >               <bind-xml name="DISPLAY_SNIPPET" node="element" />
> >           </field>
> >
> >           <field name="displayUrl" get-method="getDisplayUrl"
> > type="string" >
> >               <bind-xml name="DISPLAY_URL" node="element" />
> >           </field>
> >
> >           <field name="url" set-method="setUrl" get-method="getUrl"
> > type=" java.net.URL" >
> >               <bind-xml name="URL" node="element" />
> >           </field>
> >
> >           <field name="urlHash" set-method="setUrlHash"
> > get-method="getUrlHash" type="string" >
> >               <bind-xml name="URLHASH" node="attribute" />
> >           </field>
> >
> >           <field name="recommenderSelectionData"
> > set-method="setRecommenderSelectionData"
> > get-method="getRecommenderSelectionData" type="
> > util.result.RecommenderSelectionData" collection="arraylist">
> >               <bind-xml name="RECOMMENDER_SELECTION_DATA" node="element"
> />
> >           </field>
> >
> >     </class>
> > </mapping>
> >
> > I would appreciate any help or suggestions as I'm using the marshalling
> > for a Web application and the time delay for marshalling 10 or so
> > objects when generating a Web page is unacceptable (up to 10 seconds).
> > I've seen Castor being used in the same way for other Web applications
> > which do not seem to suffer from this speed problem and they are using
> > Castor in the same way as I am.
> >
> > Many thanks and looking forward to all replies,
> > Oisin.
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

Reply via email to