1 package mircoders.producer;
8 import mir.entity.adapter.*;
9 import mircoders.entity.*;
10 import mircoders.module.*;
11 import mircoders.storage.*;
14 public class ContentModifyingProducerNode implements ProducerNode {
15 private String contentKey;
16 private String fieldNameExpression;
17 private String valueExpression;
19 public ContentModifyingProducerNode(String aContentKey, String aFieldNameExpression, String aValueExpression) {
20 contentKey = aContentKey;
21 fieldNameExpression = aFieldNameExpression;
22 valueExpression = aValueExpression;
25 public void produce(Map aValueMap, String aVerb, PrintWriter aLogger) throws ProducerFailure {
32 ModuleContent contentModule = new ModuleContent(DatabaseContent.getInstance());
34 data = ParameterExpander.findValueForKey( aValueMap, contentKey );
36 if (! (data instanceof EntityAdapter)) {
37 throw new ProducerFailure("ContentModifyingProducerNode: value of '"+contentKey+"' is not an EntityAdapter, but an " + data.getClass().getName(), null);
40 entity = ((EntityAdapter) data).getEntity();
41 if (! (entity instanceof EntityContent)) {
42 throw new ProducerFailure("ContentModifyingProducerNode: value of '"+contentKey+"' is not a content EntityAdapter, but a " + entity.getClass().getName() + " adapter", null);
45 value = ParameterExpander.expandExpression(aValueMap, valueExpression);
46 fieldName = ParameterExpander.expandExpression(aValueMap, fieldNameExpression);
48 entity.setValueForProperty("is_produced", "0");
49 entity.setValueForProperty(fieldName, value);
52 aLogger.println(" Modified content " + entity.get("id") + ": " + fieldName + " = " + value );
55 aLogger.println("Error while modifying content: " + t.getMessage());
56 t.printStackTrace(aLogger);
58 throw new ProducerFailure(t.getMessage(), t);
62 public Set buildVerbSet() {