eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'XMLStandardCoder':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: XMLStandardCoder


Inheritance:

   Object
   |
   +--Visitor
      |
      +--AspectVisitor
         |
         +--ObjectCoder
            |
            +--XMLCoder
               |
               +--XMLStandardCoder

Package:
stx:goodies/xml/stx
Category:
XML-Presentation
Version:
rev: 1.21 date: 2021/01/20 15:03:42
user: cg
file: XMLStandardCoder.st directory: goodies/xml/stx
module: stx stc-classLibrary: stx

Description:


A standard representation, which mimics the binary storage
semantics (i.e. an object can be restored - even if self-referencing)

Standard types are mapped to different element names.
The className, the index or instVarName are stored as attributes.

The same structure is used for all same-typed instances,
and a DTD may be used to describe the output.



[instance variables:]

[class variables:]

copyright

COPYRIGHT (c) 1999 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

encoding / decoding
o  decode: aStringOrStream
redefined to make the protocol more horizontal

o  encodingOf: anObject aspect: aspect with: aParameter
return the encoding of anObject


Instance protocol:

visiting
o  visitBoolean: aBool with: nameOrIndex
xml encode a boolean

o  visitByteArray: bytes with: nameOrIndex
encode a byte array.
BASE64 coding is used

o  visitCharacter: aCharacter with: nameOrIndex
encode a character.
The characters codePoint value is used

o  visitCollection: aCollection with: nameOrIndex
encode a collection of objects

o  visitDictionary: aCollection with: nameOrIndex
encode a dictionary.
A collection of Associations is encoded

o  visitFloat: aNumber with: nameOrIndex
encode a float

o  visitInteger: aNumber with: nameOrIndex
encode an integer

o  visitInterval: anInterval with: aParameter
do not encode this as a sequenceable collection, but
encode the instance variables

o  visitNilWith: nameOrIndex
encode nil.
Be careful, often nil is not coded, but ignored

o  visitNumber: aNumber with: nameOrIndex
encode a number

o  visitObject: anObject with: nameOrIndex
encode an object.
Encode all the objects contained in anObject

o  visitSequenceableCollection: aCollection with: nameOrIndex
encode a sequenceable collection.
Nil elements in the collection are suppressed

o  visitString: aString with: nameOrIndex
self encodingOf:''
self encodingOf:'abc'
self encodingOf:'<abc'
self encodingOf:'&abc'
self encodingOf:'&abc
def'

o  visitSymbol: aSymbol with: nameOrIndex
self encodingOf:#abc


Examples:


<<EOF save a point:
     (XMLStandardCoder on:Transcript) nextPut:1 @ 2 .
save an array:
     |o|

     o := Array new:3.
     o at:1 put:1 @ 2.
     o at:2 put:'hello'.
     o at:3 put:o.
     (XMLStandardCoder on:Transcript) nextPut:o .
save and restore:
     |xmlText o s|

     s := '' writeStream.
     o := OrderedCollection new.
     o add:1 @ 2.
     o add:'hello'.
     o add:true.
     o add:o.
     xmlText := XMLStandardCoder encodingOf:o.
     Transcript showCR:xmlText.

     (XMLStandardDecoder on:(xmlText readStream)) next inspect
save and restore:
     |xmlText p o s decodedObject|

     s := '' writeStream.
     o := Array new:5.
     o at:1 put:(p := 1 @ 2).
     o at:2 put:p.
     o at:3 put:'hello'.
     o at:4 put:p.
     o at:5 put:o.
     xmlText := XMLStandardCoder encodingOf:o.
     Transcript showCR:xmlText.

     decodedObject := (XMLStandardDecoder on:(xmlText readStream)) next.
     decodedObject inspect.
     (decodedObject at:2) == (decodedObject at:4) ifFalse:[self halt].
     (decodedObject at:2) == (decodedObject at:1) ifFalse:[self halt].
save and restore. Use special aspect to encode nil variables:
     |xmlText o s encoder decoder decodedObject sharedString|

     s := '' writeStream.
     o := OrderedCollection new.
     o add:1 @ 2.
     o add:(sharedString := 'hello').
     o add:sharedString.
     o add:o.
     o add:(1 @ nil).
     encoder := XMLStandardCoder new aspect:#encodingVectorForInstanceVariables.
     encoder version:'1.0'.
     xmlText := encoder encodingOf:o.
     Transcript showCR:xmlText.

     decoder := XMLStandardDecoder on:xmlText readStream.
     decodedObject := decoder next.
     decodedObject inspect.
     Transcript cr; showCR:'Aspect:', decoder aspect, ' Version: ', decoder version.
     decodedObject size ~~ 5 ifTrue:[self halt].
     ((decodedObject at:2) == (decodedObject at:3)) ifFalse:[self halt].
     (decodedObject copyTo:3) = (o copyTo:3) ifFalse:[self halt].
     (decodedObject at:4) == decodedObject ifFalse:[self halt].
save and restore, and use message sends to restore:
     |xmlText o s sharedString decoder decodedObject|

     s := '' writeStream.
     o := Set new.
     o add:1 @ 2.
     o add:(sharedString := 'hello').
     o add:sharedString.
     o add:o.
     xmlText := XMLStandardCoder encodingOf:o.
     Transcript showCR:xmlText.

     decoder := XMLStandardDecoder on:(xmlText readStream).
     decoder useSend:true.
     decodedObject := decoder next.
     decodedObject inspect.

     decodedObject size ~~ 3 ifTrue:[self halt].
save and restore with references:
     |xmlText sharedString a o s|

     sharedString := 'hello world'.

     s := '' writeStream.
     a := Array new:2.
     a at:1 put:sharedString.

     o := OrderedCollection new.
     o add:nil.
     o add:'hello'.
     o add:sharedString.

     a at:2 put:o.
     xmlText := XMLStandardCoder encodingOf:a.
     Transcript showCR:xmlText.

     (XMLStandardDecoder on:(xmlText readStream)) next inspect
     |o xmlText|

     o := Array new:1.
     o at:1 put:o.
     xmlText := XMLStandardCoder encodingOf:o.
     Transcript showCR:xmlText.
     |o s|

    s := '
<sequence SIZE="1" ID="1">
<sequence ID="2"/>
</sequence>
'.
     (XMLStandardDecoder on:(s readStream)) next inspect

     |o s|

    s := '

<sequence SIZE="2" ID="1">
<sequence INDEX="1" IDREF="1"/>
</sequence>
'.
     (XMLStandardDecoder on:(s readStream)) next inspect

     |o s|

    s := '
<object ASPECT="encodingVector" CLASS="Expecco::ExpeccoPreferences" ID="1">
<sequence NAME="savedHostSetupList" ID="10"/>
<sequence NAME="projectPath" IDREF="10"/>
</object>
'.
     (XMLStandardDecoder on:(s readStream)) next inspect
EOF

ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Thu, 05 Dec 2024 02:33:53 GMT