Hi Martin,

can I assume that you have come across the auto-complete attribute o a class mapping ? If not, it might be worth it. By using that mode, you basically define partial mappings for classes (e.g. define a mapping for those parts where the default is not applicable to your needs), and let Castor (through) introspection figure out the remainder of the (class) mapping.

Iow, no need to fiddle around with creating mappings programatically.

Regards
Werner

On 20.05.2010 16:44, [email protected] wrote:
Thanks for the code Brian. Nearly does it. The only problem with this is
that if I do the following:



MapTo mapTo = new MapTo();

mapTo.setXml("myCustomTagName");



ClassMapping rootClassMapping = new ClassMapping();

rootClassMapping.setName(MyType.class.getName());

rootClassMapping.setMapTo(mapTo);



xmlContext.addMapping(new
Mapping().getRoot().addClassMapping(rootClassMapping));



...I have to do the mapping of the fields of MyType myself. What I'm
really trying to do is let Castor introspect my class

and then just override the xml-name it created for it (which in this
case would be 'myType').



Von: Brian Sanders [mailto:[email protected]]
Gesendet: Donnerstag, 20. Mai 2010 14:57
An: [email protected]
Betreff: RE: [castor-user] Dynamic Runtime Mapping with Castor



Not sure what you're trying to accomplish, but it sounds like something
I've done. Therefore, I will share the code...
See: http://cl1p.net/XmlEntityParser/

________________________________

Date: Thu, 20 May 2010 10:19:30 +0200
From: [email protected]
To: [email protected]
Subject: [castor-user] Dynamic Runtime Mapping with Castor

Hello everyone,



I'm wondering if there is a way to modify the xml-name of a top-level
class programmatically? My current solution works like this:



...

((XMLClassDescriptorImpl)this.marshaller.getResolver().resolve(marshalle
rTarget.getClass())).setXMLName("myCustomXMLName");

this.marshaller.marshal(marshallerTarget);

...



As you already may have noticed the problem with the above solution is
the unchecked cast to XMLClassDescriptorImpl as it is not guaranteed
that the resolve-method

returns an object of this type. For example if I pass an object of type
String to the resolve-method I get a StringClassDescriptor. In general
it would be interesting if there is a possibility to

modify the mapping-information (i.e. the state of the descriptors in
memory) at runtime without having to do conditional castings by using
instanceof-checks to get the appropriate descriptor.



Thanks in advance,



Best regards,



Martin





________________________________

Hotmail has tools for the New Busy. Search, chat and e-mail from your
inbox. Learn more.
<http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL
:ON:WL:en-US:WM_HMP:042010_1>



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to