Subclasses if an inside element is different

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

Subclasses if an inside element is different

by gufux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have an issue with binding and class inheritance based on an internal element of XML schema. I have the following classes:

----------------------------------------------------------
public class Profile {
    protected UniqueId profileId;
}

public class Traveller extends Profile {
    protected TravellerName name;
    ....
}

public class Company extends Profile {
   protected CompanyName name;
   ....
}
------------------------------------------------------------

and XML messages like that:

1) <Profile>
      <UniqueId type="1" />
       <TravellerName>Davide</TravellerName>
   </Profile>
2) <Profile>
      <UniqueId type="1" />
       <CompanyName>IBM</ComapnyName>
   </Profile>

So I want to use only instances of Traveller and Company depending if in XML inside the <Profile> i have <TravellerName> or <CompanyName>.
I've tried with abstract classes and "extends" but there isn't a solution because when JibX have to bind the <Profile> it doesn't know the inside element and the correct
instance depend on that element.

I'have spent many time on this problem and so I would know if it's me that haven't found the right solution or in fact in Jibx simply I can't do that... anyone have any suggestions?

Thanks

Davide.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
jibx-users mailing list
jibx-users@...
https://lists.sourceforge.net/lists/listinfo/jibx-users

Re: Subclasses if an inside element is different

by Mahen Perera-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hi there,

 

I also faced a similar issue. I ended up writing a custom marshaller and unmarshaller since I couldn’t find an inbuilt solution in Jibx for this.

 

Mahen


From: jibx-users-bounces@... [mailto:jibx-users-bounces@...] On Behalf Of gufux
Sent: 25 June 2008 09:36
To: jibx-users@...
Subject: [jibx-users] Subclasses if an inside element is different

 

Hi,

I have an issue with binding and class inheritance based on an internal element of XML schema. I have the following classes:

----------------------------------------------------------

public class Profile {
    protected UniqueId profileId;
}

public class Traveller extends Profile {
    protected TravellerName name;
    ....
}

public class Company extends Profile {
   protected CompanyName name;
   ....
}
------------------------------------------------------------

and XML messages like that:

1) <Profile>
      <UniqueId type="1" />
       <TravellerName>Davide</TravellerName>
   </Profile>
2) <Profile>
      <UniqueId type="1" />
       <CompanyName>IBM</ComapnyName>
   </Profile>

So I want to use only instances of Traveller and Company depending if in XML inside the <Profile> i have <TravellerName> or <CompanyName>.
I've tried with abstract classes and "extends" but there isn't a solution because when JibX have to bind the <Profile> it doesn't know the inside element and the correct
instance depend on that element.

I'have spent many time on this problem and so I would know if it's me that haven't found the right solution or in fact in Jibx simply I can't do that... anyone have any suggestions?

Thanks

Davide.

 

The information contained in this email is strictly confidential and for the use of the addressee only, unless otherwise indicated. If you are not the intended recipient, please do not read, copy, use or disclose to others this message or any attachment. Please also notify the sender by replying to this email or by telephone (+44 (0)20 7896 0011) and then delete the email and any copies of it. Opinions, conclusions (etc.) that do not relate to the official business of this company shall be understood as neither given nor endorsed by it. IG Index plc is a company registered in England and Wales under number 01190902. VAT registration number 761 2978 07. Registered Office: Friars House, 157-168 Blackfriars Road, London SE1 8EZ. Authorised and regulated by the Financial Services Authority. FSA Register number 114059.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
jibx-users mailing list
jibx-users@...
https://lists.sourceforge.net/lists/listinfo/jibx-users

Re: Subclasses if an inside element is different

by Varghese C V :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

A suggestion -
Shouldn't your models reflect how the xml is laid out?
If you remodel the Profile class be an enclosing class and has a
reference to a ProfileType abstract class whose concrete instances are
Traveller & Company then you will find the jibx mappings very straight
forward to implement.

public class Profile{
    ...
    public ProfileType profileType;
    ...
}

public abstract class ProfileType{...}

public class Traveller extends ProfileType{...}

regards
Varghese C V

gufux wrote:

> Hi,
>
> I have an issue with binding and class inheritance based on an
> internal element of XML schema. I have the following classes:
>
> ----------------------------------------------------------
> public class Profile {
>     protected UniqueId profileId;
> }
>
> public class Traveller extends Profile {
>     protected TravellerName name;
>     ....
> }
>
> public class Company extends Profile {
>    protected CompanyName name;
>    ....
> }
> ------------------------------------------------------------
>
> and XML messages like that:
>
> 1) <Profile>
>       <UniqueId type="1" />
>        <TravellerName>Davide</TravellerName>
>    </Profile>
> 2) <Profile>
>       <UniqueId type="1" />
>        <CompanyName>IBM</ComapnyName>
>    </Profile>
>
> So I want to use only instances of Traveller and Company depending if
> in XML inside the <Profile> i have <TravellerName> or <CompanyName>.
> I've tried with abstract classes and "extends" but there isn't a
> solution because when JibX have to bind the <Profile> it doesn't know
> the inside element and the correct
> instance depend on that element.
>
> I'have spent many time on this problem and so I would know if it's me
> that haven't found the right solution or in fact in Jibx simply I
> can't do that... anyone have any suggestions?
>
> Thanks
>
> Davide.
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> jibx-users@...
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>  


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
jibx-users mailing list
jibx-users@...
https://lists.sourceforge.net/lists/listinfo/jibx-users
LightInTheBox - Buy quality products at wholesale price!