Source Code Cross Referenced for StrutsActionLogicImpl.java in  » UML » AndroMDA-3.2 » org » andromda » cartridges » bpm4struts » metafacades » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » UML » AndroMDA 3.2 » org.andromda.cartridges.bpm4struts.metafacades 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.andromda.cartridges.bpm4struts.metafacades;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collection;
005:        import java.util.Collections;
006:        import java.util.HashMap;
007:        import java.util.Iterator;
008:        import java.util.LinkedHashMap;
009:        import java.util.LinkedHashSet;
010:        import java.util.List;
011:        import java.util.Map;
012:
013:        import org.andromda.cartridges.bpm4struts.Bpm4StrutsGlobals;
014:        import org.andromda.cartridges.bpm4struts.Bpm4StrutsProfile;
015:        import org.andromda.cartridges.bpm4struts.Bpm4StrutsUtils;
016:        import org.andromda.metafacades.uml.EventFacade;
017:        import org.andromda.metafacades.uml.FilteredCollection;
018:        import org.andromda.metafacades.uml.FrontEndEvent;
019:        import org.andromda.metafacades.uml.FrontEndForward;
020:        import org.andromda.metafacades.uml.FrontEndUseCase;
021:        import org.andromda.metafacades.uml.ModelElementFacade;
022:        import org.andromda.metafacades.uml.ParameterFacade;
023:        import org.andromda.metafacades.uml.PseudostateFacade;
024:        import org.andromda.metafacades.uml.StateVertexFacade;
025:        import org.andromda.metafacades.uml.TransitionFacade;
026:        import org.andromda.metafacades.uml.UMLProfile;
027:        import org.andromda.metafacades.uml.UseCaseFacade;
028:        import org.andromda.utils.StringUtilsHelper;
029:        import org.apache.commons.collections.CollectionUtils;
030:        import org.apache.commons.collections.Predicate;
031:        import org.apache.commons.lang.ObjectUtils;
032:        import org.apache.commons.lang.StringUtils;
033:
034:        /**
035:         * MetafacadeLogic implementation.
036:         *
037:         * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction
038:         */
039:        public class StrutsActionLogicImpl extends StrutsActionLogic {
040:            /**
041:             * All action states that make up this action, this includes all possible action states traversed
042:             * after a decision point too.
043:             */
044:            private Collection actionStates = null;
045:
046:            /**
047:             * All transitions leading into either a page or final state that originated from a call to this action.
048:             */
049:            private Map actionForwards = null;
050:
051:            /**
052:             * All transitions leading into a decision point that originated from a call to this action.
053:             */
054:            private Collection decisionTransitions = null;
055:
056:            /**
057:             * All transitions that can be traversed when calling this action.
058:             */
059:            private Collection transitions = null;
060:
061:            public StrutsActionLogicImpl(Object metaObject, String context) {
062:                super (metaObject, context);
063:            }
064:
065:            /**
066:             * Initializes all action states, action forwards, decision transitions and transitions in one shot, so that they
067:             * can be queried more effiencently later on.
068:             */
069:            private void initializeCollections() {
070:                actionStates = new LinkedHashSet();
071:                actionForwards = new HashMap();
072:                decisionTransitions = new LinkedHashSet();
073:                transitions = new LinkedHashSet();
074:                collectTransitions(this , transitions);
075:            }
076:
077:            /**
078:             * Recursively collects all action states, action forwards, decision transitions and transitions.
079:             *
080:             * @param transition           the current transition that is being processed
081:             * @param processedTransitions the set of transitions already processed
082:             */
083:            private void collectTransitions(TransitionFacade transition,
084:                    Collection processedTransitions) {
085:                if (processedTransitions.contains(transition)) {
086:                    return;
087:                }
088:                processedTransitions.add(transition);
089:
090:                final StateVertexFacade target = transition.getTarget();
091:                if ((target instanceof  StrutsJsp)
092:                        || (target instanceof  StrutsFinalState)) {
093:                    if (!actionForwards.containsKey(transition.getTarget())) {
094:                        actionForwards.put(transition.getTarget(), transition);
095:                    }
096:                } else if ((target instanceof  PseudostateFacade)
097:                        && ((PseudostateFacade) target).isDecisionPoint()) {
098:                    decisionTransitions.add(transition);
099:                    final Collection outcomes = target.getOutgoing();
100:                    for (final Iterator iterator = outcomes.iterator(); iterator
101:                            .hasNext();) {
102:                        final TransitionFacade outcome = (TransitionFacade) iterator
103:                                .next();
104:                        collectTransitions(outcome, processedTransitions);
105:                    }
106:                } else if (target instanceof  StrutsActionState) {
107:                    actionStates.add(target);
108:                    final FrontEndForward forward = ((StrutsActionState) target)
109:                            .getForward();
110:                    if (forward != null) {
111:                        collectTransitions(forward, processedTransitions);
112:                    }
113:                } else // all the rest is ignored but outgoing transitions are further processed
114:                {
115:                    final Collection outcomes = target.getOutgoing();
116:                    for (final Iterator iterator = outcomes.iterator(); iterator
117:                            .hasNext();) {
118:                        final TransitionFacade outcome = (TransitionFacade) iterator
119:                                .next();
120:                        collectTransitions(outcome, processedTransitions);
121:                    }
122:                }
123:            }
124:
125:            protected String handleGetActionName() {
126:                return getFormBeanName();
127:            }
128:
129:            protected String handleGetActionInput() {
130:                final StateVertexFacade source = getSource();
131:                return (source instanceof  StrutsJsp) ? ((StrutsJsp) source)
132:                        .getFullPath() : "";
133:            }
134:
135:            protected boolean handleIsMultipartFormData() {
136:                boolean multipartFormPost = false;
137:
138:                final Collection formFields = this .getActionFormFields();
139:                for (final Iterator fieldIterator = formFields.iterator(); !multipartFormPost
140:                        && fieldIterator.hasNext();) {
141:                    final StrutsParameter field = (StrutsParameter) fieldIterator
142:                            .next();
143:                    if (field.isFile()) {
144:                        multipartFormPost = true;
145:                    }
146:                }
147:
148:                return multipartFormPost;
149:            }
150:
151:            protected boolean handleIsFormPost() {
152:                final Object value = this 
153:                        .findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_ACTION_TYPE);
154:                return value == null
155:                        || Bpm4StrutsProfile.TAGGEDVALUE_ACTION_TYPE_FORM
156:                                .equals(value);
157:            }
158:
159:            protected boolean handleIsHyperlink() {
160:                final Object value = findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_ACTION_TYPE);
161:                return Bpm4StrutsProfile.TAGGEDVALUE_ACTION_TYPE_HYPERLINK
162:                        .equalsIgnoreCase(value == null ? null : value
163:                                .toString());
164:            }
165:
166:            protected boolean handleIsImageLink() {
167:                final Object value = findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_ACTION_TYPE);
168:                return Bpm4StrutsProfile.TAGGEDVALUE_ACTION_TYPE_IMAGE
169:                        .equalsIgnoreCase(value == null ? null : value
170:                                .toString());
171:            }
172:
173:            protected boolean handleIsTableAction() {
174:                return Bpm4StrutsProfile.TAGGEDVALUE_ACTION_TYPE_TABLE
175:                        .equals(this 
176:                                .findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_ACTION_TYPE));
177:            }
178:
179:            protected boolean handleIsTableRowAction() {
180:                return this .isTableLink() && !this .isTableAction();
181:            }
182:
183:            protected boolean handleIsTableLink() {
184:                return this .getTableLinkParameter() != null;
185:            }
186:
187:            protected Object handleGetTableLinkParameter() {
188:                StrutsParameter tableLinkParameter = null;
189:
190:                final String tableLinkName = getTableLinkName();
191:                if (tableLinkName != null) {
192:                    final StrutsJsp page = this .getInput();
193:                    if (page != null) {
194:                        final List tables = page.getTables();
195:                        for (int i = 0; i < tables.size()
196:                                && tableLinkParameter == null; i++) {
197:                            StrutsParameter table = (StrutsParameter) tables
198:                                    .get(i);
199:                            if (tableLinkName.equals(table.getName())) {
200:                                tableLinkParameter = table;
201:                            }
202:                        }
203:                    }
204:                }
205:
206:                return tableLinkParameter;
207:            }
208:
209:            protected List handleGetTableNonColumnFormParameters() {
210:                List tableNonColumnActionParameters = null;
211:
212:                final StrutsParameter table = getTableLinkParameter();
213:                if (table != null) {
214:                    final Map tableNonColumnActionParametersMap = new LinkedHashMap(
215:                            4);
216:                    final Collection columnNames = table.getTableColumnNames();
217:                    final List formActions = table.getTableFormActions();
218:                    for (int i = 0; i < formActions.size(); i++) {
219:                        final StrutsAction action = (StrutsAction) formActions
220:                                .get(i);
221:                        for (int j = 0; j < action.getActionParameters().size(); j++) {
222:                            final StrutsParameter parameter = (StrutsParameter) action
223:                                    .getActionParameters().get(j);
224:                            if (!columnNames.contains(parameter.getName())) {
225:                                tableNonColumnActionParametersMap.put(parameter
226:                                        .getName(), parameter);
227:                            }
228:                        }
229:                    }
230:
231:                    tableNonColumnActionParameters = new ArrayList(
232:                            tableNonColumnActionParametersMap.values());
233:                }
234:
235:                return tableNonColumnActionParameters;
236:            }
237:
238:            protected String handleGetTableLinkName() {
239:                String tableLink = null;
240:
241:                final Object value = findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_ACTION_TABLELINK);
242:                if (value != null) {
243:                    tableLink = StringUtils.trimToNull(value.toString());
244:
245:                    if (tableLink != null) {
246:                        final int columnOffset = tableLink.indexOf('.');
247:                        tableLink = (columnOffset == -1) ? tableLink
248:                                : tableLink.substring(0, columnOffset);
249:                    }
250:                }
251:
252:                return tableLink;
253:            }
254:
255:            protected String handleGetTableLinkColumnName() {
256:                String tableLink = null;
257:
258:                final Object value = findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_ACTION_TABLELINK);
259:                if (value != null) {
260:                    tableLink = StringUtils.trimToNull(value.toString());
261:
262:                    if (tableLink != null) {
263:                        final int columnOffset = tableLink.indexOf('.');
264:                        tableLink = (columnOffset == -1 || columnOffset == tableLink
265:                                .length() - 1) ? null : tableLink
266:                                .substring(columnOffset + 1);
267:                    }
268:                }
269:
270:                return tableLink;
271:            }
272:
273:            protected String handleGetImagePath() {
274:                return getPackagePath() + '/'
275:                        + Bpm4StrutsUtils.toWebFileName(getActionClassName())
276:                        + ".gif";
277:            }
278:
279:            protected java.lang.String handleGetActionPath() {
280:                return getActionPathRoot() + '/' + getActionClassName();
281:            }
282:
283:            protected String handleGetActionPathRoot() {
284:                String actionPathRoot = null;
285:
286:                final FrontEndUseCase useCase = this .getUseCase();
287:                if (useCase != null) {
288:                    final StringBuffer buffer = new StringBuffer();
289:
290:                    final String actionPathPrefix = Bpm4StrutsGlobals.PROPERTY_ACTION_PATH_PREFIX;
291:                    String prefix = this .isConfiguredProperty(actionPathPrefix) ? ObjectUtils
292:                            .toString(this 
293:                                    .getConfiguredProperty(actionPathPrefix))
294:                            : "";
295:
296:                    final ModelElementFacade useCasePackage = useCase
297:                            .getPackage();
298:                    if (useCasePackage != null) {
299:                        prefix = prefix.replaceAll("\\{0\\}", useCasePackage
300:                                .getPackagePath());
301:                    }
302:
303:                    buffer.append(prefix);
304:                    buffer.append('/');
305:                    buffer.append(StringUtilsHelper.upperCamelCaseName(useCase
306:                            .getName()));
307:
308:                    actionPathRoot = buffer.toString();
309:                }
310:                return actionPathRoot;
311:            }
312:
313:            protected String handleGetActionScope() {
314:                return "request";
315:            }
316:
317:            /**
318:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction#getActionRoles()
319:             */
320:            protected java.lang.String handleGetActionRoles() {
321:                final Collection users = getRoleUsers();
322:                final StringBuffer roles = new StringBuffer();
323:                for (final Iterator userIterator = users.iterator(); userIterator
324:                        .hasNext();) {
325:                    roles.append(((ModelElementFacade) userIterator.next())
326:                            .getName());
327:                    if (userIterator.hasNext()) {
328:                        roles.append(",");
329:                    }
330:                }
331:                return roles.toString();
332:            }
333:
334:            /**
335:             * Returns a collection containing StrutsUser instances representing the roles
336:             * authorized to call this action. If this action starts the use-case that use-case's users
337:             * are returned, otherwise it will return the users associated to the use-cases targetted by this
338:             * action (which may be none at all)
339:             */
340:            private Collection getRoleUsers() {
341:                final Collection roleUsers = new ArrayList();
342:
343:                if (this .isUseCaseStart()) {
344:                    final FrontEndUseCase useCase = getUseCase();
345:                    if (useCase != null) {
346:                        roleUsers.addAll(useCase.getRoles());
347:                    }
348:                } else {
349:                    for (final Iterator iterator = getActionForwards()
350:                            .iterator(); iterator.hasNext();) {
351:                        final TransitionFacade transition = (TransitionFacade) iterator
352:                                .next();
353:                        if (transition.getTarget() instanceof  StrutsFinalState) {
354:                            final FrontEndUseCase useCase = ((StrutsFinalState) transition
355:                                    .getTarget()).getTargetUseCase();
356:                            if (useCase != null) {
357:                                roleUsers.addAll(useCase.getRoles());
358:                            }
359:                        }
360:                    }
361:                }
362:
363:                return roleUsers;
364:            }
365:
366:            protected String handleGetActionClassName() {
367:                String name = null;
368:
369:                if (this .isExitingInitialState()) {
370:                    final UseCaseFacade useCase = this .getUseCase();
371:                    if (useCase != null) {
372:                        name = useCase.getName();
373:                    }
374:                } else {
375:                    final EventFacade trigger = getTrigger();
376:                    final String suffix = (trigger == null) ? getTarget()
377:                            .getName() : trigger.getName();
378:                    name = getSource().getName() + ' ' + suffix;
379:                }
380:                return StringUtilsHelper.upperCamelCaseName(name);
381:            }
382:
383:            protected String handleGetActionType() {
384:                return getPackageName() + '.' + getActionClassName();
385:            }
386:
387:            protected String handleGetFormBeanClassName() {
388:                return getActionClassName()
389:                        + Bpm4StrutsGlobals.FORM_IMPLEMENTATION_SUFFIX;
390:            }
391:
392:            protected String handleGetFormBeanName() {
393:                String formBeanName = null;
394:
395:                final UseCaseFacade useCase = this .getUseCase();
396:                if (useCase != null) {
397:                    final String useCaseName = useCase.getName();
398:                    formBeanName = StringUtilsHelper
399:                            .lowerCamelCaseName(useCaseName)
400:                            + getActionClassName()
401:                            + Bpm4StrutsGlobals.FORM_SUFFIX;
402:                }
403:                return formBeanName;
404:            }
405:
406:            protected String handleGetFormValidationMethodName() {
407:                return "validate" + this .getActionClassName()
408:                        + Bpm4StrutsGlobals.FORM_SUFFIX;
409:            }
410:
411:            protected String handleGetMessageKey() {
412:                String messageKey = null;
413:
414:                final StrutsTrigger actionTrigger = getActionTrigger();
415:                if (actionTrigger != null) {
416:                    messageKey = actionTrigger.getTriggerKey();
417:                }
418:
419:                return messageKey;
420:            }
421:
422:            protected String handleGetImageMessageKey() {
423:                return getMessageKey() + ".image";
424:            }
425:
426:            /**
427:             * Overrides the method defined in the facade parent of StrutsAction, this is done because actions (transitions) are
428:             * not directly contained in a UML namespace.
429:             */
430:            public String getPackageName() {
431:                String packageName = null;
432:
433:                final UseCaseFacade useCase = this .getUseCase();
434:                if (useCase != null) {
435:                    packageName = useCase.getPackageName();
436:                }
437:                return packageName;
438:            }
439:
440:            /**
441:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction#isResettable()
442:             */
443:            protected boolean handleIsResettable() {
444:                Object value = findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_ACTION_RESETTABLE);
445:                return isTrue(value == null ? null : value.toString());
446:            }
447:
448:            /**
449:             * Convenient method to detect whether or not a String instance represents a boolean <code>true</code> value.
450:             */
451:            private boolean isTrue(String string) {
452:                return "yes".equalsIgnoreCase(string)
453:                        || "true".equalsIgnoreCase(string)
454:                        || "on".equalsIgnoreCase(string)
455:                        || "1".equalsIgnoreCase(string);
456:            }
457:
458:            protected boolean handleIsUseCaseStart() {
459:                StateVertexFacade source = getSource();
460:                return source instanceof  PseudostateFacade
461:                        && ((PseudostateFacade) source).isInitialState();
462:            }
463:
464:            protected String handleGetFullActionPath() {
465:                return getPackagePath() + '/' + getActionClassName();
466:            }
467:
468:            protected String handleGetFullTilePath() {
469:                return isUseCaseStart() ? "empty-file" : getPackagePath() + '/'
470:                        + Bpm4StrutsUtils.toWebFileName(getActionClassName());
471:            }
472:
473:            /**
474:             * We override this method here to make sure the actions end-up in the same package as their use-case. A transition
475:             * (this class' parent type) does not have a real package as we need it here.
476:             */
477:            public String getPackagePath() {
478:                String packagePath = null;
479:
480:                final UseCaseFacade useCase = this .getUseCase();
481:                if (useCase != null) {
482:                    packagePath = '/' + useCase.getPackagePath();
483:                }
484:                return packagePath;
485:            }
486:
487:            protected String handleGetFullFormBeanPath() {
488:                return '/' + (getPackageName() + '/' + getFormBeanClassName())
489:                        .replace('.', '/');
490:            }
491:
492:            protected boolean handleIsValidationRequired() {
493:                final Collection actionParameters = getActionParameters();
494:                for (final Iterator iterator = actionParameters.iterator(); iterator
495:                        .hasNext();) {
496:                    final StrutsParameter parameter = (StrutsParameter) iterator
497:                            .next();
498:                    if (parameter.isValidationRequired()) {
499:                        return true;
500:                    }
501:                }
502:                return false;
503:            }
504:
505:            protected boolean handleIsDateFieldPresent() {
506:                final Collection actionParameters = getActionParameters();
507:                for (final Iterator iterator = actionParameters.iterator(); iterator
508:                        .hasNext();) {
509:                    StrutsParameter parameter = (StrutsParameter) iterator
510:                            .next();
511:                    if (parameter.isDate()) {
512:                        return true;
513:                    }
514:                }
515:                return false;
516:            }
517:
518:            protected boolean handleIsCalendarRequired() {
519:                final Collection actionParameters = getActionParameters();
520:                for (final Iterator iterator = actionParameters.iterator(); iterator
521:                        .hasNext();) {
522:                    StrutsParameter parameter = (StrutsParameter) iterator
523:                            .next();
524:                    if (parameter.isCalendarRequired()) {
525:                        return true;
526:                    }
527:                }
528:                return false;
529:            }
530:
531:            protected String handleGetFormBeanPackageName() {
532:                return getPackageName();
533:            }
534:
535:            protected String handleGetFormBeanType() {
536:                return getFormBeanPackageName() + '.' + getFormBeanClassName();
537:            }
538:
539:            protected String handleGetDocumentationKey() {
540:                final StrutsTrigger trigger = getActionTrigger();
541:                return ((trigger == null) ? getMessageKey()
542:                        + ".is.an.action.without.trigger" : trigger
543:                        .getTriggerKey())
544:                        + ".documentation";
545:            }
546:
547:            protected String handleGetDocumentationValue() {
548:                final String value = StringUtilsHelper
549:                        .toResourceMessage(getDocumentation("", 64, false));
550:                return (value == null) ? "" : value;
551:            }
552:
553:            protected String handleGetOnlineHelpKey() {
554:                final StrutsTrigger trigger = getActionTrigger();
555:                return ((trigger == null) ? getMessageKey()
556:                        + ".is.an.action.without.trigger" : trigger
557:                        .getTriggerKey())
558:                        + ".online.help";
559:            }
560:
561:            protected String handleGetOnlineHelpValue() {
562:                final String crlf = "<br/>";
563:                final StringBuffer buffer = new StringBuffer();
564:
565:                final String value = StringUtilsHelper
566:                        .toResourceMessage(getDocumentation("", 64, false));
567:                buffer
568:                        .append((value == null) ? "No action documentation has been specified"
569:                                : value);
570:                buffer.append(crlf);
571:
572:                return StringUtilsHelper.toResourceMessage(buffer.toString());
573:            }
574:
575:            protected List handleGetActionForwards() {
576:                if (actionForwards == null)
577:                    initializeCollections();
578:                return new ArrayList(actionForwards.values());
579:            }
580:
581:            protected List handleGetDecisionTransitions() {
582:                if (decisionTransitions == null)
583:                    initializeCollections();
584:                return new ArrayList(decisionTransitions);
585:            }
586:
587:            protected List handleGetActionStates() {
588:                if (actionStates == null)
589:                    initializeCollections();
590:                return new ArrayList(actionStates);
591:            }
592:
593:            protected List handleGetActionExceptions() {
594:                final Collection exceptions = new LinkedHashSet();
595:                final Collection actionStates = getActionStates();
596:                for (final Iterator iterator = actionStates.iterator(); iterator
597:                        .hasNext();) {
598:                    StrutsActionState actionState = (StrutsActionState) iterator
599:                            .next();
600:                    exceptions.addAll(actionState.getExceptions());
601:                }
602:
603:                return new ArrayList(exceptions);
604:            }
605:
606:            /**
607:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction#getInput()
608:             */
609:            protected java.lang.Object handleGetInput() {
610:                Object input = null;
611:                final ModelElementFacade source = getSource();
612:                if (source instanceof  PseudostateFacade) {
613:                    final PseudostateFacade pseudostate = (PseudostateFacade) source;
614:                    if (pseudostate.isInitialState()) {
615:                        input = source;
616:                    }
617:                } else {
618:                    if (source
619:                            .hasStereotype(UMLProfile.STEREOTYPE_FRONT_END_VIEW)) {
620:                        input = source;
621:                    }
622:                }
623:                return input;
624:            }
625:
626:            protected Object handleGetController() {
627:                final StrutsActivityGraph graph = this .getStrutsActivityGraph();
628:                return graph == null ? null : graph.getController();
629:            }
630:
631:            protected Object handleGetActionTrigger() {
632:                return this .getTrigger();
633:            }
634:
635:            protected List handleGetActionFormFields() {
636:                final Map formFieldMap = new HashMap();
637:
638:                /**
639:                 * for useCaseStart actions we need to detect all usecases forwarding to the one belonging to this action
640:                 * if there are any parameters in those requests we need to have them included in this action's form
641:                 */
642:                if (this .isUseCaseStart()) {
643:                    final FrontEndUseCase useCase = this .getUseCase();
644:                    if (useCase != null) {
645:                        final Collection finalStates = useCase
646:                                .getReferencingFinalStates();
647:                        for (final Iterator finalStateIterator = finalStates
648:                                .iterator(); finalStateIterator.hasNext();) {
649:                            final Object finalStateObject = finalStateIterator
650:                                    .next();
651:                            // we need to test for the type because a non struts-use-case final state might accidently
652:                            // we linking to this use-case (for example: the user temporarily wants to disable code generation
653:                            // for a specific use-case and is not removing the final-state to use-case link(s))
654:                            if (finalStateObject instanceof  StrutsFinalState) {
655:                                final StrutsFinalState finalState = (StrutsFinalState) finalStateObject;
656:                                final Collection parameters = finalState
657:                                        .getInterUseCaseParameters();
658:                                for (final Iterator parameterIterator = parameters
659:                                        .iterator(); parameterIterator
660:                                        .hasNext();) {
661:                                    final ParameterFacade parameter = (ParameterFacade) parameterIterator
662:                                            .next();
663:                                    formFieldMap.put(parameter.getName(),
664:                                            parameter);
665:                                }
666:                            }
667:                        }
668:                    }
669:                }
670:
671:                // if any action encountered by the execution of the complete action-graph path emits a forward
672:                // containing one or more parameters they need to be included as a form field too
673:                final Collection actionStates = getActionStates();
674:                for (final Iterator iterator = actionStates.iterator(); iterator
675:                        .hasNext();) {
676:                    final StrutsActionState actionState = (StrutsActionState) iterator
677:                            .next();
678:                    final StrutsForward forward = (StrutsForward) actionState
679:                            .getForward();
680:                    if (forward != null) {
681:                        final Collection forwardParameters = forward
682:                                .getForwardParameters();
683:                        for (final Iterator parameterIterator = forwardParameters
684:                                .iterator(); parameterIterator.hasNext();) {
685:                            final ModelElementFacade forwardParameter = (ModelElementFacade) parameterIterator
686:                                    .next();
687:                            formFieldMap.put(forwardParameter.getName(),
688:                                    forwardParameter);
689:                        }
690:                    }
691:                }
692:
693:                // add page variables for all pages/final-states targetted
694:                // also add the fields of the target page's actions (for preloading)
695:                final Collection forwards = getActionForwards();
696:                for (final Iterator iterator = forwards.iterator(); iterator
697:                        .hasNext();) {
698:                    final StrutsForward forward = (StrutsForward) iterator
699:                            .next();
700:                    final StateVertexFacade target = forward.getTarget();
701:                    if (target instanceof  StrutsJsp) {
702:                        final StrutsJsp jsp = (StrutsJsp) target;
703:                        final Collection pageVariables = jsp.getPageVariables();
704:                        for (final Iterator pageVariableIterator = pageVariables
705:                                .iterator(); pageVariableIterator.hasNext();) {
706:                            final ModelElementFacade facade = (ModelElementFacade) pageVariableIterator
707:                                    .next();
708:                            formFieldMap.put(facade.getName(), facade);
709:                        }
710:                        final Collection allActionParameters = jsp
711:                                .getAllActionParameters();
712:                        for (final Iterator actionParameterIterator = allActionParameters
713:                                .iterator(); actionParameterIterator.hasNext();) {
714:                            final ModelElementFacade facade = (ModelElementFacade) actionParameterIterator
715:                                    .next();
716:                            formFieldMap.put(facade.getName(), facade);
717:                        }
718:                    } else if (target instanceof  StrutsFinalState) {
719:                        // only add these if there is no parameter recorded yet with the same name
720:                        final Collection forwardParameters = forward
721:                                .getForwardParameters();
722:                        for (final Iterator forwardParameterIterator = forwardParameters
723:                                .iterator(); forwardParameterIterator.hasNext();) {
724:                            final ModelElementFacade facade = (ModelElementFacade) forwardParameterIterator
725:                                    .next();
726:                            if (!formFieldMap.containsKey(facade.getName())) {
727:                                formFieldMap.put(facade.getName(), facade);
728:                            }
729:                        }
730:                    }
731:                }
732:
733:                // we do the action parameters in the end because they are allowed to overwrite existing properties
734:                final Collection actionParameters = getActionParameters();
735:                for (final Iterator actionParameterIterator = actionParameters
736:                        .iterator(); actionParameterIterator.hasNext();) {
737:                    final ModelElementFacade facade = (ModelElementFacade) actionParameterIterator
738:                            .next();
739:                    formFieldMap.put(facade.getName(), facade);
740:                }
741:
742:                return new ArrayList(formFieldMap.values());
743:            }
744:
745:            protected List handleGetDeferredOperations() {
746:                final Collection deferredOperations = new LinkedHashSet();
747:
748:                final StrutsController controller = getController();
749:                if (controller != null) {
750:                    final List actionStates = getActionStates();
751:                    for (int i = 0; i < actionStates.size(); i++) {
752:                        final StrutsActionState actionState = (StrutsActionState) actionStates
753:                                .get(i);
754:                        deferredOperations.addAll(actionState
755:                                .getControllerCalls());
756:                    }
757:
758:                    final List transitions = getDecisionTransitions();
759:                    for (int i = 0; i < transitions.size(); i++) {
760:                        final StrutsForward forward = (StrutsForward) transitions
761:                                .get(i);
762:                        final FrontEndEvent trigger = forward
763:                                .getDecisionTrigger();
764:                        if (trigger != null) {
765:                            deferredOperations.add(trigger.getControllerCall());
766:                        }
767:                    }
768:                }
769:                return new ArrayList(deferredOperations);
770:            }
771:
772:            protected List handleGetActionParameters() {
773:                final StrutsTrigger trigger = getActionTrigger();
774:                return (trigger == null) ? Collections.EMPTY_LIST
775:                        : new ArrayList(trigger.getParameters());
776:            }
777:
778:            protected List handleGetInterUseCaseParameters(
779:                    StrutsFinalState finalState) {
780:                List parameters;
781:
782:                if (finalState == null) {
783:                    parameters = Collections.EMPTY_LIST;
784:                } else {
785:                    // we don't want to list parameters with the same name to we use a hash map
786:                    final Map parameterMap = new HashMap();
787:
788:                    final List transitions = getActionForwards();
789:                    for (int i = 0; i < transitions.size(); i++) {
790:                        final StrutsForward forward = (StrutsForward) transitions
791:                                .get(i);
792:                        // only return those parameters that belong to both this action and the argument final state
793:                        if (finalState.equals(forward.getTarget())) {
794:                            final List forwardParameters = forward
795:                                    .getForwardParameters();
796:                            for (int j = 0; j < forwardParameters.size(); j++) {
797:                                final ModelElementFacade parameter = (ModelElementFacade) forwardParameters
798:                                        .get(j);
799:                                parameterMap
800:                                        .put(parameter.getName(), parameter);
801:                            }
802:                        }
803:                    }
804:                    parameters = new ArrayList(parameterMap.values());
805:                }
806:
807:                return parameters;
808:            }
809:
810:            /**
811:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction#getTargetPages()
812:             */
813:            protected List handleGetTargetPages() {
814:                Collection targetPages = new LinkedHashSet();
815:
816:                Collection forwards = getActionForwards();
817:                for (final Iterator forwardIterator = forwards.iterator(); forwardIterator
818:                        .hasNext();) {
819:                    StrutsForward forward = (StrutsForward) forwardIterator
820:                            .next();
821:                    if (forward.isEnteringPage()) {
822:                        targetPages.add(forward.getTarget());
823:                    }
824:                }
825:
826:                return new ArrayList(targetPages);
827:            }
828:
829:            /**
830:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsActionLogic#getTransitions()
831:             */
832:            protected List handleGetTransitions() {
833:                if (transitions == null) {
834:                    initializeCollections();
835:                }
836:                return new ArrayList(transitions);
837:            }
838:
839:            /**
840:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction#getStyleId()
841:             */
842:            protected String handleGetStyleId() {
843:                String styleId = null;
844:
845:                StrutsTrigger trigger = getActionTrigger();
846:                if (trigger != null) {
847:                    String triggerName = trigger.getName();
848:                    styleId = StringUtilsHelper.lowerCamelCaseName(triggerName);
849:                }
850:                return styleId;
851:            }
852:
853:            /**
854:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction#isRedirect()
855:             */
856:            protected boolean handleIsRedirect() {
857:                String redirect = (String) this 
858:                        .getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_DEFAULT_ACTION_REDIRECT);
859:                Object value = this 
860:                        .findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_ACTION_REDIRECT);
861:                if (value != null) {
862:                    redirect = (String) value;
863:                }
864:                return Boolean.valueOf(StringUtils.trimToEmpty(redirect))
865:                        .booleanValue();
866:            }
867:
868:            /**
869:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction#getResettableActionParameters()
870:             */
871:            protected List handleGetResettableActionParameters() {
872:                return new ArrayList(new FilteredCollection(this 
873:                        .getActionParameters()) {
874:                    public boolean evaluate(Object object) {
875:                        return object != null
876:                                && ((StrutsParameter) object).isShouldReset();
877:                    }
878:                });
879:            }
880:
881:            /**
882:             * The "session" action form scope.
883:             */
884:            private static final String FORM_SCOPE_SESSION = "session";
885:
886:            /**
887:             * The "request" action form scope.
888:             */
889:            private static final String FORM_SCOPE_REQUEST = "request";
890:
891:            /**
892:             * The "none" action form scope.
893:             */
894:            private static final String FORM_SCOPE_NONE = "none";
895:
896:            /**
897:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction#getFormScope()
898:             */
899:            protected String handleGetFormScope() {
900:                String actionFormScope = String
901:                        .valueOf(this 
902:                                .getConfiguredProperty(Bpm4StrutsGlobals.PROPERTY_ACTION_FORM_SCOPE));
903:                Object value = this 
904:                        .findTaggedValue(Bpm4StrutsProfile.TAGGEDVALUE_ACTION_FORM_SCOPE);
905:                if (value != null) {
906:                    actionFormScope = String.valueOf(value);
907:                }
908:                return StringUtils.trimToEmpty(actionFormScope);
909:            }
910:
911:            /**
912:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction#isFormScopeSession()
913:             */
914:            protected boolean handleIsFormScopeSession() {
915:                return this .getFormScope().equalsIgnoreCase(FORM_SCOPE_SESSION);
916:            }
917:
918:            /**
919:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction#isFormScopeRequest()
920:             */
921:            protected boolean handleIsFormScopeRequest() {
922:                return this .getFormScope().equalsIgnoreCase(FORM_SCOPE_REQUEST);
923:            }
924:
925:            /**
926:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsAction#isFormScopeNone()
927:             */
928:            protected boolean handleIsFormScopeNone() {
929:                return this .getFormScope().equalsIgnoreCase(FORM_SCOPE_NONE);
930:            }
931:
932:            /**
933:             * @see org.andromda.cartridges.bpm4struts.metafacades.StrutsActionLogic#handleGetHiddenActionParameters()
934:             */
935:            protected List handleGetHiddenActionParameters() {
936:                final List hiddenActionParameters = new ArrayList(this 
937:                        .getActionParameters());
938:                CollectionUtils.filter(hiddenActionParameters, new Predicate() {
939:                    public boolean evaluate(final Object object) {
940:                        return StrutsParameterLogicImpl.HIDDEN_INPUT_TYPE
941:                                .equals(((StrutsParameter) object)
942:                                        .getWidgetType());
943:                    }
944:                });
945:                return hiddenActionParameters;
946:            }
947:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.