01: package org.obe.runtime.tool;
02:
03: import org.apache.velocity.context.AbstractContext;
04: import org.obe.spi.model.AttributeInstance;
05: import org.obe.spi.model.AttributeReadOnlyException;
06: import org.obe.xpdl.model.data.Type;
07:
08: import java.util.Map;
09:
10: /**
11: * @author Adrian Price
12: */
13: public class VelocityProcessContext extends AbstractContext {
14: private final Map _attrs;
15:
16: public VelocityProcessContext(Map attrs) {
17: _attrs = attrs;
18: }
19:
20: public Object internalGet(String key) {
21: return ((AttributeInstance) _attrs.get(key)).getValue();
22: }
23:
24: public Object internalPut(String key, Object value) {
25: AttributeInstance attr = (AttributeInstance) _attrs.get(key);
26: Object previousValue;
27: if (attr != null) {
28: try {
29: previousValue = attr.getValue();
30: attr.setValue(Type.DEFAULT_TYPE, value);
31: } catch (AttributeReadOnlyException e) {
32: throw new UnsupportedOperationException(
33: "put: readonly attribute: " + key);
34: }
35: } else {
36: throw new UnsupportedOperationException(
37: "put: undefined attribute: " + key);
38: }
39: return previousValue;
40: }
41:
42: public boolean internalContainsKey(Object key) {
43: return _attrs.containsKey(key);
44: }
45:
46: public Object[] internalGetKeys() {
47: return _attrs.keySet().toArray();
48: }
49:
50: public Object internalRemove(Object key) {
51: throw new UnsupportedOperationException("remove");
52: }
53: }
|