#$Id: s.composite.xotcl 1.4 01/03/23 22:24:35+01:00 neumann@somewhere.wu-wien.ac.at $
Class Composite -superclass Class
Composite metadata add description
@ @File {
  description {
  Simple composite pattern meta-class taken from the paper 
  'Filters as a Language Support for Design Patterns in
  Object-Oriented Scripting Languages'. 
  }
}

Composite instproc addOperations args {
  foreach op $args {
    if {![my exists operations($op)]} {
      my set operations($op) $op
    }
  }
} 

Composite instproc removeOperations args {
  foreach op $args {
    if {![my exists operations($op)]} {
      my unset operations($op)
    }
  }
}

Composite instproc compositeFilter args {
  # get the operations class variable from the object's class
  set registrationclass [lindex [self filterreg] 0]
  $registrationclass instvar operations
  # get the request
  set r [self calledproc]
  puts ***compositeFilter--${r}--[self]

  # check if the request is a registered operation 
  if {[info exists operations($r)]} {
    foreach object [my info children] {
      # forward request
      eval $object $r $args
    }
  }
  return [next]    
}


Composite instproc init {args} {
  my array set operations {}
  next
  my instfilterappend compositeFilter 
}


