Hi Lukas,
----- Original Message -----
I am currently developing a new Smalltalk Wiki
implementation
(
http://scgwiki.iam.unibe.ch:8080/SCG/520) and I am planning to use
SIXX to store my large tree-structures to xml. It seems to me the
perfect solution, because it can handle circular references and it
dialect independent.
Great!
But how do I prevent SIXX from saving the binary data
again, without
hardcoding the other i-vars? How do I archive the loading of the binary
data?
I feel it is best to explain in code. So I attached the sample.
The sample is Squeak file-in format but you can read it by text editor.
Basically, in #sixxContentOn:indent:context:,
you can delegate the writing process to some of the children (inst-vars)
by using #sixxOn:name:indent:context:.
Resource>>sixxContentOn:indent:context:
| id newLevel fileStr |
"Write ID to XML instead of binary data"
newLevel := level + 1.
aStream cr.
id := self generateID.
id sixxOn: aStream name: 'resourceID' indent: newLevel context: dictionary.
"Write some other inst vars (optional)"
self name sixxOn: aStream name: 'name' indent: newLevel context:
dictionary.
"Dump actual data to file"
[fileStr := FileStream forceNewFileNamed: id.
fileStr nextPutAll: binaryData asArray printString. "just a sample - you
should use binary mode"]
ensure: [fileStr close.]
For the reading, you can override #sixxInstVarNamed:put:
Resource >>sixxInstVarNamed:put:
instVarName = 'resourceID' ifTrue: [ | fileStr |
[fileStr := FileStream readOnlyFileNamed: aValue.
self binaryData: (Array readFrom: fileStr contents) asByteArray]
ensure: [fileStr close.].
^self.
].
instVarName = 'name' ifTrue: [^self name: aValue].
There are other "hook" methods in SIXX for the more efficient
serialization/deserialization.
But I think the sample code fits your purpose.
I hope it helps. Please feel free to ask me, if you have some questions.
I'm looking forward to SmallWiki!
---
[:masashi | ^umezawa]