7591
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2002 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
6379
|
13 |
"{ Package: 'stx:libbasic' }"
|
|
14 |
|
|
15 |
Object subclass:#AbstractObjectCoder
|
6719
|
16 |
instanceVariableNames:'aspect'
|
6379
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'System-Storage'
|
|
20 |
!
|
|
21 |
|
|
22 |
!AbstractObjectCoder class methodsFor:'documentation'!
|
|
23 |
|
7591
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 2002 by eXept Software AG
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
|
37 |
|
6379
|
38 |
documentation
|
|
39 |
"
|
|
40 |
This class is defines #encodeXXX:with: messages for various kinds of objects.
|
|
41 |
Any of these messsages is mapped to #encodeObject:with:.
|
|
42 |
|
|
43 |
When a class redefines #encodeOn:with:, an method has to be defined here, too.
|
|
44 |
|
|
45 |
Subclasses have to define at least #encodeObject:with:
|
|
46 |
|
|
47 |
[author:]
|
|
48 |
Stefan Vogel (stefan@zwerg)
|
|
49 |
|
|
50 |
[see also:]
|
|
51 |
Object>>encodeOn:with:
|
|
52 |
"
|
|
53 |
! !
|
|
54 |
|
6719
|
55 |
!AbstractObjectCoder methodsFor:'accessing'!
|
|
56 |
|
|
57 |
aspect
|
|
58 |
"return the value of the instance variable 'aspect' (automatically generated)"
|
|
59 |
|
|
60 |
^ aspect
|
|
61 |
!
|
|
62 |
|
|
63 |
aspect:something
|
|
64 |
"set the value of the instance variable 'aspect' (automatically generated)"
|
|
65 |
|
|
66 |
aspect := something.
|
|
67 |
! !
|
|
68 |
|
7265
|
69 |
!AbstractObjectCoder methodsFor:'encoding-smalltalk types'!
|
6379
|
70 |
|
|
71 |
encodeAbsoluteTime:anAbsoluteTime with:aParameter
|
|
72 |
"encode an absolute time value"
|
|
73 |
|
|
74 |
self encodeObject:anAbsoluteTime with:aParameter
|
|
75 |
|
|
76 |
|
|
77 |
!
|
|
78 |
|
6597
|
79 |
encodeBehavior:aSymbol with:aParameter
|
|
80 |
"encode a class"
|
|
81 |
|
|
82 |
self encodeObject:aSymbol with:aParameter
|
|
83 |
!
|
|
84 |
|
6379
|
85 |
encodeBitArray:aBitArray with:aParameter
|
|
86 |
"encode a BitArray"
|
|
87 |
|
6594
|
88 |
self encodeSequenceableCollection:aBitArray with:aParameter
|
6379
|
89 |
!
|
|
90 |
|
6750
|
91 |
encodeBlock:aBlock with:aParameter
|
|
92 |
"encoding of blocks is rather difficult and an error by default.
|
|
93 |
If your encoder supports this, redefine it there"
|
|
94 |
|
|
95 |
self error:'encoding of blocks is not supported'
|
|
96 |
!
|
|
97 |
|
6379
|
98 |
encodeBoolean:aBoolean with:aParameter
|
|
99 |
"encode a Boolean"
|
|
100 |
|
|
101 |
self encodeObject:aBoolean with:aParameter
|
|
102 |
|
|
103 |
|
|
104 |
!
|
|
105 |
|
|
106 |
encodeByteArray:aByteArray with:aParameter
|
|
107 |
"encode an absolute time value"
|
|
108 |
|
6594
|
109 |
self encodeSequenceableCollection:aByteArray with:aParameter
|
6379
|
110 |
!
|
|
111 |
|
|
112 |
encodeCharacter:aCharacter with:aParameter
|
|
113 |
"encode a Character"
|
|
114 |
|
|
115 |
self encodeObject:aCharacter with:aParameter
|
|
116 |
|
|
117 |
|
|
118 |
!
|
|
119 |
|
6594
|
120 |
encodeCollection:aCollection with:aParameter
|
|
121 |
"encode a Collection"
|
|
122 |
|
|
123 |
self encodeObject:aCollection with:aParameter
|
|
124 |
!
|
|
125 |
|
6379
|
126 |
encodeDictionary:aDictionary with:aParameter
|
|
127 |
"encode a Dictionary"
|
|
128 |
|
6594
|
129 |
self encodeCollection:aDictionary with:aParameter
|
6379
|
130 |
!
|
|
131 |
|
|
132 |
encodeFloat:aFloat with:aParameter
|
|
133 |
"encode a Float"
|
|
134 |
|
6485
|
135 |
self encodeNumber:aFloat with:aParameter
|
|
136 |
!
|
6379
|
137 |
|
6485
|
138 |
encodeFraction:aFraction with:aParameter
|
|
139 |
"encode a Fraction"
|
6379
|
140 |
|
6485
|
141 |
self encodeNumber:aFraction with:aParameter
|
6379
|
142 |
!
|
|
143 |
|
|
144 |
encodeInteger:anInteger with:aParameter
|
|
145 |
"encode an Integer"
|
|
146 |
|
6485
|
147 |
self encodeNumber:anInteger with:aParameter
|
6379
|
148 |
!
|
|
149 |
|
6747
|
150 |
encodeInterval:anInterval with:aParameter
|
|
151 |
"intervals are a special flavor of sequenceable collection (saving memory)
|
|
152 |
We treat it as SequenceableCollection by default.
|
|
153 |
Encoders that do a dense representation, redefine this to #encodeObject"
|
|
154 |
|
|
155 |
^ self encodeSequenceableCollection:anInterval with:aParameter
|
|
156 |
!
|
|
157 |
|
6379
|
158 |
encodeNilWith:aParameter
|
|
159 |
"encode a nil"
|
|
160 |
|
|
161 |
self encodeObject:nil with:aParameter
|
|
162 |
|
|
163 |
|
|
164 |
!
|
|
165 |
|
6485
|
166 |
encodeNumber:aNumber with:aParameter
|
|
167 |
"encode an Integer"
|
|
168 |
|
|
169 |
self encodeObject:aNumber with:aParameter
|
|
170 |
!
|
|
171 |
|
6379
|
172 |
encodeSequencableCollection:aCollection with:aParameter
|
6594
|
173 |
"encode a SequenceableCollection.
|
|
174 |
This is the wrong spelling but kept foe backward compatibility"
|
|
175 |
|
|
176 |
self encodeCollection:aCollection with:aParameter
|
|
177 |
!
|
6379
|
178 |
|
6594
|
179 |
encodeSequenceableCollection:aCollection with:aParameter
|
|
180 |
"encode a SequenceableCollection"
|
6379
|
181 |
|
6594
|
182 |
"send the historic (wrong) selector, for backward compatibility with old subclasses"
|
|
183 |
self encodeSequencableCollection:aCollection with:aParameter
|
6379
|
184 |
!
|
|
185 |
|
|
186 |
encodeSet:aCollection with:aParameter
|
|
187 |
"encode a Set"
|
|
188 |
|
6594
|
189 |
self encodeCollection:aCollection with:aParameter
|
6379
|
190 |
!
|
|
191 |
|
|
192 |
encodeString:aString with:aParameter
|
|
193 |
"encode a String"
|
|
194 |
|
|
195 |
self encodeObject:aString with:aParameter
|
|
196 |
|
|
197 |
|
|
198 |
!
|
|
199 |
|
|
200 |
encodeSymbol:aSymbol with:aParameter
|
|
201 |
"encode a Symbol"
|
|
202 |
|
|
203 |
self encodeObject:aSymbol with:aParameter
|
|
204 |
|
|
205 |
|
|
206 |
! !
|
|
207 |
|
6719
|
208 |
!AbstractObjectCoder methodsFor:'helpers'!
|
|
209 |
|
|
210 |
encodeAllInstanceVariablesOf:anObject
|
|
211 |
"recursively enumerate anObjects refs, encoding each of the child objects.
|
|
212 |
nil childs are not encoded"
|
|
213 |
|
|
214 |
|instVarNames theClass
|
|
215 |
sz "{ Class: SmallInteger }"|
|
|
216 |
|
|
217 |
theClass := anObject class.
|
|
218 |
sz := theClass instSize.
|
|
219 |
sz ~~ 0 ifTrue:[
|
|
220 |
instVarNames := theClass allInstVarNames.
|
|
221 |
1 to:sz do:[:i | |ref|
|
|
222 |
ref := anObject instVarAt:i.
|
|
223 |
ref notNil ifTrue:[
|
|
224 |
ref encodeOn:self with:(instVarNames at:i).
|
|
225 |
self nextObject.
|
|
226 |
].
|
|
227 |
].
|
|
228 |
].
|
|
229 |
|
|
230 |
theClass isVariable ifTrue:[
|
|
231 |
sz := anObject basicSize.
|
|
232 |
sz ~~ 0 ifTrue:[
|
|
233 |
1 to:sz do:[:i |
|
|
234 |
(anObject basicAt:i) encodeOn:self with:i.
|
|
235 |
self nextObject.
|
|
236 |
]
|
|
237 |
].
|
|
238 |
].
|
|
239 |
!
|
|
240 |
|
|
241 |
encodeChildrenOf:anObject
|
|
242 |
"encode all child objects of anObject.
|
|
243 |
If aspect is defined, perform aspect to fetch the child objects.
|
|
244 |
Otherwise encode all the instance variables"
|
|
245 |
|
|
246 |
|childObjectDescriptors|
|
|
247 |
|
|
248 |
aspect isNil ifTrue:[
|
|
249 |
"shortcut -- basic mechanism: encode instance variables by name"
|
|
250 |
self encodeAllInstanceVariablesOf:anObject.
|
|
251 |
^ self.
|
|
252 |
].
|
|
253 |
|
|
254 |
childObjectDescriptors := anObject encodingVectorFor:aspect.
|
|
255 |
childObjectDescriptors do:[:association|
|
|
256 |
association notNil ifTrue:[
|
|
257 |
association value encodeOn:self with:association key.
|
|
258 |
self nextObject.
|
|
259 |
].
|
|
260 |
].
|
|
261 |
|
|
262 |
"
|
|
263 |
XMLStandardCoder new aspect:#encodingVectorForInstanceVariables;
|
|
264 |
encodingOf:('blaKey' -> 'blaValue')
|
|
265 |
|
|
266 |
XMLStandardCoder new aspect:#encodingVectorForInstanceVariables;
|
|
267 |
encodingOf:('blaKey' -> nil)
|
|
268 |
|
|
269 |
XMLStandardCoder new aspect:#encodingVectorForNonNilInstanceVariables;
|
|
270 |
encodingOf:('blaKey' -> nil)
|
|
271 |
|
|
272 |
XMLStandardCoder new aspect:#blaFaselQuall;
|
|
273 |
encodingOf:('blaKey' -> nil)
|
|
274 |
"
|
|
275 |
! !
|
|
276 |
|
6379
|
277 |
!AbstractObjectCoder methodsFor:'subclass responsibility'!
|
|
278 |
|
|
279 |
encodeObject:anObject with:aParameter
|
|
280 |
"encode an object. Subclasses must implement this method"
|
|
281 |
|
|
282 |
self subclassResponsibility
|
|
283 |
|
|
284 |
|
6719
|
285 |
!
|
|
286 |
|
|
287 |
nextObject
|
|
288 |
"this is sent, when a new Object is going to be encoded.
|
|
289 |
Subclasses may redefine this e.g.to output a CR"
|
|
290 |
|
|
291 |
^ self
|
6379
|
292 |
! !
|
|
293 |
|
|
294 |
!AbstractObjectCoder class methodsFor:'documentation'!
|
|
295 |
|
|
296 |
version
|
7591
|
297 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/AbstractObjectCoder.st,v 1.9 2003-08-29 19:30:02 cg Exp $'
|
6379
|
298 |
! !
|