ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.jbpm.pvm.internal.wire.descriptor;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.jbpm.pvm.internal.wire.Descriptor;
import org.jbpm.pvm.internal.wire.WireContext;
import org.jbpm.pvm.internal.wire.WireException;
 
/**
 *
 * <p>This {@link Descriptor} creates a {@link Map}.</p>
 *
 * <p>If no specific implementation for the {@link Map} is specified, a {@link HashMap} will be used.</p>
 *
 * <p>Entries can be added during the map initialization. The list of entries (key, value) to add must be specified with two operations:
 * <ol>
 * <li>{@link #setKeyDescriptors(List)} sets the list of the keys to generate.</li>
 * <li>{@link #setValueDescriptors(List)} sets the list of value associated with these keys.</li>
 * </ol>
 * The two lists must be in the same order
 * (the n-th element of the key list will be associated with the n-th element of the value list).</p>
 *
 * @author Tom Baeyens
 * @author Guillaume Porcher (documentation)
 *
 * @see Descriptor
 */
public class MapDescriptor extends CollectionDescriptor {
 
  private static final long serialVersionUID = 1L;
 
  List<Descriptor> keyDescriptors;
 
  public MapDescriptor() {
    super(HashMap.class.getName());
  }
 
  public void initialize(Object object, WireContext wireContext) {
    Map<Object,Object> map = (Map<Object,Object>) object;
    try {
      if (keyDescriptors!=null) {
        for (int i=0; i<keyDescriptors.size(); i++) {
          Descriptor keyDescriptor = keyDescriptors.get(i);
          Descriptor valueDescriptor = valueDescriptors.get(i);
          Object key = wireContext.create(keyDescriptor, true);
          Object value = wireContext.create(valueDescriptor, true);
          map.put(key, value);
        }
      }
    } catch (WireException e) {
      throw e;
    } catch (Exception e) {
      throw new WireException("couldn't initialize object '"+(name!=null ? name : className)+"'", e);
    }
  }
  
  
 
  public List<Descriptor> getKeyDescriptors() {
    return keyDescriptors;
  }
 
  public void setKeyDescriptors(List<Descriptor> keyDescriptors) {
    this.keyDescriptors = keyDescriptors;
  }
}