01: package fr.aliacom.form.common;
02:
03: import java.util.Hashtable;
04: import java.util.Iterator;
05:
06: /**
07: * This class is a collection of <code>FormVariable</code> that will be loaded
08: * in an <code>IForm</code> instance by a <code>FormLoader</code>.
09: *
10: * The variables defined in a form context will passed to python interpreters to
11: * be used as real python variables.
12: *
13: * @author tom
14: *
15: * (C) 2001, 2003 Thomas Cataldo
16: */
17: public final class FormContext implements Cloneable {
18:
19: private Hashtable vars;
20: private IForm form;
21:
22: public FormContext() {
23: vars = new Hashtable();
24: }
25:
26: public void setForm(IForm form) {
27: this .form = form;
28: }
29:
30: public IForm getForm() {
31: return form;
32: }
33:
34: public void addVariable(FormVariable fv) {
35: vars.put(fv.getName(), fv);
36: }
37:
38: public void addVariable(String name, Object value) {
39: addVariable(new FormVariable(name, value));
40: }
41:
42: public Iterator getVariables() {
43: return vars.values().iterator();
44: }
45:
46: public FormVariable get(String name) {
47: return (FormVariable) vars.get(name);
48: }
49:
50: public String toString() {
51: StringBuffer buf = new StringBuffer();
52: Iterator it = getVariables();
53: buf.append("/-[Printing FormContext]-\\\n");
54: while (it.hasNext()) {
55: buf.append("| ");
56: buf.append((FormVariable) it.next());
57: buf.append("\n");
58: }
59: buf.append("\\________________________/\n");
60: return buf.toString();
61: }
62:
63: public Object clone() throws CloneNotSupportedException {
64: FormContext ret = new FormContext();
65: Iterator it = getVariables();
66: while (it.hasNext()) {
67: ret.addVariable((FormVariable) it.next());
68: }
69: ret.setForm(form);
70: return ret;
71: }
72:
73: }
|