At last the EntityBatchingProducerNode is working. This will replace the old
[mir.git] / source / mircoders / producer / ContentMarkingProducerNode.java
1 package mircoders.producer;
2
3 import java.util.*;
4 import java.io.*;
5 import mir.util.*;
6 import mir.producer.*;
7 import mir.entity.*;
8 import mir.entity.adapter.*;
9 import mircoders.entity.*;
10
11
12 public class ContentMarkingProducerNode implements ProducerNode {
13   private String contentKey;
14
15   public ContentMarkingProducerNode(String aContentKey) {
16     contentKey = aContentKey;
17   }
18
19   public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure {
20     Object data;
21     Entity entity;
22
23     try {
24       data = ParameterExpander.findValueForKey( aValueMap, contentKey );
25
26       if (! (data instanceof EntityAdapter)) {
27         throw new ProducerFailure("ContentMarkingProducerNode: value of '"+contentKey+"' is not an EntityAdapter, but an " + data.getClass().getName(), null);
28       }
29
30       entity = ((EntityAdapter) data).getEntity();
31       if (! (entity instanceof EntityContent)) {
32         throw new ProducerFailure("ContentMarkingProducerNode: value of '"+contentKey+"' is not a content EntityAdapter, but a " + entity.getClass().getName() + " adapter", null);
33       }
34
35       ((EntityContent) entity).setProduced(true);
36     }
37     catch (Throwable t) {
38       aLogger.println("Error while marking content: " + t.getMessage());
39       t.printStackTrace(aLogger);
40
41       throw new ProducerFailure(t.getMessage(), t);
42     }
43   }
44
45   public Set buildVerbSet() {
46     return new HashSet();
47   }
48 }