01: /*
02: * Project: AMODA - Abstract Modeled Application
03: * Class: de.gulden.framework.amoda.generic.behaviour.CommandWrapper
04: * Version: snapshot-beautyj-1.1
05: *
06: * Date: 2004-09-29
07: *
08: * This is a snapshot version of the AMODA 0.2 development branch,
09: * it is not released as a seperate version.
10: * For AMODA, see http://amoda.berlios.de/.
11: *
12: * This is licensed under the GNU Lesser General Public License (LGPL)
13: * and comes with NO WARRANTY.
14: *
15: * Author: Jens Gulden
16: * Email: amoda@jensgulden.de
17: */
18:
19: package de.gulden.framework.amoda.generic.behaviour;
20:
21: import de.gulden.framework.amoda.generic.core.*;
22: import de.gulden.framework.amoda.model.behaviour.Command;
23: import de.gulden.framework.amoda.model.data.*;
24: import java.awt.event.*;
25: import java.lang.*;
26: import java.util.*;
27:
28: /**
29: * Class CommandWrapper.
30: *
31: * @author Jens Gulden
32: * @version snapshot-beautyj-1.1
33: */
34: public class CommandWrapper extends GenericCommand implements Command {
35:
36: // ------------------------------------------------------------------------
37: // --- fields ---
38: // ------------------------------------------------------------------------
39:
40: public String text;
41:
42: protected GenericApplicationMemberAbstract wrapped;
43:
44: // ------------------------------------------------------------------------
45: // --- methods ---
46: // ------------------------------------------------------------------------
47:
48: public void setParent(CompositeGroup parent) {
49: super .setParent(parent);
50: getWrapped().setParent(parent);
51: }
52:
53: public void setText(String _text) {
54: text = _text; // works as classname of wrapped command
55: }
56:
57: public GenericApplicationMemberAbstract getWrapped() {
58: text = text.trim();
59: if (wrapped == null) {
60: try {
61: Class clazz = Class.forName(text); // field "text" has been initialized by XML deserializer
62: wrapped = (GenericApplicationMemberAbstract) clazz
63: .newInstance();
64: } catch (Exception e) {
65: de.gulden.framework.amoda.generic.core.GenericApplicationEnvironmentFactory
66: .fatalError(
67: "cannot instantiate object of class '"
68: + text + "'", e);
69: }
70: }
71: return wrapped;
72: }
73:
74: public void actionPerformed(ActionEvent event) {
75: Object wrapped = getWrapped();
76: if (wrapped instanceof GenericCommand) {
77: ((GenericCommand) wrapped).actionPerformed(event);
78: } else {
79: perform();
80: }
81: }
82:
83: public void perform() {
84: de.gulden.framework.amoda.model.behaviour.Command wrapped = (de.gulden.framework.amoda.model.behaviour.Command) getWrapped();
85: if (wrapped.getParent() == null) { // make sure command has reference to a parent
86: wrapped.setParent(this .getParent());
87: }
88: wrapped.perform();
89: }
90:
91: } // end CommandWrapper
|