Werner Guttmann wrote:
Just to make sure, it seems liek you are *not* using a mapping file,
correct ?
I want to use mapping file and I assume XMLClassDescriptorResolver would
automatically take care. Is there anyway I can specify mapping files
without using Mapping class?
ANyway I am trying to reuse mapping file usage so that I can get rid of
too many file open problem. I started using following way of doing
marshalling and let me know whther this should solve the IO problem
related to mapping files.
// --------------------------------------------------
//Following code gets loaded duirng startup and reused later
Mapping mapping = XMLContext.createMapping();
mapping.setBaseURL("file:///C:/ranjan/FeedReader/src/conf/mapping");
mapping.loadMapping("Description.xml");
mapping.loadMapping("Product.xml");
// create an XMLContext instance and set mapping
XMLContext context = new XMLContext();
context.addMapping(mapping);
//
------------------------------------------------------------------
//Called to convert object to XML string in each class
StringWriter writer = new StringWriter();
Marshaller marshaller = context.createMarshaller();
marshaller.setWriter(writer); // Is there anyway I can
specify a blank DOM document so that I can use it instead of using
StringWriter
marshaller.marshal(desc);
StringBuffer sbDoc = writer.getBuffer();
System.out.println(sbDoc);
Image img = new Image();
img.setId(11111);
img.setDescription(desc);
marshaller.marshal(img);
sbDoc = writer.getBuffer();
System.out.println(sbDoc);
writer .close();
I would request your valuable input.
- Ranjan
Werner
Ranjan Kumar Baisak wrote:
Thanks for your help. I tried to use XMLClassDescriptorResolver with
Marshaller but Java objects do not get marshalled properly(I got lots
of unnecessary tags in generated XML). I think it uses default
descriptor loading mechanism.
Generated XML :
<?xml version="1.0" encoding="UTF-8"?>
<description dirty="false" persisted="false">
<description-text>This is test</description-text>
<column-method-mapping-data op-type="1" col-index="0">
<table-col-name>id</table-col-name>
<method-name>getId</method-name>
...
....
One of the note in best practices site says "For some of the methods,
pre-loading class descriptors will only work if you provide the
.castor.cdr file with your generated classes" and I dont use
generated classes, instead I use my own classes. Let me add my
marshalling code so that you might be able to suggest.
XMLClassDescriptorResolver classDescriptorResolver =
(XMLClassDescriptorResolver)
ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
classDescriptorResolver.addClass("com.yamaha.portal.site.transport.Description");
Writer writer = new FileWriter("test1.xml");
Marshaller marshaller = new Marshaller();
marshaller.setWriter(writer);
marshaller.setResolver((XMLClassDescriptorResolver)
classDescriptorResolver);
marshaller.marshal(desc);
Let me know if I am doing anything wrong.
regards,
Ranjan
Werner Guttmann wrote:
Sure. Have a look at
http://www.castor.org/xml-best-practice.html
for instructions on how to use the xml class descriptor resolver.
Other than that, you could consider using the new XMLContext class
which will give you a preconfigured XMLClassDescriptorResolver
anyhow. Instructions for using this new classare available at
http://www.castor.org/xml-framework.html#Using-XMLContext-to-bootstrap-Castor
Regards
Werner
P.S. A search on the mailing list archives for terms such as 'usage'
and 'XMLClassDescriptorResolver' might have revealed some intersting
things to read. The archives are available at
http://archive.castor.codehaus.org
Ranjan Kumar Baisak wrote:
Werner Guttmann wrote:
Before starting to have a close look, I wonder whether it would
make a difference to switch to using the
XMLClassDescriptorResolver instead.
Could you please throw some examples for using
XMLClassDescriptorResolver?
regards,
Ranjan
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email