# $Id: s.OnCalleeProxy.xotcl 1.7 01/03/23 21:55:33+01:00 neumann@somewhere.wu-wien.ac.at $
package provide xotcl::pattern::onCalleeProxy 0.8

Class OnCalleeProxy -superclass Class  

OnCalleeProxy metadata add description

OnCalleeProxy metadata description "
  Simple proxy pattern implementation enhanced with the ability to adapt
  calls solely for specified calling objects
  for each calling obj there may be a different delegator obj
"

OnCalleeProxy instproc onCalleeProxyFilter args { 
  set o [string trimleft [self callingobject] :]
  [self] instvar callee
  #puts stderr "[self class]: checking $o -- [self] -- [self calledproc] "
  if {[info exists callee($o)]} {
    return [::eval [set callee($o)] [self calledproc] $args]
  } else {
    next
  }
}

OnCalleeProxy instproc init args {
  [self] filterappend [self class]::onCalleeProxyFilter
  next
  [self] instproc setCallee {callingObj a} {
    [self] set callee([string trimleft $callingObj :]) $a
  }
}
