KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > gulden > framework > amoda > generic > core > GenericFeature


1 /*
2  * Project: AMODA - Abstract Modeled Application
3  * Class: de.gulden.framework.amoda.generic.core.GenericFeature
4  * Version: snapshot-beautyj-1.1
5  *
6  * Date: 2004-09-29
7  *
8  * This is a snapshot version of the AMODA 0.2 development branch,
9  * 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.core;
20
21 import de.gulden.framework.amoda.generic.data.GenericCompositeGroup;
22 import de.gulden.framework.amoda.generic.metadata.*;
23 import de.gulden.framework.amoda.generic.option.*;
24 import de.gulden.framework.amoda.model.behaviour.*;
25 import de.gulden.framework.amoda.model.core.Feature;
26 import de.gulden.framework.amoda.model.interaction.*;
27 import java.lang.*;
28 import java.util.*;
29
30 /**
31  * Class GenericFeature.
32  *
33  * @author Jens Gulden
34  * @version snapshot-beautyj-1.1
35  */

36 public class GenericFeature extends GenericCompositeGroup implements Feature, Command {
37
38     // ------------------------------------------------------------------------
39
// --- fields ---
40
// ------------------------------------------------------------------------
41

42     static final String JavaDoc[] FEATURE_MEMBERS = {"command","rule","state","message","dialog","question","feature-group","feature"};
43
44     public static final Object JavaDoc[][] XML_COLLECTION_ELEMENTS = {{"all",FEATURE_MEMBERS}};
45
46     public boolean enabled = true;
47
48     public boolean system = false;
49
50     public boolean constant = false;
51
52     public String JavaDoc shortcut = null;
53
54     public String JavaDoc style = null;
55
56
57     // ------------------------------------------------------------------------
58
// --- methods ---
59
// ------------------------------------------------------------------------
60

61     public boolean isEnabled() {
62         return enabled;
63     }
64
65     public void setEnabled(boolean _enabled) {
66         enabled = _enabled;
67     }
68
69     public Message getMessage(String JavaDoc id) {
70         return (Message)get(id);
71     }
72
73     public Question getQuestion(String JavaDoc id) {
74         return (Question)get(id);
75     }
76
77     public Dialog getDialog(String JavaDoc id) {
78         return (Dialog)get(id);
79     }
80
81     public Command getCommand(String JavaDoc id) {
82         return (Command)get(id);
83     }
84
85     public Rule getRule(String JavaDoc id) {
86         return (Rule)get(id);
87     }
88
89     public State getState(String JavaDoc id) {
90         // your code here
91
return null;
92     }
93
94     public boolean isSystem() {
95         return system;
96     }
97
98     public void setSystem(boolean _system) {
99         system = _system;
100     }
101
102     public boolean isConstant() {
103         return constant;
104     }
105
106     public void setConstant(boolean _constant) {
107         constant = _constant;
108     }
109
110     public String JavaDoc getShortcut() {
111         return shortcut;
112     }
113
114     public void setShortcut(String JavaDoc _shortcut) {
115         shortcut = _shortcut;
116     }
117
118     public GenericFeature getByShortcut(String JavaDoc shortcut, boolean recursive) {
119         /*String thisShortcut = this.getShortcut();
120         if (thisShortcut!=null) {
121             if (shortcut.equals(thisShortcut)) {
122                 return this;
123             }
124         }*/

125         Map children = getAll(GenericFeature.class, recursive);
126         for (Iterator it = children.values().iterator(); it.hasNext(); ) {
127             GenericFeature f = (GenericFeature)it.next();
128             String JavaDoc s = f.getShortcut();
129             if (s!=null) {
130                 if (shortcut.equals(f.getShortcut())) {
131                     return f;
132                 }
133             }
134         }
135         return null;
136     }
137
138     public void perform() {
139         for (Iterator it = getAll(de.gulden.framework.amoda.model.behaviour.Command.class, false).values().iterator(); it.hasNext(); ) {
140             de.gulden.framework.amoda.model.behaviour.Command command = (de.gulden.framework.amoda.model.behaviour.Command)it.next();
141             if (command.getParent()==null) { // make sure command has reference to a parent
142
command.setParent(this);
143             }
144             command.perform();
145         }
146     }
147
148     public String JavaDoc getStyle() {
149         return style;
150     }
151
152     public void setStyle(String JavaDoc _style) {
153         style = _style;
154     }
155
156     public Properties getStyleAttributes() {
157         String JavaDoc style = getStyle();
158         if (style != null) {
159             return de.gulden.util.Toolbox.parseKeyValuePairs(style);
160         } else {
161             return new Properties();
162         }
163     }
164
165 } // end GenericFeature
166
Popular Tags