Hello Werner,

Thank you for support. Not sure if it is correct to state, but it seems to me that Castor takes element name and it's namespace to determine which descriptor to use for conversion from XML. What I need it is to also take into consideration which namespace element defines and I'm not sure if it's possible. Whatever combination of namespace related mappings I've tried it didn't work. It only worked once I changed XML and appended elements with namespace, so from example, when I replaced

<table xmlns:ns1="table1"> with <table1:table xmlns:ns1="table1">

I didn't like that preprocessing was needed, but didn't find any other solution.

Mapping like this:

   <class name="foo.bar.Database">
       <map-to xml="DATABASE"/>
<field name="fooTables" type="foo.bar.FooTable" collection="arraylist"/> <field name="barTables" type="foo.bar.BarTable" collection="arraylist"/>
   </class>
   <class name="foo.bar.FooTable">
       <map-to xml="TABLE" ns-uri="FOO.COM"/>
       <field name="dsc" type="foo.bar.TableDescription" />
       <field name="occurrences" type="foo.bar.Foo" collection="arraylist">
           <bind-xml name="OCC" node="element"/>
       </field>
   </class>
   <class name="foo.bar.BarTable">
       <map-to xml="TABLE" ns-uri="BAR.COM"/>
       <field name="dsc" type="foo.bar.TableDescription" />
       <field name="occurrences" type="foo.bar.Bar" collection="arraylist">
           <bind-xml name="OCC" node="element"/>
       </field>
   </class>
   <class name="foo.bar.Foo">
       <map-to xml="OCC"/>
       <field name="foo1" type="string">
           <bind-xml name="FOO:FOO1" node="element" xmlns:FOO="FOO.COM"/>
       </field>
       <field name="foo2" type="string">
           <bind-xml name="FOO:FOO2" node="element" xmlns:FOO="FOO.COM"/>
       </field>
   </class>
   <class name="foo.bar.Bar">
       <map-to xml="OCC"/>
       <field name="bar1" type="string">
           <bind-xml name="BAR:BAR1" node="element" xmlns:BAR="BAR.COM"/>
       </field>
       <field name="bar2" type="string">
           <bind-xml name="BAR:BAR2" node="element" xmlns:BAR="BAR.COM"/>
       </field>
       <field name="bar3" type="string">
           <bind-xml name="BAR:BAR3" node="element" xmlns:BAR="BAR.COM"/>
       </field>
   </class>

for the XML like this:

<DATABASE>
   <TABLE xmlns:FOO="FOO.COM">
       <DSC .../>
       <OCC>
           <FOO:FOO1>...</FOO:FOO1>
           <FOO:FOO2>...</FOO:FOO2>
       </OCC>
       <OCC>
           <FOO:FOO1>...</FOO:FOO1>
           <FOO:FOO2>...</FOO:FOO2>
       </OCC>
   </TABLE>
   <TABLE xmlns:BAR="BAR.COM">
       <DSC .../>
       <OCC>
           <BAR:BAR1>...</BAR:BAR1>
           <BAR:BAR2>...</BAR:BAR2>
           <BAR:BAR3>...</BAR:BAR3>
       </OCC>
       <OCC>
           <BAR:BAR1>...</BAR:BAR1>
           <BAR:BAR2>...</BAR:BAR2>
           <BAR:BAR3>...</BAR:BAR3>
       </OCC>
       <OCC>
           <BAR:BAR1>...</BAR:BAR1>
           <BAR:BAR2>...</BAR:BAR2>
           <BAR:BAR3>...</BAR:BAR3>
       </OCC>
   </TABLE>
   <TABLE xmlns:FOO="FOO.COM">
       <DSC .../>
       <OCC>
           <FOO:FOO1>...</FOO:FOO1>
           <FOO:FOO2>...</FOO:FOO2>
       </OCC>
       <OCC>
           <FOO:FOO1>...</FOO:FOO1>
           <FOO:FOO2>...</FOO:FOO2>
       </OCC>
       <OCC>
           <FOO:FOO1>...</FOO:FOO1>
           <FOO:FOO2>...</FOO:FOO2>
       </OCC>
   </TABLE>
   <TABLE xmlns:BAR="BAR.COM">
       <DSC .../>
       <OCC>
           <BAR:BAR1>...</BAR:BAR1>
           <BAR:BAR2>...</BAR:BAR2>
           <BAR:BAR3>...</BAR:BAR3>
       </OCC>
       <OCC>
           <BAR:BAR1>...</BAR:BAR1>
           <BAR:BAR2>...</BAR:BAR2>
           <BAR:BAR3>...</BAR:BAR3>
       </OCC>
   </TABLE>
</DATABASE>

didn't work. In initial optimistic version that would suit me most I wanted to have a single collection in Database class, and in initial mapping file I've defined it's type to be arraylist of Table class which is a generic class extended by FooTable (extends Table<Foo>) and BarTable (extends Table<Bar>).

Regards,
Stevo.

Werner Guttmann wrote:
Stevo,

Stevo Slavić wrote:
Hello all,

Is it possible to define castor mapping so that castor, when
unmarshalling XML, takes into account element namespace? E.g. if there
are two elements both with same element name but belonging to different
namespace a different OXM mapping should be used; similarly for all
nested elements. Example XML snippet follows:

<database>
   <table xmlns:ns1="table1">
      <description/>
      <row />
      <row />
   </table>
   <table xmlns:ns1="table2">
      <description/>
      <row />
      <row />
   </table>
</database>

I can see what you are trying to do, but Castor - by the means of a
mapping file - allows you to define one mapping per Java class only.

Having said that, this does not prevent you to define more than one Java
class that are mapped against the same XML artefacts.

Database class has collection of Table<?> classes, while table element
with table1 namespace (and all it's nested elements) should be mapped in
one way, e.g to a Table1 class (extends Table<Row1>) while table element
with table2 namespace should be mapped to Table2 class (extends
Table<Row2>).
If you happen to have an extension hierarchy, you should be able to get
this working, though.

I've thought that if I map tables property of Database class to Table
class binding it to table XML element without mentioning namespace, and
then define mapping for each Table specialization binding each of them
to table XML element and their specific ns-prefix and ns-uri, it would
work, but it doesn't.
Can you show me the relevant mapping fragments ?

Regards
Werner

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

    http://xircles.codehaus.org/manage_email




--
Met vriendelijke groet / Kind regards,
Stevo Slavić
Senior Software Developer
Levi9 Global Sourcing
------------------------------------------------------------------------
.  Jan van Goyenkade 8, 1075 HP Amsterdam, The Netherlands
(    (+31) (0) 20 6701 947
È    (+381) (0) 63 7 258 458
*    [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
^    Skype: sslavic
ü    http://www.levi9.com/

Chamber of commerce Levi9 Global Sourcing BV: 34221951
Chamber of commerce Levi9 Global Sourcing Benelux BV: 34224746
------------------------------------------------------------------------
This e-mail may contain confidential or privileged information. If you are not (one of) the intended recipient(s), please notify the sender immediately by reply e-mail and delete this message and any attachments permanently without retaining a copy. Any review, disclosure, copying, distribution or taking any action in reliance on the contents of this e-mail by persons or entities other than the intended recipient(s) is strictly prohibited and may be unlawful.

The services of Levi9 are exclusively subject to its general terms and conditions. These general terms and conditions can be found on http://www.levi9.com/ and a copy will be promptly submitted to you on your request and free of charge.

Reply via email to