Thanks Werner by the answer,
but in my project I can't use unstable version, when the version 1.2.1 gonna be 
stable I'll update the Castor. So, until there, and this is my question, How is 
the better thing to do to set InitialContext of ClassDescriptorResolver? To use 
BackWardCompatibilityContext as the itself documentation say is not a good 
choice but we have other options ?

Thanks,

 *-----------------------------------------------------*
|| Marcelo Henrique De Oliveira Lima
|| Ciência da Computação - UECE
|| Linux User #399803
|| Slackware GNU/Linux Powered!
*-----------------------------------------------------*



----- Mensagem original ----
De: Werner Guttmann <[EMAIL PROTECTED]>
Para: [email protected]
Enviadas: Quarta-feira, 28 de Maio de 2008 17:23:44
Assunto: Re: Res: [castor-user] Changing classloader in marshaller

As already mentioned elsewhere, the issue with an NPE in
ClassDescriptorResolver has already been reported shortly after 1.2 has
been released, and has already been fixed in SVN trunk.

Have a look at the latest 1.2.1 snapshot release, as this should work
straight out of the box.

Werner

Marcelo Henrique wrote:
> Hi,
> I had the same problem with InitialContext null in ClassDescriptorResolver 
> too. Thus I initilize it with BackwardCompatibilityContext but I've seen that 
> BackwardCompatibilityContext will be unused in the future versions of Castor 
> so, What's the better way of use ClassDescriptorResolver or how can I 
> initilize the InitialContext without use BackwardCompatibilityContext?
> 
> My Code:
> 
> Mapping mapping = getMapping( mapeamento );
> XMLClassDescriptorResolver classDescriptorResolver = ( 
> XMLClassDescriptorResolver ) 
> ClassDescriptorResolverFactory.createClassDescriptorResolver( BindingType.XML 
> );
> classDescriptorResolver.setInternalContext( new 
> BackwardCompatibilityContext() );
> MappingUnmarshaller mappingUnmarshaller = new MappingUnmarshaller();
> MappingLoader mappingLoader = mappingUnmarshaller.getMappingLoader( mapping, 
> BindingType.XML );
> classDescriptorResolver.setMappingLoader( mappingLoader );
> 
> Thanks,
> 
>  *-----------------------------------------------------*
> || Marcelo Henrique De Oliveira Lima
> || Ciência da Computação - UECE
> || Linux User #399803
> || Slackware GNU/Linux Powered!
> *-----------------------------------------------------*
> 
> 
> 
> ----- Mensagem original ----
> De: brandywheat <[EMAIL PROTECTED]>
> Para: [email protected]
> Enviadas: Quarta-feira, 28 de Maio de 2008 6:45:49
> Assunto: Re: [castor-user] Changing classloader in marshaller
> 
> 
> Hi,
> I have this working - I found that I had a couple of problems, first the
> code shown on the web gives a null pointer exception (because the internal
> context is not set in classDR). 
> The second was that I was calling m.marshall(this, writer) and I did not
> realize that this was a static method, once I changed this to the
> m.marshall(this) it worked .... the final code is then:
> 
> public void export(Writer writer) throws MarshalException,
> ValidationException {
>     try {
>       Marshaller m = new Marshaller();
>      XMLClassDescriptorResolver classDR =
> (org.exolab.castor.xml.XMLClassDescriptorResolver)
>        
> ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
>       classDR.setInternalContext(m.getInternalContext());
>    
> classDR.setClassLoader(Thread.currentThread().getContextClassLoader());
>       classDR.addClass("com.xxxx.domain.Theme");
>       m.setResolver(classDR);
>       m.setWriter(writer);
>       m.marshal(this);
>     } catch (....)
> }
> 
> Many thanks,
> Brian 
> 
> 
> Werner Guttmann wrote:
>> Hi,
>>
>> how about trying things with the XMLClassDescriptorResolver document
>> first, to get and/or keep you going.
>>
>> Have a look at the XML best practise document at http://www.castor.org,
>> and let us know whether this is enough information.
>>
>> Werner
>>
>> brandywheat wrote:
>>> Hi,
>>>  I do not have enough experience with castor (yet) to see either method
>>> being beneficial over the other ... so I will take what ever you suggest. 
>>>  Working from the snapshot is not an issue, nor is waiting a couple of
>>> days
>>> a problem - what ever is best for you - I'll be happy when it is working!
>>>  
>>>  I do have a couple of class to marshal and these include quite a few
>>> classes (30+) which are included in the output structure - I am not sure
>>> if
>>> this would be an issue with option b (do I have to add a
>>> classDescriptionResolver for each class ?).
>>>
>>>  Many, many thanks for the super response on this, I am suitably
>>> impressed 
>>> :-)
>>>
>>> Thanks,
>>>   Brian 
>>>
>>>
>>>
>>> Werner Guttmann wrote:
>>>> Well, in that case, there's two options:
>>>>
>>>> a) switch to XMLContext (where we'd have to add a setClassLoader()
>>>> method, which is sufficiently easy; if you are fine working against a
>>>> snapshot releaswe, this could be done within one or two days).
>>>>
>>>> b) Set an XMLClassDescriptorResolver on your Marshaller, and use
>>>> XMLClassDescriptorResolver.setClassLoader() to set a custom class
>>>> loader.
>>>>
>>>> Does this make sense ...
>>>>
>>>> Werner
>>>>
>>>>
>>>> brandywheat wrote:
>>>>> Hi, 
>>>>>  I'm on the latest castor version (1.2) ... 
>>>>>
>>>>> Thanks,
>>>>>  Brian 
>>>>>
>>>>>
>>>>>
>>>>> Werner Guttmann wrote:
>>>>>> Hi,
>>>>>>
>>>>>> What version of Castor are you using ? There's a solution to this
>>>>>> problem, but it depends on whether you are on a release that has
>>>>>> support
>>>>>> for XMLContext already (or not).
>>>>>>
>>>>>> Werner
>>>>>>
>>>>>> brandywheat wrote:
>>>>>>> Hi,
>>>>>>>  I am currently having problems with the castor marshaller and
>>>>>>> classloaders. 
>>>>>>>  My code works in the unit tests but fails once included in a
>>>>>>> netbeans
>>>>>>> RPC -
>>>>>>> the problem looks to be the classloader and the modules within the
>>>>>>> RPC. 
>>>>>>>  
>>>>>>>  I can resolve the issue of the classloader with the code:
>>>>>>>       Marshaller m = new Marshaller();
>>>>>>>       Mapping mapping = new
>>>>>>> Mapping(Thread.currentThread().getContextClassLoader());
>>>>>>>       mapping.loadMapping("c:\\temp\\mapping.xml");
>>>>>>>       m.setMapping(mapping);
>>>>>>>       m.marshal(this, writer);
>>>>>>>
>>>>>>>  But this forces me to write a mapping file, which I do not have
>>>>>>> available
>>>>>>> and do not really want to generate.
>>>>>>>
>>>>>>>  Is it possible to set the classloader for the marshaller without
>>>>>>> having
>>>>>>> to
>>>>>>> define a mapping file, e.g. have it use the default structure it
>>>>>>> would
>>>>>>> generated without a mapping file? (If I skip the loadMapping then the
>>>>>>> setMapping gives an exception saying a mapping must be loaded
>>>>>>> first....)
>>>>>>>
>>>>>>> Thanks in Advance,
>>>>>>>   Brian 
>>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> 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


      Abra sua conta no Yahoo! Mail, o único sem limite de espaço para 
armazenamento!
http://br.mail.yahoo.com/

Reply via email to