TypeConverters?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

TypeConverters?

Barry Carr-2
Hi,

A Bit of background might help first.

I'm using Steve Waring's YAXO package to stream object out as XML.
Getting the Data out is no problem. However, when I come to read the data
back in all the data elements are considered to be text and not type they
went out as. For most of the data this is OK 'cos it is text - but there
are one or two numbers ans the odd boolean. I was wondering if type
converters would help me. I was considering saving the class name of the
required type converter with the data and interpreting that when the data
comes back in.

So, is there a way to dynamically create or determine the TypeConverter
class one would need for an instance of an object that would be
considered a simple type in other languages (integers, booleans, floats
etc) with out having to resort to code like:

| tc |
(anObject isMemberOf: Boolean) ifTrue: [ tc := BoolToText new ].
(anObject isMemberOf: Integer) ifTrue: [ tc := IntegerToText new ].
...

I've had a scout round the image and nothing obvious leaps out. The
Object>>isXXXX methods don't feel right, either and would probably result
in a similar mess to the above.

My other question, I suppose, is: Are type converted a reasonable
approach for this problem or is there a better pattern or idiom that can
do the job more elegantly.

Thanks

Barry Carr
Ixian Software Components Ltd
Blairgowrie
Perthshire
Scotland


Reply | Threaded
Open this post in threaded view
|

Re: TypeConverters?

Bill Schwab-2
Barry,

Do you have control over the format of the output?  Obviously it will be
XML, but, can you add tags as you see fit?  If so, could you add the name of
the type converter class to be used to convert the data back to its useful
form?  It would also be nice if it could handle references to objects
already in the stream, etc., to become a working serializer.  Blair has at
times mentioned things that an XML based binary filer should do, so a look
through the archives might be helpful.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: TypeConverters?

Barry Carr-2
"Bill Schwab" <[hidden email]> wrote in
news:aeat27$5ihk5$[hidden email]:

Hi Bill,

> Do you have control over the format of the output?  Obviously it will
> be XML, but, can you add tags as you see fit?  If so, could you add
> the name of the type converter class to be used to convert the data
> back to its useful form?  

Yes I have. I've already used tags to tell me what that data accessors
are and whether or not this a complex nested instance that needs to
created and "streamed" in. I was considering using the class name of the
type converter as you mentioned - What I was looking for was an elegant
way of determining what typeconverted was needed. What would be ideal is
something along the lines of: tc := anObject typeConverter or tc :=
anObject class typeConverter rather than some sort of "evil type checking
case statement mutant"!

> It would also be nice if it could handle
> references to objects already in the stream, etc., to become a working
> serializer.  

I think I've already tried to do this. As I mentioned above I have tags
that tell me that need to go down another level. I must confess that I've
not got this completely beaten. I look out for collections and nested
objects but I've not tried it yet with anything that contains
Associations

Blair has at times mentioned things that an XML based
> binary filer should do, so a look through the archives might be
> helpful.

Thanks - Ill go and get a copy of Ian's goodies for D5 and have a mooch
about. Thnaks for the suggestions.

>
> Have a good one,
>
> Bill

Cheers

Barry


Reply | Threaded
Open this post in threaded view
|

Re: TypeConverters?

Ian Bartholomew-14
Barry,

Do you _have_ to use XML?. From the way you describe it you are just writing
and reading data to/from a Dolphin application so I would have thought that
the built in STB filer would be ideal for that - you can just read and write
objects without worrying about their makeup.

Ian


Reply | Threaded
Open this post in threaded view
|

Re: TypeConverters?

Barry Carr-2
"Ian Bartholomew" <[hidden email]> wrote in
news:jw8O8.7380$VP6.570925@stones:

Hi Ian,

Its because of the STB filer I decided to use XML! I made a change to a
class definition after I streamed some data out (I added a boolean field)
and the STB filer read in my data incorrectly. At this point I guessed that
the filer was intimately tied up with the class def and couldn't tolerate
changes. I thought that if I streamed the data out as XML changing the
class def wouldn't cause problems as only the fields that were described in
the XML would get updated when it came to reading the data back in -
leaving me free to change stuff to my hearts content.

Please don't tell me that the STB filer is much more flexible that I
thought and that I've made a huge mistake!

Cheers

Barry


Reply | Threaded
Open this post in threaded view
|

Re: TypeConverters?

Jeffrey Odell-2
Did you read the education centre notes on STB?  Versioning and conversion
is pretty flexible -

jlo

"Barry Carr arrakis.clara.net>" <barry@<nospam> wrote in message
news:Xns922D7C018938barryarrakisclaranet@158.152.254.72...
> "Ian Bartholomew" <[hidden email]> wrote in
> news:jw8O8.7380$VP6.570925@stones:
>
> Hi Ian,
>
> Its because of the STB filer I decided to use XML! I made a change to a
> class definition after I streamed some data out (I added a boolean field)
> and the STB filer read in my data incorrectly. At this point I guessed
that
> the filer was intimately tied up with the class def and couldn't tolerate
> changes. I thought that if I streamed the data out as XML changing the
> class def wouldn't cause problems as only the fields that were described
in
> the XML would get updated when it came to reading the data back in -
> leaving me free to change stuff to my hearts content.
>
> Please don't tell me that the STB filer is much more flexible that I
> thought and that I've made a huge mistake!
>
> Cheers
>
> Barry


Reply | Threaded
Open this post in threaded view
|

Re: TypeConverters?

Louis Sumberg-2
In reply to this post by Barry Carr-2
Barry,

> Please don't tell me that the STB filer is much more flexible that I
> thought and that I've made a huge mistake!

The STB filer has some features that you may want to capitalize on :)

I (shamelessly) think there's a pretty good writeup on using binary filing
(do a search on "binary") in
http://www.mindspring.com/~lsumberg/PersonalMoney, parts 3-6.

 From part 6, "The bottom line AND the big lesson on all of this is that if
you're using the binary filer, make sure you update the #stbVersion and
#stbConvertFrom: class-side methods whenever changes are made to the class
definition.  Also, make sure you use #stbSaveOn: to convert any sorted
collections back to ordered collections before filing them out."

-- Louis


Reply | Threaded
Open this post in threaded view
|

Re: TypeConverters?

Ian Bartholomew-14
In reply to this post by Barry Carr-2
Barry,

> Please don't tell me that the STB filer is much more flexible that I
> thought and that I've made a huge mistake!

OK

Regards
    Ian  ;-)


Reply | Threaded
Open this post in threaded view
|

Re: TypeConverters?

Andy Bower
In reply to this post by Barry Carr-2
Barry,

> Its because of the STB filer I decided to use XML! I made a change to a
> class definition after I streamed some data out (I added a boolean field)
> and the STB filer read in my data incorrectly. At this point I guessed
that
> the filer was intimately tied up with the class def and couldn't tolerate
> changes. I thought that if I streamed the data out as XML changing the
> class def wouldn't cause problems as only the fields that were described
in
> the XML would get updated when it came to reading the data back in -
> leaving me free to change stuff to my hearts content.
>
> Please don't tell me that the STB filer is much more flexible that I
> thought and that I've made a huge mistake!

You're right that the STB filer is intimately tied up with the class
definition but it really would be unacceptable if one wasn't able to read
old files. Remember the Dolphin ViewComposer saves view resources using STB
and, over the years, there have been many changes to the view classes yet we
are still able to read in the old files.

How, does it workt? You have to write a conversion method in any class that
is changed and might have been saved down to STB. The method is a class side
method called #stbConvertFrom: so do a browse definitions in the image to
see existing conversions that are in place. Things get a little complicated
if you need to support multiple old versions of classes but you'll see that
the cases that do this separate out the conversions into separate methods.
Take a look at:

http://www.object-arts.com/Lib/EducationCentre4/htm/binaryfilingobjects.htm

and, in particular:

http://www.object-arts.com/Lib/EducationCentre4/htm/convertingstbdataafterin
stancelayoutchanges.htm

Best Regards,

Andy Bower
Dolphin Support
http://www.object-arts.com
---
Are you trying too hard?
http://www.object-arts.com/Relax.htm
---


Reply | Threaded
Open this post in threaded view
|

Re: TypeConverters?

Barry Carr-2
"Andy Bower" <[hidden email]> wrote in
news:aecbq2$61e4l$[hidden email]:

Andy,

Thanks very much. I'll take a look at those links you provided.

Cheers

Barry


Reply | Threaded
Open this post in threaded view
|

Re: TypeConverters?

Bill Schwab-2
In reply to this post by Andy Bower
Barry,

To Andy's reply I'll add that

 http://www.object-arts.com/wiki/html/Dolphin/BinaryFiler.htm

shows how to use two streams to simplify (IMHO at least) the task.  It's a
generalization of an idea that appeared in one of the base system classes.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]