View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] Filter Chaining Question

From: Sheik Yussuff <sheik_at_carib-link.net>
Date: Sun, 15 Jul 2001 16:45:40 -0300

Subject: The Adapter pattern inplemented with filters(code from
distribution)

The code below from the XOTcl distribution is given below.
Suppose the class Adapter has another filter "filter2"
registered after the filter "adapterFilter".
My understanding of the code(below) is that only requests that
are not found in specificRequest will be filtered by
filter2.
.........................................................

Question:
If my understanding is correct, how can I have all
messages/requests to Adapter be filtered by both filters.
.........................................................

Code from distribution:

Class Adapter -superclass Class

Adapter metadata add description

Adapter metadata description {
  Simple adapter pattern meta-class taken from the paper
  'Filters as a Language Support for Design Patterns in
  Object-Oriented Scripting Languages'.
}


Adapter instproc adapterFilter args {
    # Appears that filter args == args of triggering method
    set r [self calledproc]
    [self] instvar specificRequest adaptee
    #puts [self]
    if {[info exists specificRequest($r)]} {
        #puts $args
        return [eval $adaptee $specificRequest($r) $args]
    }
    next
}

Adapter instproc init args {
    [self] filterappend [self class]::adapterFilter
    next
    [self] instproc setRequest {r sr} {
 [self] set specificRequest($r) $sr
    }
    [self] instproc setAdaptee {a} {
 [self] set adaptee $a
    }
}