|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Question about inheritance...Hello,
Does anyone have a sample of using xstream in inherited classes using
converters? Essentially I have an object that's inherited through about
5 other classes, I'd like to put the correct converters in the correct
class, so the end class may only have one, even though there may be 10
total converters.
Sample:
Class A {
String foobar;
public Object clone() {
// use xstream converter on variable foobar
}
}
Class B extends A {
String helloworld;
public Object clone() {
// use xstream converter on variable helloworld
// but also call a super.clone() or something so the converter
// on foobar is also called
}
}
|
|
|
Re: Question about inheritance...Hi Ben,
Ben Douglas wrote: > Hello, > > Does anyone have a sample of using xstream in inherited classes using > converters? Essentially I have an object that's inherited through about > 5 other classes, I'd like to put the correct converters in the correct > class, so the end class may only have one, even though there may be 10 > total converters. > > Sample: > > Class A { > String foobar; > > public Object clone() { > // use xstream converter on variable foobar > } > > } > > Class B extends A { > String helloworld; > > public Object clone() { > // use xstream converter on variable helloworld > // but also call a super.clone() or something so the converter > // on foobar is also called > } > > } If you use XStream for cloning, why do you create any custom converter at all? - Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Re: Question about inheritance...Hi Jörg,
I have some singleton objects that the objects I'm cloning point to. In order to save time / risk duplicate singletons, I just write a string to the xml instead of the entire object (some are rather large). So class A may have singleton Singleton_1 and class B may have Singleton_2. I can put the converter for both in B, but thought it would make sense to put singleton_1 in A, and singleton_2 in b. I just used Strings as a more basic example. Thanks, Ben On 10/29/2009 11:00 AM, Jörg Schaible wrote: > Hi Ben, > > Ben Douglas wrote: > > >> Hello, >> >> Does anyone have a sample of using xstream in inherited classes using >> converters? Essentially I have an object that's inherited through about >> 5 other classes, I'd like to put the correct converters in the correct >> class, so the end class may only have one, even though there may be 10 >> total converters. >> >> Sample: >> >> Class A { >> String foobar; >> >> public Object clone() { >> // use xstream converter on variable foobar >> } >> >> } >> >> Class B extends A { >> String helloworld; >> >> public Object clone() { >> // use xstream converter on variable helloworld >> // but also call a super.clone() or something so the converter >> // on foobar is also called >> } >> >> } >> > If you use XStream for cloning, why do you create any custom converter at > all? > > - Jörg > > > --------------------------------------------------------------------- > 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: Re: Question about inheritance...Hi Ben,
Ben Douglas wrote: > Hi Jörg, > > I have some singleton objects that the objects I'm cloning point to. In > order to save time / risk duplicate singletons, I just write a string to > the xml instead of the entire object (some are rather large). So class > A may have singleton Singleton_1 and class B may have Singleton_2. I > can put the converter for both in B, but thought it would make sense to > put singleton_1 in A, and singleton_2 in b. I just used Strings as a > more basic example. Why don't you simply write a converter for the singleton's type (even if the individual instances are different types of a class hierarchy)? If you can represent it by a String that can be used to refer the proper singleton at deserialization time, it's all you need (and the proper condition in the canConvert method). - Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Re: Re: Question about inheritance...Yes -- I actually have converters for the singletons I need. The
question is if I have class A that uses singleton 1, and class B that uses singleton 2, and class A inherits class B, I'd like class B to take care of the singleton 2 converter (since the writer of A may not even use singleton 2 that class B uses). So really it'd be great to be able to write a "clone" for A and B -- each of which takes care of any converters they need. So A would only do a converter for '1', but inherit the use of the converter for singleton '2'. Let me know if a better example would work. Thanks, Ben On 11/03/2009 06:49 PM, Jörg Schaible wrote: > Hi Ben, > > Ben Douglas wrote: > > >> Hi Jörg, >> >> I have some singleton objects that the objects I'm cloning point to. In >> order to save time / risk duplicate singletons, I just write a string to >> the xml instead of the entire object (some are rather large). So class >> A may have singleton Singleton_1 and class B may have Singleton_2. I >> can put the converter for both in B, but thought it would make sense to >> put singleton_1 in A, and singleton_2 in b. I just used Strings as a >> more basic example. >> > Why don't you simply write a converter for the singleton's type (even if the > individual instances are different types of a class hierarchy)? If you can > represent it by a String that can be used to refer the proper singleton at > deserialization time, it's all you need (and the proper condition in the > canConvert method). > > > - Jörg > > > --------------------------------------------------------------------- > 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: Re: Re: Question about inheritance...Hi Ben,
Ben Douglas wrote: > Yes -- I actually have converters for the singletons I need. The > question is if I have class A that uses singleton 1, and class B that > uses singleton 2, and class A inherits class B, I'd like class B to take > care of the singleton 2 converter (since the writer of A may not even > use singleton 2 that class B uses). So really it'd be great to be able > to write a "clone" for A and B -- each of which takes care of any > converters they need. So A would only do a converter for '1', but > inherit the use of the converter for singleton '2'. Even with the example in your first posting I am still not understanding what you really try to do, sorry. > Let me know if a > better example would work. Definitely. - Jörg --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |