Packageorg.granite.reflect.visitor
Classpublic class Guide

The Guide class is the entry point of the visitor pattern implementation. It uses an array of IHandlers in order to explore and expose to a visitor the properties of a given bean. Exploring a beans graph is a sequence of two-phases processes: for each bean, first, the visitor is asked if it accepts to visit each property of the current bean; second, for each accepted property of this bean, the property is visited and cascaded.

A Guide instance is not intended to be used more than once. Any attempt to reuse an already used intance will throw an error.

A typical usage would be:

  var guide:Guide = new Guide(new MyVisitorImpl());
  guide.explore(myBean);

See also

IHandler
IVisitor


Public Properties
 PropertyDefined by
  defaultHandlers : Array
[static][read-only] The array of the default handlers (not including the NullHandler)used when visiting a given bean.
Guide
  handlers : Array
[read-only] The array IHandlers used by this Guide instance.
Guide
  recursionStrategy : String
[read-only] The recursion strategy used by this Guide instance.
Guide
  visitor : IVisitor
[read-only] The IVisitor implementation used by this Guide instance.
Guide
Public Methods
 MethodDefined by
  
Guide(visitor:IVisitor, handlers:Array = null, recursionStrategy:String)
Constructs a new Guide that will explore a given bean and expose its properties to the supplied visitor implementation.
Guide
  
explore(o:*):void
Explore the supplied bean, exposing its properties to the current visitor.
Guide
  
exploreVisitable(visitable:Visitable):void
Explore the supplied Visitable, exposing its properties to the current visitor.
Guide
Protected Methods
 MethodDefined by
  
accept(visitor:IVisitor, visitable:Visitable):void
Try to find a IHandler instance that will handle the visit of the visitable item by the visitor object.
Guide
  
isInContext(value:*):Boolean
Checks if the supplied parameter is already in the recursion context (ie.
Guide
  
popFromContext(value:*):void
Remove the supplied parameter from the recursion context (this method does nothing when the recursion strategy is "dictionary").
Guide
  
pushInContext(value:*):void
Put the supplied parameter in the recursion context (so it is marked as already visited).
Guide
Public Constants
 ConstantDefined by
  RS_DICTIONARY : String = "dictionary"
[static] The constant for "dictionary" recursion strategy: an instance of a bean is only visited once, even if it appears several times in an objects graph (this is the default).
Guide
  RS_STACK : String = "stack"
[static] The constant for "stack" recursion strategy: an instance of a bean is visited if and only if it wasn't already visited in the current path fo the objects graph.
Guide
Property detail
defaultHandlersproperty
defaultHandlers:Array  [read-only]

The array of the default handlers (not including the NullHandler)used when visiting a given bean. This array may be modified in order to globally add a specific handler (or replace an existing one).

Implementation
    public static function get defaultHandlers():Array
handlersproperty 
handlers:Array  [read-only]

The array IHandlers used by this Guide instance.

Implementation
    public function get handlers():Array
recursionStrategyproperty 
recursionStrategy:String  [read-only]

The recursion strategy used by this Guide instance.

Implementation
    public function get recursionStrategy():String
visitorproperty 
visitor:IVisitor  [read-only]

The IVisitor implementation used by this Guide instance.

Implementation
    public function get visitor():IVisitor
Constructor detail
Guide()constructor
public function Guide(visitor:IVisitor, handlers:Array = null, recursionStrategy:String)

Constructs a new Guide that will explore a given bean and expose its properties to the supplied visitor implementation.

Parameters
visitor:IVisitor — a IVisitor implementation.
 
handlers:Array (default = null) — an array of specific handlers to insert between the NullHandler and the default handlers.
 
recursionStrategy:String — the recursion strategy to be used when visiting a bean (must be RS_DICTIONARY or RS_STACK). Default is RS_DICTIONARY.

See also

Method detail
accept()method
protected function accept(visitor:IVisitor, visitable:Visitable):void

Try to find a IHandler instance that will handle the visit of the visitable item by the visitor object.

Parameters
visitor:IVisitor — the IVisitor that will visit the item.
 
visitable:Visitable — the Visitable item to visit.
explore()method 
public function explore(o:*):void

Explore the supplied bean, exposing its properties to the current visitor.

This method is a shortcut for: exploreVisitable(new Visitable(null, Type.forInstance(o), o)).

Parameters
o:* — the bean to explore.
exploreVisitable()method 
public function exploreVisitable(visitable:Visitable):void

Explore the supplied Visitable, exposing its properties to the current visitor.

Parameters
visitable:Visitable — the visitable to explore.
isInContext()method 
protected function isInContext(value:*):Boolean

Checks if the supplied parameter is already in the recursion context (ie. already visited).

Parameters
value:* — the value to check against the current recursion context.

Returns
Booleantrue if value is already in the recursion context, false otherwise.
popFromContext()method 
protected function popFromContext(value:*):void

Remove the supplied parameter from the recursion context (this method does nothing when the recursion strategy is "dictionary").

Parameters
value:* — the value to remove from the recursion context.
pushInContext()method 
protected function pushInContext(value:*):void

Put the supplied parameter in the recursion context (so it is marked as already visited).

Parameters
value:* — the value to put in the recursion context.
Constant detail
RS_DICTIONARYconstant
public static const RS_DICTIONARY:String = "dictionary"

The constant for "dictionary" recursion strategy: an instance of a bean is only visited once, even if it appears several times in an objects graph (this is the default).

RS_STACKconstant 
public static const RS_STACK:String = "stack"

The constant for "stack" recursion strategy: an instance of a bean is visited if and only if it wasn't already visited in the current path fo the objects graph.