i changed the exception-handling of the new producers and localizers to use the multe...
[mir.git] / source / mircoders / producer / CompositeProducerFactory.java
1 package mircoders.producer;
2
3 import java.util.*;
4 import mir.entity.*;
5 import mir.producer.*;
6 import mircoders.storage.*;
7
8 public class CompositeProducerFactory implements ProducerFactory {
9   Map factories;          // verb -> Vector ( ProducerFactory )
10
11   public CompositeProducerFactory() {
12     factories = new HashMap();
13   }
14
15   private List factoriesForVerb(String aVerb) {
16     List result;
17
18     result=(List) factories.get(aVerb);
19
20     if (result==null) {
21       result=new Vector();
22
23       factories.put(aVerb, result);
24     }
25
26     return result;
27   }
28
29   public void addFactory(ProducerFactory aFactory) {
30     Iterator i;
31
32     i=aFactory.verbs();
33
34     while (i.hasNext()) {
35       factoriesForVerb((String) i.next()).add(aFactory);
36     }
37   }
38
39   public mir.producer.Producer makeProducer(String aVerb) throws ProducerFailure {
40     CompositeProducer result = new CompositeProducer();
41
42     Iterator i=factoriesForVerb(aVerb).iterator();
43
44     while (i.hasNext())
45       result.addProducer(((ProducerFactory) i.next()).makeProducer(aVerb));
46
47     return result;
48   }
49
50   public Iterator verbs() {
51     return factories.keySet().iterator();
52   }
53 }