castor-xml writing empty file

View: New views
11 Messages — Rating Filter:   Alert me  

castor-xml writing empty file

by mohn3310 :: Rate this Message:

| View Threaded | Show Only this Message

Hello,

I'm using castor-xml in introspection mode to write out simple POJOs to files (one POJO per file). I've written unit tests and verified that this works. I've also inspected the files and made sure they have appropriate xml.

I then packaged this up into an osgi bundle and deployed it to a container (felix). For some reason when I run it, it ends up creating the file but it is empty... i.e. no xml in the file. Yet another strange thing is that I use Unmarshaller.unmarshall() to convert the xml files back to their associated POJOs. As a test I generated the xml by hand and it was able to load it. So Marshaller.marshall() doesn't work, but Unmarshaller.unmarshall() does!

Any idea why it is behaving this way? Same code... works great "normally", but doesn't work inside an osgi container.

Thanks,
Mohnish

Re: castor-xml writing empty file

by mohn3310 :: Rate this Message:

| View Threaded | Show Only this Message

I did have a dependency issue when i deployed it to the osgi container. castor-xml uses com.sun.org.apache.xml.internal.serialize in jdk5+, which is not exported by the osgi system bundle (it is not part of the standard java library but rather an implementation detail). To resolve this, I created a fragment bundle and exported the package.

Thought to mention this in case it has any bearing on the problem.

Thanks,
Mohnish

mohn3310 wrote:
Hello,

I'm using castor-xml in introspection mode to write out simple POJOs to files (one POJO per file). I've written unit tests and verified that this works. I've also inspected the files and made sure they have appropriate xml.

I then packaged this up into an osgi bundle and deployed it to a container (felix). For some reason when I run it, it ends up creating the file but it is empty... i.e. no xml in the file. Yet another strange thing is that I use Unmarshaller.unmarshall() to convert the xml files back to their associated POJOs. As a test I generated the xml by hand and it was able to load it. So Marshaller.marshall() doesn't work, but Unmarshaller.unmarshall() does!

Any idea why it is behaving this way? Same code... works great "normally", but doesn't work inside an osgi container.

Thanks,
Mohnish

Re: castor-xml writing empty file

by Joachim Grüneis :: Rate this Message:

| View Threaded | Show Only this Message

Hello,

I try to help you with some hints... but to be more precise I have not enough information

It seams that you use the static methods of marshaller and unmarshaller - this often leads to problems as no configuration step takes place which e.g. would load the mapping information...

so please instantiate an XMLContext, introduce the classes to map by using addClass or loadMapping, create marshaller and unmarshaller  instance and work with this instance - that might already solve your problem

on the other hand you might have a problem caused by class loading mechanisms of felix (OSGi)
marshaling takes existing Java objects instances and serializes them into XML - no problem there, all Java classes are known and can easily be marshaled to XML without any mapping information...
the other way round is more complicated
Caster has to find a corresponding class for each element found in the XML and needs to be able to instantiate this class - this is where two problems might occur:
1) no matching class can be found, mapping information is not available cause static methods are used so nothing is unmarshalled
2) no matching class can be found because Castor is not allowed to access these classes because they are bound to a different class loader

These are just some ideas of what might have happend...

to really help it is required to know more about your implementation:
Is an XSD definition existing?
Has the Java code been generated using code generator?
Have you included the .cdr files into the jar?
Do you use a mapping file?
How does the marshaling/unmarshaling code look like?

Hth Joachim

2009/6/24 mohn3310 <mohn3310@...>

Hello,

I'm using castor-xml in introspection mode to write out simple POJOs to
files (one POJO per file). I've written unit tests and verified that this
works. I've also inspected the files and made sure they have appropriate
xml.

I then packaged this up into an osgi bundle and deployed it to a container
(felix). For some reason when I run it, it ends up creating the file but it
is empty... i.e. no xml in the file. Yet another strange thing is that I use
Unmarshaller.unmarshall() to convert the xml files back to their associated
POJOs. As a test I generated the xml by hand and it was able to load it. So
Marshaller.marshall() doesn't work, but Unmarshaller.unmarshall() does!

Any idea why it is behaving this way? Same code... works great "normally",
but doesn't work inside an osgi container.

Thanks,
Mohnish
--
View this message in context: http://www.nabble.com/castor-xml-writing-empty-file-tp24175804p24175804.html
Sent from the Castor - User mailing list archive at Nabble.com.


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

   http://xircles.codehaus.org/manage_email




Re: castor-xml writing empty file

by mohn3310 :: Rate this Message:

| View Threaded | Show Only this Message

Hi Joachim,

Thanks for your response.

There is no mapping information and is using static Marshall/Unmarshall methods. Here is that code:

private void save(String location, Object o) throws Exception {
        FileWriter writer = null;
       
        try {
        writer = new FileWriter(location);
                Marshaller.marshal(facet, o);
        } finally {
        writer.close();
        }
}

private <T> T load(String location, Class<T> c) throws Exception {
        FileReader reader = null;
       
        try {
            reader = new FileReader(location);
            return (T) Unmarshaller.unmarshal(c, reader);
        } finally {
            reader.close();
        }
}

The answers to the rest of your questions are all No.  The code is very basic. We wanted something extremely simple so we started with this.

I can try using the non-static marshaller/unmarshaller, but can it be used without a class specific mapping file?

Let me know if I can provide any more information.

Thanks,
Mohnish

Joachim Grüneis wrote:
Hello,
I try to help you with some hints... but to be more precise
I have not enough information

It seams that you use the static methods of marshaller and unmarshaller -
this often leads to problems as no configuration step takes place which e.g.
would load the mapping information...

so please instantiate an XMLContext, introduce the classes to map by using
addClass or loadMapping, create marshaller and unmarshaller  instance and
work with this instance - that might already solve your problem

on the other
hand you might have a problem caused by class loading mechanisms of felix (OSGi)
marshaling takes existing Java
objects instances and serializes them into XML - no problem there, all
Java classes are known and can easily be
marshaled to XML without any mapping information...
the other way round is more complicated
Caster has to find a corresponding class for each element found in the XML
and needs to be able to
instantiate this class - this is where two problems might occur:
1) no matching class can be found, mapping information is not
available cause static methods are used so nothing is unmarshalled
2) no matching class can be found because Castor is not allowed to
access these classes because they are bound to a different class
loader

These are just some ideas of what might have happend...

to really help it is required to know more about your implementation:
Is an XSD definition existing?
Has the Java code been generated using code generator?
Have you included the .cdr files into the jar?
Do you use a mapping file?
How does the marshaling/unmarshaling code look like?

Hth Joachim

2009/6/24 mohn3310 <mohn3310@gmail.com>

>
> Hello,
>
> I'm using castor-xml in introspection mode to write out simple POJOs to
> files (one POJO per file). I've written unit tests and verified that this
> works. I've also inspected the files and made sure they have appropriate
> xml.
>
> I then packaged this up into an osgi bundle and deployed it to a container
> (felix). For some reason when I run it, it ends up creating the file but it
> is empty... i.e. no xml in the file. Yet another strange thing is that I
> use
> Unmarshaller.unmarshall() to convert the xml files back to their associated
> POJOs. As a test I generated the xml by hand and it was able to load it. So
> Marshaller.marshall() doesn't work, but Unmarshaller.unmarshall() does!
>
> Any idea why it is behaving this way? Same code... works great "normally",
> but doesn't work inside an osgi container.
>
> Thanks,
> Mohnish
> --
> View this message in context:
> http://www.nabble.com/castor-xml-writing-empty-file-tp24175804p24175804.html
> Sent from the Castor - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

Re: castor-xml writing empty file

by mohn3310 :: Rate this Message:

| View Threaded | Show Only this Message


Hi Joachim,

Thanks for your response.

There is no mapping information and is using static Marshall/Unmarshall
methods. Here is that code:

private void save(String location, Object o) throws Exception {
        FileWriter writer = null;
       
        try {
        writer = new FileWriter(location);
                Marshaller.marshal(facet, o);
        } finally {
        writer.close();
        }
}

private <T> T load(String location, Class<T> c) throws Exception {
        FileReader reader = null;
       
        try {
            reader = new FileReader(location);
            return (T) Unmarshaller.unmarshal(c, reader);
        } finally {
            reader.close();
        }
}

The answers to the rest of your questions are all No.  The code is very
basic. We wanted something extremely simple so we started with this.

I can try using the non-static marshaller/unmarshaller, but can it be used
without a class specific mapping file?

Let me know if I can provide any more information.

Thanks,
Mohnish


Joachim Grüneis wrote:

>
> Hello,
> I try to help you with some hints... but to be more precise
> I have not enough information
>
> It seams that you use the static methods of marshaller and unmarshaller -
> this often leads to problems as no configuration step takes place which
> e.g.
> would load the mapping information...
>
> so please instantiate an XMLContext, introduce the classes to map by using
> addClass or loadMapping, create marshaller and unmarshaller  instance and
> work with this instance - that might already solve your problem
>
> on the other
> hand you might have a problem caused by class loading mechanisms of felix
> (OSGi)
> marshaling takes existing Java
> objects instances and serializes them into XML - no problem there, all
> Java classes are known and can easily be
> marshaled to XML without any mapping information...
> the other way round is more complicated
> Caster has to find a corresponding class for each element found in the XML
> and needs to be able to
> instantiate this class - this is where two problems might occur:
> 1) no matching class can be found, mapping information is not
> available cause static methods are used so nothing is unmarshalled
> 2) no matching class can be found because Castor is not allowed to
> access these classes because they are bound to a different class
> loader
>
> These are just some ideas of what might have happend...
>
> to really help it is required to know more about your implementation:
> Is an XSD definition existing?
> Has the Java code been generated using code generator?
> Have you included the .cdr files into the jar?
> Do you use a mapping file?
> How does the marshaling/unmarshaling code look like?
>
> Hth Joachim
>
> 2009/6/24 mohn3310 <mohn3310@...>
>
>>
>> Hello,
>>
>> I'm using castor-xml in introspection mode to write out simple POJOs to
>> files (one POJO per file). I've written unit tests and verified that this
>> works. I've also inspected the files and made sure they have appropriate
>> xml.
>>
>> I then packaged this up into an osgi bundle and deployed it to a
>> container
>> (felix). For some reason when I run it, it ends up creating the file but
>> it
>> is empty... i.e. no xml in the file. Yet another strange thing is that I
>> use
>> Unmarshaller.unmarshall() to convert the xml files back to their
>> associated
>> POJOs. As a test I generated the xml by hand and it was able to load it.
>> So
>> Marshaller.marshall() doesn't work, but Unmarshaller.unmarshall() does!
>>
>> Any idea why it is behaving this way? Same code... works great
>> "normally",
>> but doesn't work inside an osgi container.
>>
>> Thanks,
>> Mohnish
>> --
>> View this message in context:
>> http://www.nabble.com/castor-xml-writing-empty-file-tp24175804p24175804.html
>> Sent from the Castor - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
>
>

--
View this message in context: http://www.nabble.com/castor-xml-writing-empty-file-tp24175804p24176402.html
Sent from the Castor - User mailing list archive at Nabble.com.


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

    http://xircles.codehaus.org/manage_email



Re: castor-xml writing empty file

by Werner Guttmann :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

for what it's worth: I have seen that Spring does offer a pre-built OSG
bundle for their TC server, and I gave not heard of any complaints that
things do not work.

Regards
Werner

mohn3310 wrote:

> Hello,
>
> I'm using castor-xml in introspection mode to write out simple POJOs to
> files (one POJO per file). I've written unit tests and verified that this
> works. I've also inspected the files and made sure they have appropriate
> xml.
>
> I then packaged this up into an osgi bundle and deployed it to a container
> (felix). For some reason when I run it, it ends up creating the file but it
> is empty... i.e. no xml in the file. Yet another strange thing is that I use
> Unmarshaller.unmarshall() to convert the xml files back to their associated
> POJOs. As a test I generated the xml by hand and it was able to load it. So
> Marshaller.marshall() doesn't work, but Unmarshaller.unmarshall() does!
>
> Any idea why it is behaving this way? Same code... works great "normally",
> but doesn't work inside an osgi container.
>
> Thanks,
> Mohnish

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

    http://xircles.codehaus.org/manage_email



Re: castor-xml writing empty file

by Werner Guttmann :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

Did this make any differences ?

Werner

mohn3310 wrote:

> I did have a dependency issue when i deployed it to the osgi container.
> castor-xml uses com.sun.org.apache.xml.internal.serialize in jdk5+, which is
> not exported by the osgi system bundle (it is not part of the standard java
> library but rather an implementation detail). To resolve this, I created a
> fragment bundle and exported the package.
>
> Thought to mention this in case it has any bearing on the problem.
>
> Thanks,
> Mohnish
>
>
> mohn3310 wrote:
>> Hello,
>>
>> I'm using castor-xml in introspection mode to write out simple POJOs to
>> files (one POJO per file). I've written unit tests and verified that this
>> works. I've also inspected the files and made sure they have appropriate
>> xml.
>>
>> I then packaged this up into an osgi bundle and deployed it to a container
>> (felix). For some reason when I run it, it ends up creating the file but
>> it is empty... i.e. no xml in the file. Yet another strange thing is that
>> I use Unmarshaller.unmarshall() to convert the xml files back to their
>> associated POJOs. As a test I generated the xml by hand and it was able to
>> load it. So Marshaller.marshall() doesn't work, but
>> Unmarshaller.unmarshall() does!
>>
>> Any idea why it is behaving this way? Same code... works great "normally",
>> but doesn't work inside an osgi container.
>>
>> Thanks,
>> Mohnish
>>
>

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

    http://xircles.codehaus.org/manage_email



Re: castor-xml writing empty file

by Werner Guttmann :: Rate this Message:

| View Threaded | Show Only this Message

Hi Joachim,

Joachim Grüneis wrote:
> Hello,
> I try to help you with some hints... but to be more precise
> I have not enough information
>
> It seams that you use the static methods of marshaller and unmarshaller -
But that's exactly what he user is looking for. All he wants to use is
introspection mode, soo usage of the static methods is just fine.

> this often leads to problems as no configuration step takes place which e.g.
> would load the mapping information...
>
> so please instantiate an XMLContext, introduce the classes to map by using
> addClass or loadMapping, create marshaller and unmarshaller  instance and
> work with this instance - that might already solve your problem
Well, it might be still owrth it to try this, even though there's no
mapping information to be loaded.

> on the other
> hand you might have a problem caused by class loading mechanisms of felix (OSGi)
> marshaling takes existing Java
> objects instances and serializes them into XML - no problem there, all
> Java classes are known and can easily be
> marshaled to XML without any mapping information...
> the other way round is more complicated
> Caster has to find a corresponding class for each element found in the XML
> and needs to be able to
> instantiate this class - this is where two problems might occur:
> 1) no matching class can be found, mapping information is not
> available cause static methods are used so nothing is unmarshalled
> 2) no matching class can be found because Castor is not allowed to
> access these classes because they are bound to a different class
> loader
>
> These are just some ideas of what might have happend...
>
> to really help it is required to know more about your implementation:
> Is an XSD definition existing?
No, I guess.
> Has the Java code been generated using code generator?
No, I guess.
> Have you included the .cdr files into the jar?
Well, no classes have been generated.

> Do you use a mapping file?
No, as introspection mode is used.

> How does the marshaling/unmarshaling code look like?

> Hth Joachim
>
> 2009/6/24 mohn3310 <mohn3310@...>
>
>> Hello,
>>
>> I'm using castor-xml in introspection mode to write out simple POJOs to
>> files (one POJO per file). I've written unit tests and verified that this
>> works. I've also inspected the files and made sure they have appropriate
>> xml.
>>
>> I then packaged this up into an osgi bundle and deployed it to a container
>> (felix). For some reason when I run it, it ends up creating the file but it
>> is empty... i.e. no xml in the file. Yet another strange thing is that I
>> use
>> Unmarshaller.unmarshall() to convert the xml files back to their associated
>> POJOs. As a test I generated the xml by hand and it was able to load it. So
>> Marshaller.marshall() doesn't work, but Unmarshaller.unmarshall() does!
>>
>> Any idea why it is behaving this way? Same code... works great "normally",
>> but doesn't work inside an osgi container.
>>
>> Thanks,
>> Mohnish
>> --
>> View this message in context:
>> http://www.nabble.com/castor-xml-writing-empty-file-tp24175804p24175804.html
>> Sent from the Castor - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> 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



Re: castor-xml writing empty file

by mohn3310 :: Rate this Message:

| View Threaded | Show Only this Message

Hi guys,

It looks like this was an osgi specific issue. I had two bundles; one of which was using castor to persist objects handed to it by the other. It turns out the bundle using castor did not include an import of the package the object it was handed resided in. Adding that seemed to do the trick.

I'm still trying to figure this out exactly. Why were there no errors when the import was missing. It just failed silently.

Thanks for your help.

Mohnish

Werner Guttmann wrote:
Hi Joachim,

Joachim Grüneis wrote:
> Hello,
> I try to help you with some hints... but to be more precise
> I have not enough information
>
> It seams that you use the static methods of marshaller and unmarshaller -
But that's exactly what he user is looking for. All he wants to use is
introspection mode, soo usage of the static methods is just fine.

> this often leads to problems as no configuration step takes place which e.g.
> would load the mapping information...
>
> so please instantiate an XMLContext, introduce the classes to map by using
> addClass or loadMapping, create marshaller and unmarshaller  instance and
> work with this instance - that might already solve your problem
Well, it might be still owrth it to try this, even though there's no
mapping information to be loaded.

> on the other
> hand you might have a problem caused by class loading mechanisms of felix (OSGi)
> marshaling takes existing Java
> objects instances and serializes them into XML - no problem there, all
> Java classes are known and can easily be
> marshaled to XML without any mapping information...
> the other way round is more complicated
> Caster has to find a corresponding class for each element found in the XML
> and needs to be able to
> instantiate this class - this is where two problems might occur:
> 1) no matching class can be found, mapping information is not
> available cause static methods are used so nothing is unmarshalled
> 2) no matching class can be found because Castor is not allowed to
> access these classes because they are bound to a different class
> loader
>
> These are just some ideas of what might have happend...
>
> to really help it is required to know more about your implementation:
> Is an XSD definition existing?
No, I guess.
> Has the Java code been generated using code generator?
No, I guess.
> Have you included the .cdr files into the jar?
Well, no classes have been generated.

> Do you use a mapping file?
No, as introspection mode is used.

> How does the marshaling/unmarshaling code look like?

> Hth Joachim
>
> 2009/6/24 mohn3310 <mohn3310@gmail.com>
>
>> Hello,
>>
>> I'm using castor-xml in introspection mode to write out simple POJOs to
>> files (one POJO per file). I've written unit tests and verified that this
>> works. I've also inspected the files and made sure they have appropriate
>> xml.
>>
>> I then packaged this up into an osgi bundle and deployed it to a container
>> (felix). For some reason when I run it, it ends up creating the file but it
>> is empty... i.e. no xml in the file. Yet another strange thing is that I
>> use
>> Unmarshaller.unmarshall() to convert the xml files back to their associated
>> POJOs. As a test I generated the xml by hand and it was able to load it. So
>> Marshaller.marshall() doesn't work, but Unmarshaller.unmarshall() does!
>>
>> Any idea why it is behaving this way? Same code... works great "normally",
>> but doesn't work inside an osgi container.
>>
>> Thanks,
>> Mohnish
>> --
>> View this message in context:
>> http://www.nabble.com/castor-xml-writing-empty-file-tp24175804p24175804.html
>> Sent from the Castor - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> 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


Re: castor-xml writing empty file

by Werner Guttmann :: Rate this Message:

| View Threaded | Show Only this Message

Hi Mohnish,

That's what I thought/hoped it would be. Thanks for letting us know.

Regards
Werner

mohn3310 wrote:

> Hi guys,
>
> It looks like this was an osgi specific issue. I had two bundles; one of
> which was using castor to persist objects handed to it by the other. It
> turns out the bundle using castor did not include an import of the package
> the object it was handed resided in. Adding that seemed to do the trick.
>
> I'm still trying to figure this out exactly. Why were there no errors when
> the import was missing. It just failed silently.
>
> Thanks for your help.
>
> Mohnish
>
>
> Werner Guttmann wrote:
>> Hi Joachim,
>>
>> Joachim Grüneis wrote:
>>> Hello,
>>> I try to help you with some hints... but to be more precise
>>> I have not enough information
>>>
>>> It seams that you use the static methods of marshaller and unmarshaller -
>> But that's exactly what he user is looking for. All he wants to use is
>> introspection mode, soo usage of the static methods is just fine.
>>
>>> this often leads to problems as no configuration step takes place which
>>> e.g.
>>> would load the mapping information...
>>>
>>> so please instantiate an XMLContext, introduce the classes to map by
>>> using
>>> addClass or loadMapping, create marshaller and unmarshaller  instance and
>>> work with this instance - that might already solve your problem
>> Well, it might be still owrth it to try this, even though there's no
>> mapping information to be loaded.
>>
>>> on the other
>>> hand you might have a problem caused by class loading mechanisms of felix
>>> (OSGi)
>>> marshaling takes existing Java
>>> objects instances and serializes them into XML - no problem there, all
>>> Java classes are known and can easily be
>>> marshaled to XML without any mapping information...
>>> the other way round is more complicated
>>> Caster has to find a corresponding class for each element found in the
>>> XML
>>> and needs to be able to
>>> instantiate this class - this is where two problems might occur:
>>> 1) no matching class can be found, mapping information is not
>>> available cause static methods are used so nothing is unmarshalled
>>> 2) no matching class can be found because Castor is not allowed to
>>> access these classes because they are bound to a different class
>>> loader
>>>
>>> These are just some ideas of what might have happend...
>>>
>>> to really help it is required to know more about your implementation:
>>> Is an XSD definition existing?
>> No, I guess.
>>> Has the Java code been generated using code generator?
>> No, I guess.
>>> Have you included the .cdr files into the jar?
>> Well, no classes have been generated.
>>
>>> Do you use a mapping file?
>> No, as introspection mode is used.
>>
>>> How does the marshaling/unmarshaling code look like?
>>> Hth Joachim
>>>
>>> 2009/6/24 mohn3310 <mohn3310@...>
>>>
>>>> Hello,
>>>>
>>>> I'm using castor-xml in introspection mode to write out simple POJOs to
>>>> files (one POJO per file). I've written unit tests and verified that
>>>> this
>>>> works. I've also inspected the files and made sure they have appropriate
>>>> xml.
>>>>
>>>> I then packaged this up into an osgi bundle and deployed it to a
>>>> container
>>>> (felix). For some reason when I run it, it ends up creating the file but
>>>> it
>>>> is empty... i.e. no xml in the file. Yet another strange thing is that I
>>>> use
>>>> Unmarshaller.unmarshall() to convert the xml files back to their
>>>> associated
>>>> POJOs. As a test I generated the xml by hand and it was able to load it.
>>>> So
>>>> Marshaller.marshall() doesn't work, but Unmarshaller.unmarshall() does!
>>>>
>>>> Any idea why it is behaving this way? Same code... works great
>>>> "normally",
>>>> but doesn't work inside an osgi container.
>>>>
>>>> Thanks,
>>>> Mohnish
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/castor-xml-writing-empty-file-tp24175804p24175804.html
>>>> Sent from the Castor - User mailing list archive at Nabble.com.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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



Re: castor-xml writing empty file

by mohn3310 :: Rate this Message:

| View Threaded | Show Only this Message

Hello again,

I wanted to just follow up on this to further my understanding. This might end up being an osgi specific question, but I wasn't able to find an appropriate forum to post this to. Please feel free to point me to the right one.

The bundle using castor provides a generic service... hand it an object and it will convert it to xml and marshall it. To make it work successfully, I ended up having to add the package of the object to this bundle's imports list. But this isn't viable... i.e. for every potential client of this bundle to keep adding to the imports list. This bundle shouldn't really know anything about its clients.

Why does it behave in such a way? Is this a limitation of the osgi imports/exports model or is castor doing something which requires the imports?

Thanks,
Mohnish


Werner Guttmann wrote:
Hi Mohnish,

That's what I thought/hoped it would be. Thanks for letting us know.

Regards
Werner

mohn3310 wrote:
> Hi guys,
>
> It looks like this was an osgi specific issue. I had two bundles; one of
> which was using castor to persist objects handed to it by the other. It
> turns out the bundle using castor did not include an import of the package
> the object it was handed resided in. Adding that seemed to do the trick.
>
> I'm still trying to figure this out exactly. Why were there no errors when
> the import was missing. It just failed silently.
>
> Thanks for your help.
>
> Mohnish
>
>
> Werner Guttmann wrote:
>> Hi Joachim,
>>
>> Joachim Grüneis wrote:
>>> Hello,
>>> I try to help you with some hints... but to be more precise
>>> I have not enough information
>>>
>>> It seams that you use the static methods of marshaller and unmarshaller -
>> But that's exactly what he user is looking for. All he wants to use is
>> introspection mode, soo usage of the static methods is just fine.
>>
>>> this often leads to problems as no configuration step takes place which
>>> e.g.
>>> would load the mapping information...
>>>
>>> so please instantiate an XMLContext, introduce the classes to map by
>>> using
>>> addClass or loadMapping, create marshaller and unmarshaller  instance and
>>> work with this instance - that might already solve your problem
>> Well, it might be still owrth it to try this, even though there's no
>> mapping information to be loaded.
>>
>>> on the other
>>> hand you might have a problem caused by class loading mechanisms of felix
>>> (OSGi)
>>> marshaling takes existing Java
>>> objects instances and serializes them into XML - no problem there, all
>>> Java classes are known and can easily be
>>> marshaled to XML without any mapping information...
>>> the other way round is more complicated
>>> Caster has to find a corresponding class for each element found in the
>>> XML
>>> and needs to be able to
>>> instantiate this class - this is where two problems might occur:
>>> 1) no matching class can be found, mapping information is not
>>> available cause static methods are used so nothing is unmarshalled
>>> 2) no matching class can be found because Castor is not allowed to
>>> access these classes because they are bound to a different class
>>> loader
>>>
>>> These are just some ideas of what might have happend...
>>>
>>> to really help it is required to know more about your implementation:
>>> Is an XSD definition existing?
>> No, I guess.
>>> Has the Java code been generated using code generator?
>> No, I guess.
>>> Have you included the .cdr files into the jar?
>> Well, no classes have been generated.
>>
>>> Do you use a mapping file?
>> No, as introspection mode is used.
>>
>>> How does the marshaling/unmarshaling code look like?
>>> Hth Joachim
>>>
>>> 2009/6/24 mohn3310 <mohn3310@gmail.com>
>>>
>>>> Hello,
>>>>
>>>> I'm using castor-xml in introspection mode to write out simple POJOs to
>>>> files (one POJO per file). I've written unit tests and verified that
>>>> this
>>>> works. I've also inspected the files and made sure they have appropriate
>>>> xml.
>>>>
>>>> I then packaged this up into an osgi bundle and deployed it to a
>>>> container
>>>> (felix). For some reason when I run it, it ends up creating the file but
>>>> it
>>>> is empty... i.e. no xml in the file. Yet another strange thing is that I
>>>> use
>>>> Unmarshaller.unmarshall() to convert the xml files back to their
>>>> associated
>>>> POJOs. As a test I generated the xml by hand and it was able to load it.
>>>> So
>>>> Marshaller.marshall() doesn't work, but Unmarshaller.unmarshall() does!
>>>>
>>>> Any idea why it is behaving this way? Same code... works great
>>>> "normally",
>>>> but doesn't work inside an osgi container.
>>>>
>>>> Thanks,
>>>> Mohnish
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/castor-xml-writing-empty-file-tp24175804p24175804.html
>>>> Sent from the Castor - User mailing list archive at Nabble.com.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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