AspectVisitor.st
changeset 8393 26ee8a3be5e4
child 17711 39faaaf888b4
equal deleted inserted replaced
8392:17648405fc9b 8393:26ee8a3be5e4
       
     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 
       
    13 "{ Package: 'stx:libbasic' }"
       
    14 
       
    15 Visitor subclass:#AspectVisitor
       
    16 	instanceVariableNames:'aspect'
       
    17 	classVariableNames:''
       
    18 	poolDictionaries:''
       
    19 	category:'System-Visiting'
       
    20 !
       
    21 
       
    22 !AspectVisitor class methodsFor:'documentation'!
       
    23 
       
    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 
       
    38 documentation
       
    39 "
       
    40     This is a Visitor that visits only some aspects of an object.
       
    41 
       
    42     [author:]
       
    43         Stefan Vogel (stefan@zwerg)
       
    44 
       
    45     [instance variables:]
       
    46         aspect  <Symbol|Object>     something defining the aspect to be visited        
       
    47 
       
    48     [class variables:]
       
    49 
       
    50     [see also:]
       
    51 
       
    52 "
       
    53 ! !
       
    54 
       
    55 !AspectVisitor 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 
       
    69 !AspectVisitor methodsFor:'helpers'!
       
    70 
       
    71 aspectElementDescriptorFor:anObject
       
    72     "return association that should be visited for all child objects of anObject.
       
    73      Return a collection of associations. The association key is the name of the object,
       
    74      where the association value is the child object"
       
    75 
       
    76     ^ anObject elementDescriptorFor:aspect.
       
    77 
       
    78     "
       
    79         XMLStandardCoder new aspect:#elementDescriptorForInstanceVariables;
       
    80                  encodingOf:('blaKey' -> 'blaValue')
       
    81 
       
    82         XMLStandardCoder new aspect:#elementDescriptorForInstanceVariables;
       
    83                  encodingOf:('blaKey' -> nil)
       
    84 
       
    85         XMLStandardCoder new aspect:#elementDescriptorForNonNilInstanceVariables;
       
    86                  encodingOf:('blaKey' -> nil)
       
    87 
       
    88         XMLStandardCoder new aspect:#blaFaselQuall;
       
    89                  encodingOf:('blaKey' -> nil)
       
    90     "
       
    91 !
       
    92 
       
    93 visitChildrenOf:anObject
       
    94     "visit all child objects of anObject.
       
    95      If aspect is defined, perform aspect to fetch the child objects.
       
    96      Otherwise encode all the instance variables of anObject.
       
    97 
       
    98      Subclasses may send this message"
       
    99 
       
   100     |childObjectDescriptors|
       
   101 
       
   102     aspect isNil ifTrue:[
       
   103         "shortcut -- basic mechanism: visit instance variables by name"
       
   104         super visitChildrenOf:anObject.
       
   105         ^ self.
       
   106     ].
       
   107 
       
   108     childObjectDescriptors := self aspectElementDescriptorFor:anObject.
       
   109     childObjectDescriptors do:[:association|
       
   110         association notNil ifTrue:[
       
   111             association value acceptVisitor:self with:association key.
       
   112             self nextObject.
       
   113         ].
       
   114     ].
       
   115 
       
   116     "
       
   117         XMLStandardCoder new aspect:#elementDescriptorForInstanceVariables;
       
   118                  encodingOf:('blaKey' -> 'blaValue')
       
   119 
       
   120         XMLStandardCoder new aspect:#elementDescriptorForInstanceVariables;
       
   121                  encodingOf:('blaKey' -> nil)
       
   122 
       
   123         XMLStandardCoder new aspect:#elementDescriptorForNonNilInstanceVariables;
       
   124                  encodingOf:('blaKey' -> nil)
       
   125 
       
   126         XMLStandardCoder new aspect:#blaFaselQuall;
       
   127                  encodingOf:('blaKey' -> nil)
       
   128     "
       
   129 ! !
       
   130 
       
   131 !AspectVisitor class methodsFor:'documentation'!
       
   132 
       
   133 version
       
   134     ^ '$Header: /cvs/stx/stx/libbasic/AspectVisitor.st,v 1.1 2004-06-11 17:55:26 stefan Exp $'
       
   135 ! !