1 package org.andromda.metafacades.uml14;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Iterator;
6 import java.util.LinkedHashSet;
7 import org.andromda.metafacades.uml.AttributeFacade;
8 import org.andromda.metafacades.uml.ClassifierFacade;
9 import org.andromda.metafacades.uml.EventFacade;
10 import org.andromda.metafacades.uml.FrontEndAction;
11 import org.andromda.metafacades.uml.FrontEndControllerOperation;
12 import org.andromda.metafacades.uml.FrontEndEvent;
13 import org.andromda.metafacades.uml.FrontEndForward;
14 import org.andromda.metafacades.uml.ModelElementFacade;
15 import org.andromda.metafacades.uml.OperationFacade;
16 import org.andromda.metafacades.uml.TransitionFacade;
17 import org.andromda.metafacades.uml.UMLProfile;
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.collections.Predicate;
20 import org.apache.commons.collections.Transformer;
21 import org.apache.commons.lang.ObjectUtils;
22 import org.apache.commons.lang.StringUtils;
23
24
25
26
27
28
29
30 public class FrontEndParameterLogicImpl
31 extends FrontEndParameterLogic
32 {
33 private static final long serialVersionUID = 2219144832310011722L;
34
35
36
37
38
39 public FrontEndParameterLogicImpl(
40 Object metaObject,
41 String context)
42 {
43 super(metaObject, context);
44 }
45
46
47
48
49 @Override
50 protected boolean handleIsControllerOperationArgument()
51 {
52 return this.getControllerOperation() != null;
53 }
54
55
56
57
58 @Override
59 protected OperationFacade handleGetControllerOperation()
60 {
61 return this.getOperation();
62 }
63
64
65
66
67 @Override
68 protected boolean handleIsContainedInFrontEndUseCase()
69 {
70 return this.getEvent() instanceof FrontEndEvent || this.getOperation() instanceof FrontEndControllerOperation;
71 }
72
73
74
75
76 @Override
77 protected Object handleGetView()
78 {
79 Object view = null;
80 final EventFacade event = this.getEvent();
81 if (event != null)
82 {
83 final TransitionFacade transition = event.getTransition();
84 if (transition instanceof FrontEndAction)
85 {
86 final FrontEndAction action = (FrontEndAction)transition;
87 view = action.getInput();
88 }
89 else if (transition instanceof FrontEndForward)
90 {
91 final FrontEndForward forward = (FrontEndForward)transition;
92 if (forward.isEnteringView())
93 {
94 view = forward.getTarget();
95 }
96 }
97 }
98 return view;
99 }
100
101
102
103
104 @Override
105 protected boolean handleIsActionParameter()
106 {
107 final FrontEndAction action = this.getAction();
108 return action != null && action.getParameters().contains(this.THIS());
109 }
110
111
112
113
114 @Override
115 protected FrontEndAction handleGetAction()
116 {
117 Object actionObject = null;
118 final EventFacade event = this.getEvent();
119 if (event != null)
120 {
121 final TransitionFacade transition = event.getTransition();
122 if (transition instanceof FrontEndAction)
123 {
124 actionObject = transition;
125 }
126 }
127 return (FrontEndAction)actionObject;
128 }
129
130
131
132
133 @Override
134 protected boolean handleIsTable()
135 {
136 boolean isTable = false;
137 final ClassifierFacade type = this.getType();
138 if (type != null)
139 {
140 isTable = type.isCollectionType() || type.isArrayType();
141 if (isTable)
142 {
143 final String tableTaggedValue = ObjectUtils.toString(this.findTaggedValue(UMLProfile.TAGGEDVALUE_PRESENTATION_IS_TABLE));
144 isTable =
145 StringUtils.isNotBlank(tableTaggedValue) ? Boolean.valueOf(tableTaggedValue.trim()) : true;
146 if (!isTable)
147 {
148 isTable = !this.getTableColumnNames().isEmpty();
149 }
150 }
151 }
152 return isTable && this.getOperation() == null;
153 }
154
155
156
157
158 @Override
159 protected Collection<String> handleGetTableColumnNames()
160 {
161 final Collection tableColumnNames = new LinkedHashSet();
162 final Collection taggedValues = this.findTaggedValues(UMLProfile.TAGGEDVALUE_PRESENTATION_TABLE_COLUMNS);
163 if (!taggedValues.isEmpty())
164 {
165 for (final Iterator iterator = taggedValues.iterator(); iterator.hasNext();)
166 {
167 final String taggedValue = StringUtils.trimToNull(String.valueOf(iterator.next()));
168 if (taggedValue != null)
169 {
170 final String[] properties = taggedValue.split("[,\\s]+");
171 for (int ctr = 0; ctr < properties.length; ctr++)
172 {
173 final String property = properties[ctr];
174 tableColumnNames.add(property);
175 }
176 }
177 }
178 }
179
180 if (tableColumnNames.isEmpty())
181 {
182 tableColumnNames.addAll(this.getTableAttributeNames());
183 }
184 return tableColumnNames;
185 }
186
187
188
189
190 @Override
191 protected Collection<String> handleGetTableColumns()
192 {
193 final Collection tableColumns = new ArrayList(this.getNonArrayAttributes());
194 final Collection tableColumnNames = this.getTableColumnNames();
195 CollectionUtils.filter(tableColumns,
196 new Predicate()
197 {
198 public boolean evaluate(final Object object)
199 {
200 final ModelElementFacade attribute = (ModelElementFacade)object;
201 final String attributeName = attribute.getName();
202 return attributeName != null && tableColumnNames.contains(attributeName);
203 }
204 });
205 return tableColumns;
206 }
207
208
209
210
211
212
213 private Collection getNonArrayAttributes()
214 {
215 final Collection nonArrayAttributes = new ArrayList();
216 final ClassifierFacade type = this.getType();
217 if (type != null && type.isArrayType())
218 {
219 final ClassifierFacade nonArrayType = type.getNonArray();
220 if (nonArrayType != null)
221 {
222 nonArrayAttributes.addAll(nonArrayType.getAttributes(true));
223 }
224 }
225 return nonArrayAttributes;
226 }
227
228
229
230
231 @Override
232 protected Collection<String> handleGetTableAttributeNames()
233 {
234 final Collection tableAttributeNames = new ArrayList(this.getNonArrayAttributes());
235 CollectionUtils.transform(tableAttributeNames,
236 new Transformer()
237 {
238 public Object transform(final Object object)
239 {
240 return ((AttributeFacade)object).getName();
241 }
242 });
243 return tableAttributeNames;
244 }
245 }