Index: xotcl/library/patterns/ChainOfResponsibility.xotcl =================================================================== diff -u -r5ce5a10c82bc948f50fc4542f844dcd50de1eae3 -r435b41481fb51bf000ebe736d8574fefbeec1710 --- xotcl/library/patterns/ChainOfResponsibility.xotcl (.../ChainOfResponsibility.xotcl) (revision 5ce5a10c82bc948f50fc4542f844dcd50de1eae3) +++ xotcl/library/patterns/ChainOfResponsibility.xotcl (.../ChainOfResponsibility.xotcl) (revision 435b41481fb51bf000ebe736d8574fefbeec1710) @@ -1,43 +1,53 @@ -# $Id: ChainOfResponsibility.xotcl,v 1.2 2004/07/03 21:19:39 neumann Exp $ +# $Id: ChainOfResponsibility.xotcl,v 1.3 2005/09/09 21:07:23 neumann Exp $ + package provide xotcl::pattern::chainOfResponsibility 0.9 +package require XOTcl -Class ChainOfResponsibility -superclass Class +namespace eval ::xotcl::pattern::chainOfResponsibility { + namespace import ::xotcl::* -ChainOfResponsibility instproc chainingFilter args { - set cp [self calledproc] - set registrationclass [lindex [self filterreg] 0] - $registrationclass instvar operations - #puts stderr "CHAIN [array names [self regclass]::chainedOperations ]---$cp" - if {[$registrationclass exists chainedOperations($cp)]} { - # - # a value is found on the chain, if it differs from the failure value ! - # - set failureValue [$registrationclass set chainedOperations($cp)] - set r [my $cp $args] - if {$r == $failureValue} { - if {[my exists successor] && - [set s [my set successor]] != ""} { - #puts stderr "CHAIN: forwarding to $s" - set r [$s $cp $args] - } + Class ChainOfResponsibility -superclass Class + + ChainOfResponsibility instproc chainingFilter args { + set cp [self calledproc] + set registrationclass [lindex [self filterreg] 0] + $registrationclass instvar operations + #puts stderr "CHAIN [array names [self regclass]::chainedOperations ]---$cp" + if {[$registrationclass exists chainedOperations($cp)]} { + # + # a value is found on the chain, if it differs from the failure value ! + # + set failureValue [$registrationclass set chainedOperations($cp)] + set r [my $cp $args] + if {$r == $failureValue} { + if {[my exists successor] && + [set s [my set successor]] != ""} { + #puts stderr "CHAIN: forwarding to $s" + set r [$s $cp $args] + } + } + set r ;# return $r + } else { + next ;# return [next] + } } - set r ;# return $r - } else { - next ;# return [next] - } -} -ChainOfResponsibility instproc init args { - my instfilter add chainingFilter - my parameter {successor} - # chained operations hold their value of failure - my array set chainedOperations {} -} + ChainOfResponsibility instproc init args { + my instfilter add chainingFilter + my parameter {successor} + # chained operations hold their value of failure + my array set chainedOperations {} + } -ChainOfResponsibility instproc addChainedOperation {name {failureValue ""}} { - my set chainedOperations($name) $failureValue -} + ChainOfResponsibility instproc addChainedOperation {name {failureValue ""}} { + my set chainedOperations($name) $failureValue + } -ChainOfResponsibility instproc removeChainedOperation {name} { - my unset chainedOperations($name) + ChainOfResponsibility instproc removeChainedOperation {name} { + my unset chainedOperations($name) + } + + namespace export ChainOfResponsibility } + +namespace import ::xotcl::pattern::chainOfResponsibility::*