Source Code Cross Referenced for JSFParameterLogicImpl.java in  » UML » AndroMDA-3.2 » org » andromda » cartridges » jsf » 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.jsf.metafacades 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.andromda.cartridges.jsf.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:        import java.util.Set;
013:
014:        import org.andromda.cartridges.jsf.JSFGlobals;
015:        import org.andromda.cartridges.jsf.JSFProfile;
016:        import org.andromda.cartridges.jsf.JSFUtils;
017:        import org.andromda.metafacades.uml.ClassifierFacade;
018:        import org.andromda.metafacades.uml.FrontEndActivityGraph;
019:        import org.andromda.metafacades.uml.FrontEndView;
020:        import org.andromda.metafacades.uml.ModelElementFacade;
021:        import org.andromda.metafacades.uml.TransitionFacade;
022:        import org.andromda.metafacades.uml.UseCaseFacade;
023:        import org.andromda.utils.StringUtilsHelper;
024:        import org.apache.commons.lang.ObjectUtils;
025:        import org.apache.commons.lang.StringUtils;
026:
027:        /**
028:         * MetafacadeLogic implementation for org.andromda.cartridges.jsf.metafacades.JSFParameter.
029:         *
030:         * @see org.andromda.cartridges.jsf.metafacades.JSFParameter
031:         */
032:        public class JSFParameterLogicImpl extends JSFParameterLogic {
033:            public JSFParameterLogicImpl(Object metaObject, String context) {
034:                super (metaObject, context);
035:            }
036:
037:            /**
038:             * Overrridden to make sure its not an inputTable.
039:             *
040:             * @see org.andromda.metafacades.uml.FrontEndParameter#isTable()
041:             */
042:            public boolean isTable() {
043:                return super .isTable() && !this .isInputTable();
044:            }
045:
046:            /**
047:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getMessageKey()
048:             */
049:            protected java.lang.String handleGetMessageKey() {
050:                final StringBuffer messageKey = new StringBuffer();
051:
052:                if (!this .isNormalizeMessages()) {
053:                    if (this .isActionParameter()) {
054:                        final JSFAction action = (JSFAction) this .getAction();
055:                        if (action != null) {
056:                            messageKey.append(action.getMessageKey());
057:                            messageKey.append('.');
058:                        }
059:                    } else {
060:                        final JSFView view = (JSFView) this .getView();
061:                        if (view != null) {
062:                            messageKey.append(view.getMessageKey());
063:                            messageKey.append('.');
064:                        }
065:                    }
066:                    messageKey.append("param.");
067:                }
068:
069:                messageKey.append(StringUtilsHelper.toResourceMessageKey(super 
070:                        .getName()));
071:                return messageKey.toString();
072:            }
073:
074:            /**
075:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getDocumentationKey()
076:             */
077:            protected String handleGetDocumentationKey() {
078:                return getMessageKey() + '.'
079:                        + JSFGlobals.DOCUMENTATION_MESSAGE_KEY_SUFFIX;
080:            }
081:
082:            /**
083:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getDocumentationValue(()
084:             */
085:            protected String handleGetDocumentationValue() {
086:                final String value = StringUtilsHelper.toResourceMessage(this 
087:                        .getDocumentation("", 64, false));
088:                return value == null ? "" : value;
089:            }
090:
091:            /**
092:             * Overridden to provide quotes around string types.
093:             *
094:             * @see org.andromda.metafacades.uml.ParameterFacade#getDefaultValue()
095:             */
096:            public String getDefaultValue() {
097:                String defaultValue = super .getDefaultValue();
098:                if (StringUtils.isNotBlank(defaultValue)) {
099:                    final ClassifierFacade type = this .getType();
100:                    if (type != null && type.isStringType()) {
101:                        defaultValue = "\"" + defaultValue + "\"";
102:                    }
103:                }
104:                return defaultValue;
105:            }
106:
107:            /**
108:             * Indicates whether or not we should normalize messages.
109:             *
110:             * @return true/false
111:             */
112:            private final boolean isNormalizeMessages() {
113:                final String normalizeMessages = (String) getConfiguredProperty(JSFGlobals.NORMALIZE_MESSAGES);
114:                return Boolean.valueOf(normalizeMessages).booleanValue();
115:            }
116:
117:            /**
118:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getMessageValue()
119:             */
120:            protected java.lang.String handleGetMessageValue() {
121:                return StringUtilsHelper.toPhrase(super .getName()); // the actual name is used for displaying
122:            }
123:
124:            /**
125:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getTableColumnMessageKey(String)
126:             */
127:            protected String handleGetTableColumnMessageKey(
128:                    final String columnName) {
129:                StringBuffer messageKey = new StringBuffer();
130:                if (!this .isNormalizeMessages()) {
131:                    final JSFView view = (JSFView) this .getView();
132:                    if (view != null) {
133:                        messageKey.append(this .getMessageKey());
134:                        messageKey.append('.');
135:                    }
136:                }
137:                messageKey.append(StringUtilsHelper
138:                        .toResourceMessageKey(columnName));
139:                return messageKey.toString();
140:            }
141:
142:            /**
143:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getTableColumnMessageValue(String)
144:             */
145:            protected String handleGetTableColumnMessageValue(
146:                    final String columnName) {
147:                return StringUtilsHelper.toPhrase(columnName);
148:            }
149:
150:            /**
151:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getTableHyperlinkActions()
152:             */
153:            protected List handleGetTableHyperlinkActions() {
154:                return this .getTableActions(true);
155:            }
156:
157:            /**
158:             * If this is a table this method returns all those actions that are declared to work
159:             * on this table.
160:             *
161:             * @param hyperlink denotes on which type of actions to filter
162:             */
163:            private final List getTableActions(boolean hyperlink) {
164:                final Set actions = new LinkedHashSet();
165:                final String name = StringUtils.trimToNull(getName());
166:                if (name != null && isTable()) {
167:                    final JSFView view = (JSFView) this .getView();
168:
169:                    final Collection allUseCases = getModel().getAllUseCases();
170:                    for (final Iterator useCaseIterator = allUseCases
171:                            .iterator(); useCaseIterator.hasNext();) {
172:                        final UseCaseFacade useCase = (UseCaseFacade) useCaseIterator
173:                                .next();
174:                        if (useCase instanceof  JSFUseCase) {
175:                            final FrontEndActivityGraph graph = ((JSFUseCase) useCase)
176:                                    .getActivityGraph();
177:                            if (graph != null) {
178:                                final Collection transitions = graph
179:                                        .getTransitions();
180:                                for (final Iterator transitionIterator = transitions
181:                                        .iterator(); transitionIterator
182:                                        .hasNext();) {
183:                                    final TransitionFacade transition = (TransitionFacade) transitionIterator
184:                                            .next();
185:                                    if (transition.getSource().equals(view)
186:                                            && transition instanceof  JSFAction) {
187:                                        final JSFAction action = (JSFAction) transition;
188:                                        if (action.isTableLink()
189:                                                && name.equals(action
190:                                                        .getTableLinkName())) {
191:                                            if (hyperlink == action
192:                                                    .isHyperlink()) {
193:                                                actions.add(action);
194:                                            }
195:                                        }
196:                                    }
197:                                }
198:                            }
199:                        }
200:                    }
201:                }
202:                return new ArrayList(actions);
203:            }
204:
205:            /**
206:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getTableFormActions()
207:             */
208:            protected List handleGetTableFormActions() {
209:                return this .getTableActions(false);
210:            }
211:
212:            /**
213:             * @see org.andromda.metafacades.uml.FrontEndParameter#getTableColumns()
214:             */
215:            public Collection getTableColumns() {
216:                final Collection tableColumns = super .getTableColumns();
217:                if (tableColumns.isEmpty()) {
218:                    // try to preserve the order of the elements encountered
219:                    final Map tableColumnsMap = new LinkedHashMap();
220:
221:                    // order is important
222:                    final List actions = new ArrayList();
223:
224:                    // all table actions need the exact same parameters, just not always all of them
225:                    actions.addAll(this .getTableFormActions());
226:
227:                    // if there are any actions that are hyperlinks then their parameters get priority
228:                    // the user should not have modeled it that way (constraints will warn him/her)
229:                    actions.addAll(this .getTableHyperlinkActions());
230:
231:                    for (final Iterator actionIterator = actions.iterator(); actionIterator
232:                            .hasNext();) {
233:                        final JSFAction action = (JSFAction) actionIterator
234:                                .next();
235:                        final Collection actionParameters = action
236:                                .getParameters();
237:                        for (final Iterator parameterIterator = actionParameters
238:                                .iterator(); parameterIterator.hasNext();) {
239:                            final Object object = parameterIterator.next();
240:                            if (object instanceof  JSFParameter) {
241:                                final JSFParameter parameter = (JSFParameter) object;
242:                                final String parameterName = parameter
243:                                        .getName();
244:                                if (parameterName != null) {
245:                                    // never overwrite column specific table links
246:                                    // the hyperlink table links working on a real column get priority
247:                                    final Object existingObject = tableColumnsMap
248:                                            .get(parameterName);
249:                                    if (existingObject instanceof  JSFParameter) {
250:                                        final JSFParameter existingParameter = (JSFParameter) existingObject;
251:                                        if (existingParameter == null
252:                                                || (action.isHyperlink() && parameterName
253:                                                        .equals(action
254:                                                                .getTableLinkColumnName()))) {
255:                                            tableColumnsMap.put(parameterName,
256:                                                    parameter);
257:                                        }
258:                                    }
259:                                }
260:                            }
261:                        }
262:                    }
263:
264:                    // for any missing parameters we just add the name of the column
265:                    final Collection columnNames = this .getTableColumnNames();
266:                    for (final Iterator columnNameIterator = columnNames
267:                            .iterator(); columnNameIterator.hasNext();) {
268:                        final String columnName = (String) columnNameIterator
269:                                .next();
270:                        if (!tableColumnsMap.containsKey(columnName)) {
271:                            tableColumnsMap.put(columnName, columnName);
272:                        }
273:                    }
274:
275:                    // return everything in the same order as it has been modeled (using the table tagged value)
276:                    for (final Iterator columnNameIterator = columnNames
277:                            .iterator(); columnNameIterator.hasNext();) {
278:                        final Object columnObject = columnNameIterator.next();
279:                        tableColumns.add(tableColumnsMap.get(columnObject));
280:                    }
281:                }
282:                return tableColumns;
283:            }
284:
285:            /**
286:             * @return the default date format pattern as defined using the configured property
287:             */
288:            private String getDefaultDateFormat() {
289:                return (String) this 
290:                        .getConfiguredProperty(JSFGlobals.PROPERTY_DEFAULT_DATEFORMAT);
291:            }
292:
293:            /**
294:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getFormat()
295:             */
296:            protected String handleGetFormat() {
297:                return JSFUtils.getFormat((ModelElementFacade) this .THIS(),
298:                        this .getType(), this .getDefaultDateFormat(), this 
299:                                .getDefaultTimeFormat());
300:            }
301:
302:            /**
303:             * @return the default time format pattern as defined using the configured property
304:             */
305:            private String getDefaultTimeFormat() {
306:                return (String) this 
307:                        .getConfiguredProperty(JSFGlobals.PROPERTY_DEFAULT_TIMEFORMAT);
308:            }
309:
310:            /**
311:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isStrictDateFormat()
312:             */
313:            protected boolean handleIsStrictDateFormat() {
314:                return JSFUtils.isStrictDateFormat((ModelElementFacade) this 
315:                        .THIS());
316:            }
317:
318:            /**
319:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getDateFormatter()
320:             */
321:            protected String handleGetDateFormatter() {
322:                final ClassifierFacade type = this .getType();
323:                return type != null && type.isDateType() ? this .getName()
324:                        + "DateFormatter" : null;
325:            }
326:
327:            /**
328:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getTimeFormatter()
329:             */
330:            protected String handleGetTimeFormatter() {
331:                final ClassifierFacade type = this .getType();
332:                return type != null && type.isTimeType() ? this .getName()
333:                        + "TimeFormatter" : null;
334:            }
335:
336:            /**
337:             * Gets the current value of the specified input type (or an empty string
338:             * if one isn't specified).
339:             *
340:             * @return the input type name.
341:             */
342:            private final String getInputType() {
343:                return ObjectUtils
344:                        .toString(
345:                                this 
346:                                        .findTaggedValue(JSFProfile.TAGGEDVALUE_INPUT_TYPE))
347:                        .trim();
348:            }
349:
350:            /**
351:             * Indicates whether or not this parameter is of the given input type.
352:             *
353:             * @param inputType the name of the input type to check for.
354:             * @return true/false
355:             */
356:            private final boolean isInputType(final String inputType) {
357:                return inputType.equalsIgnoreCase(this .getInputType());
358:            }
359:
360:            /**
361:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isInputTextarea()
362:             */
363:            protected boolean handleIsInputTextarea() {
364:                return this .isInputType(JSFGlobals.INPUT_TEXTAREA);
365:            }
366:
367:            /**
368:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isInputSelect()
369:             */
370:            protected boolean handleIsInputSelect() {
371:                return this .isInputType(JSFGlobals.INPUT_SELECT);
372:            }
373:
374:            /**
375:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isInputSecret()
376:             */
377:            protected boolean handleIsInputSecret() {
378:                return this .isInputType(JSFGlobals.INPUT_PASSWORD);
379:            }
380:
381:            /**
382:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isInputHidden()
383:             */
384:            protected boolean handleIsInputHidden() {
385:                return this .isInputType(JSFGlobals.INPUT_HIDDEN);
386:            }
387:
388:            /**
389:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isPlaintext()
390:             */
391:            protected boolean handleIsPlaintext() {
392:                return this .isInputType(JSFGlobals.PLAIN_TEXT);
393:            }
394:
395:            /**
396:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isInputTable()
397:             */
398:            protected boolean handleIsInputTable() {
399:                return this .getInputTableIdentifierColumns().length() > 0
400:                        || this .isInputType(JSFGlobals.INPUT_TABLE);
401:            }
402:
403:            /**
404:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isInputRadio()
405:             */
406:            protected boolean handleIsInputRadio() {
407:                return this .isInputType(JSFGlobals.INPUT_RADIO);
408:            }
409:
410:            /**
411:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isInputText()
412:             */
413:            protected boolean handleIsInputText() {
414:                return this .isInputType(JSFGlobals.INPUT_TEXT);
415:            }
416:
417:            /**
418:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isInputMultibox()
419:             */
420:            protected boolean handleIsInputMultibox() {
421:                return this .isInputType(JSFGlobals.INPUT_MULTIBOX);
422:            }
423:
424:            /**
425:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isInputCheckbox()
426:             */
427:            protected boolean handleIsInputCheckbox() {
428:                boolean checkbox = this .isInputType(JSFGlobals.INPUT_CHECKBOX);
429:                if (!checkbox && this .getInputType().length() == 0) {
430:                    final ClassifierFacade type = this .getType();
431:                    checkbox = type != null ? type.isBooleanType() : false;
432:                }
433:                return checkbox;
434:            }
435:
436:            /**
437:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isInputFile()
438:             */
439:            protected boolean handleIsInputFile() {
440:                boolean file = false;
441:                ClassifierFacade type = getType();
442:                if (type != null) {
443:                    file = type.isFileType();
444:                }
445:                return file;
446:            }
447:
448:            /**
449:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getBackingListName()
450:             */
451:            protected String handleGetBackingListName() {
452:                return ObjectUtils
453:                        .toString(
454:                                this 
455:                                        .getConfiguredProperty(JSFGlobals.BACKING_LIST_PATTERN))
456:                        .replaceAll("\\{0\\}", this .getName());
457:            }
458:
459:            /**
460:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getBackingValueName()
461:             */
462:            protected String handleGetBackingValueName() {
463:                return ObjectUtils
464:                        .toString(
465:                                this 
466:                                        .getConfiguredProperty(JSFGlobals.BACKING_VALUE_PATTERN))
467:                        .replaceAll("\\{0\\}", this .getName());
468:            }
469:
470:            /**
471:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getValueListName()
472:             */
473:            protected String handleGetValueListName() {
474:                return ObjectUtils
475:                        .toString(
476:                                this 
477:                                        .getConfiguredProperty(JSFGlobals.VALUE_LIST_PATTERN))
478:                        .replaceAll("\\{0\\}", this .getName());
479:            }
480:
481:            /**
482:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getLabelListName()
483:             */
484:            protected String handleGetLabelListName() {
485:                return ObjectUtils
486:                        .toString(
487:                                this 
488:                                        .getConfiguredProperty(JSFGlobals.LABEL_LIST_PATTERN))
489:                        .replaceAll("\\{0\\}", this .getName());
490:            }
491:
492:            /**
493:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isSelectable()
494:             */
495:            protected boolean handleIsSelectable() {
496:                boolean selectable = false;
497:                if (this .isActionParameter()) {
498:                    selectable = this .isInputMultibox() || this .isInputSelect()
499:                            || this .isInputRadio();
500:                    final ClassifierFacade type = this .getType();
501:
502:                    if (!selectable && type != null) {
503:                        final String name = this .getName();
504:                        final String typeName = type.getFullyQualifiedName();
505:
506:                        // - if the parameter is not selectable but on a targetting page it IS selectable we must
507:                        //   allow the user to set the backing list too                 
508:                        final Collection views = this .getAction()
509:                                .getTargetViews();
510:                        for (final Iterator iterator = views.iterator(); iterator
511:                                .hasNext()
512:                                && !selectable;) {
513:                            final FrontEndView view = (FrontEndView) iterator
514:                                    .next();
515:                            final Collection parameters = view
516:                                    .getAllActionParameters();
517:                            for (final Iterator parameterIterator = parameters
518:                                    .iterator(); parameterIterator.hasNext()
519:                                    && !selectable;) {
520:                                final Object object = parameterIterator.next();
521:                                if (object instanceof  JSFParameter) {
522:                                    final JSFParameter parameter = (JSFParameter) object;
523:                                    final String parameterName = parameter
524:                                            .getName();
525:                                    final ClassifierFacade parameterType = parameter
526:                                            .getType();
527:                                    if (parameterType != null) {
528:                                        final String parameterTypeName = parameterType
529:                                                .getFullyQualifiedName();
530:                                        if (name.equals(parameterName)
531:                                                && typeName
532:                                                        .equals(parameterTypeName)) {
533:                                            selectable = parameter
534:                                                    .isInputMultibox()
535:                                                    || parameter
536:                                                            .isInputSelect()
537:                                                    || parameter.isInputRadio();
538:                                        }
539:                                    }
540:                                }
541:                            }
542:                        }
543:                    }
544:                } else if (this .isControllerOperationArgument()) {
545:                    final String name = this .getName();
546:                    final Collection actions = this .getControllerOperation()
547:                            .getDeferringActions();
548:                    for (final Iterator actionIterator = actions.iterator(); actionIterator
549:                            .hasNext();) {
550:                        final JSFAction action = (JSFAction) actionIterator
551:                                .next();
552:                        final Collection formFields = action.getFormFields();
553:                        for (final Iterator fieldIterator = formFields
554:                                .iterator(); fieldIterator.hasNext()
555:                                && !selectable;) {
556:                            final Object object = fieldIterator.next();
557:                            if (object instanceof  JSFParameter) {
558:                                final JSFParameter parameter = (JSFParameter) object;
559:                                if (!parameter.equals(this )) {
560:                                    if (name.equals(parameter.getName())) {
561:                                        selectable = parameter.isSelectable();
562:                                    }
563:                                }
564:                            }
565:                        }
566:                    }
567:                }
568:                return selectable;
569:            }
570:
571:            /**
572:             * Stores the initial value of each type.
573:             */
574:            private final Map initialValues = new HashMap();
575:
576:            /**
577:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getValueListDummyValue()
578:             */
579:            protected String handleGetValueListDummyValue() {
580:                return this .constructDummyArray();
581:            }
582:
583:            /**
584:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getDummyValue()
585:             */
586:            protected String handleGetDummyValue() {
587:                final ClassifierFacade type = this .getType();
588:                final String typeName = type != null ? type
589:                        .getFullyQualifiedName() : "";
590:                String initialValue = null;
591:                if (type != null) {
592:                    if (type.isSetType()) {
593:                        initialValue = "new java.util.LinkedHashSet(java.util.Arrays.asList("
594:                                + this .constructDummyArray() + "))";
595:                    } else if (type.isCollectionType()) {
596:                        initialValue = "java.util.Arrays.asList("
597:                                + this .constructDummyArray() + ")";
598:                    } else if (type.isArrayType()) {
599:                        initialValue = this .constructDummyArray();
600:                    }
601:                    final String name = this .getName() != null ? this .getName()
602:                            : "";
603:                    if (this .initialValues.isEmpty()) {
604:                        initialValues.put(boolean.class.getName(), "false");
605:                        initialValues.put(int.class.getName(), "(int)"
606:                                + name.hashCode());
607:                        initialValues.put(long.class.getName(), "(long)"
608:                                + name.hashCode());
609:                        initialValues.put(short.class.getName(), "(short)"
610:                                + name.hashCode());
611:                        initialValues.put(byte.class.getName(), "(byte)"
612:                                + name.hashCode());
613:                        initialValues.put(float.class.getName(), "(float)"
614:                                + name.hashCode());
615:                        initialValues.put(double.class.getName(), "(double)"
616:                                + name.hashCode());
617:                        initialValues.put(char.class.getName(), "(char)"
618:                                + name.hashCode());
619:
620:                        initialValues.put(String.class.getName(), "\"" + name
621:                                + "-test" + "\"");
622:                        initialValues.put(java.util.Date.class.getName(),
623:                                "new java.util.Date()");
624:                        initialValues.put(java.sql.Date.class.getName(),
625:                                "new java.util.Date()");
626:                        initialValues.put(java.sql.Timestamp.class.getName(),
627:                                "new java.util.Date()");
628:
629:                        initialValues.put(Integer.class.getName(),
630:                                "new Integer((int)" + name.hashCode() + ")");
631:                        initialValues.put(Boolean.class.getName(),
632:                                "Boolean.FALSE");
633:                        initialValues.put(Long.class.getName(),
634:                                "new Long((long)" + name.hashCode() + ")");
635:                        initialValues.put(Character.class.getName(),
636:                                "new Character(char)" + name.hashCode() + ")");
637:                        initialValues.put(Float.class.getName(),
638:                                "new Float((float)" + name.hashCode()
639:                                        / hashCode() + ")");
640:                        initialValues.put(Double.class.getName(),
641:                                "new Double((double)" + name.hashCode()
642:                                        / hashCode() + ")");
643:                        initialValues.put(Short.class.getName(),
644:                                "new Short((short)" + name.hashCode() + ")");
645:                        initialValues.put(Byte.class.getName(),
646:                                "new Byte((byte)" + name.hashCode() + ")");
647:                    }
648:                    if (initialValue == null) {
649:                        initialValue = (String) this .initialValues
650:                                .get(typeName);
651:                    }
652:                }
653:                if (initialValue == null) {
654:                    initialValue = "null";
655:                }
656:                return initialValue;
657:            }
658:
659:            /**
660:             * Constructs a string representing an array initialization in Java.
661:             *
662:             * @return A String representing Java code for the initialization of an array.
663:             */
664:            private final String constructDummyArray() {
665:                return JSFUtils.constructDummyArrayDeclaration(this .getName(),
666:                        JSFGlobals.DUMMY_ARRAY_COUNT);
667:            }
668:
669:            /**
670:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getTableSortColumnProperty()
671:             */
672:            protected String handleGetTableSortColumnProperty() {
673:                return this .getName() + "SortColumn";
674:            }
675:
676:            /**
677:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getTableSortAscendingProperty()
678:             */
679:            protected String handleGetTableSortAscendingProperty() {
680:                return this .getName() + "SortAscending";
681:            }
682:
683:            /**
684:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getFormAttributeSetProperty()
685:             */
686:            protected String handleGetFormAttributeSetProperty() {
687:                return this .getName() + "Set";
688:            }
689:
690:            /**
691:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isValidationRequired()
692:             */
693:            protected boolean handleIsValidationRequired() {
694:                boolean required = !this .getValidatorTypes().isEmpty();
695:                if (!required) {
696:                    // - look for any attributes
697:                    for (final Iterator iterator = this .getAttributes()
698:                            .iterator(); iterator.hasNext();) {
699:                        final JSFAttribute attribute = (JSFAttribute) iterator
700:                                .next();
701:                        required = !attribute.getValidatorTypes().isEmpty();
702:                        if (required) {
703:                            break;
704:                        }
705:                    }
706:
707:                    // - look for any table columns
708:                    if (!required) {
709:                        for (final Iterator iterator = this .getTableColumns()
710:                                .iterator(); iterator.hasNext();) {
711:                            final Object object = iterator.next();
712:                            if (object instanceof  JSFAttribute) {
713:                                final JSFAttribute attribute = (JSFAttribute) object;
714:                                required = !attribute.getValidatorTypes()
715:                                        .isEmpty();
716:                                if (required) {
717:                                    break;
718:                                }
719:                            }
720:                        }
721:                    }
722:                }
723:                return required;
724:            }
725:
726:            /**
727:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getValidatorTypes()
728:             */
729:            protected java.util.Collection handleGetValidatorTypes() {
730:                return JSFUtils.getValidatorTypes((ModelElementFacade) this 
731:                        .THIS(), this .getType());
732:            }
733:
734:            /**
735:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getValidWhen()
736:             */
737:            protected java.lang.String handleGetValidWhen() {
738:                return JSFUtils.getValidWhen(this );
739:            }
740:
741:            /**
742:             * Overridden to have the same behavior as bpm4struts.
743:             *
744:             * @see org.andromda.metafacades.uml.ParameterFacade#isRequired()
745:             */
746:            public boolean isRequired() {
747:                final Object value = this 
748:                        .findTaggedValue(JSFProfile.TAGGEDVALUE_INPUT_REQUIRED);
749:                return Boolean.valueOf(ObjectUtils.toString(value))
750:                        .booleanValue();
751:            }
752:
753:            /**
754:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isReadOnly()
755:             */
756:            protected boolean handleIsReadOnly() {
757:                return JSFUtils.isReadOnly(this );
758:            }
759:
760:            /**
761:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getValidatorArgs(java.lang.String)
762:             */
763:            protected java.util.Collection handleGetValidatorArgs(
764:                    final java.lang.String validatorType) {
765:                return JSFUtils.getValidatorArgs((ModelElementFacade) this 
766:                        .THIS(), validatorType);
767:            }
768:
769:            /**
770:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getValidatorVars()
771:             */
772:            protected java.util.Collection handleGetValidatorVars() {
773:                return JSFUtils.getValidatorVars(((ModelElementFacade) this 
774:                        .THIS()), this .getType());
775:            }
776:
777:            /**
778:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isReset()
779:             */
780:            protected boolean handleIsReset() {
781:                boolean reset = Boolean
782:                        .valueOf(
783:                                ObjectUtils
784:                                        .toString(this 
785:                                                .findTaggedValue(JSFProfile.TAGGEDVALUE_INPUT_RESET)))
786:                        .booleanValue();
787:                if (!reset) {
788:                    final JSFAction action = (JSFAction) this .getAction();
789:                    reset = action != null && action.isFormReset();
790:                }
791:                return reset;
792:            }
793:
794:            /**
795:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isComplex()
796:             */
797:            protected boolean handleIsComplex() {
798:                boolean complex = false;
799:                final ClassifierFacade type = this .getType();
800:                if (type != null) {
801:                    complex = !type.getAttributes().isEmpty();
802:                    if (!complex) {
803:                        complex = !type.getAssociationEnds().isEmpty();
804:                    }
805:                }
806:                return complex;
807:            }
808:
809:            /**
810:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getAttributes()
811:             */
812:            protected Collection handleGetAttributes() {
813:                Collection attributes = null;
814:                final ClassifierFacade type = this .getType();
815:                if (type != null) {
816:                    attributes = type.getAttributes(true);
817:                }
818:                return attributes == null ? Collections.EMPTY_LIST : attributes;
819:            }
820:
821:            /**
822:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getNavigableAssociationEnds()
823:             */
824:            protected Collection handleGetNavigableAssociationEnds() {
825:                Collection associationEnds = null;
826:                final ClassifierFacade type = this .getType();
827:                if (type != null) {
828:                    associationEnds = type.getNavigableConnectingEnds();
829:                }
830:                return associationEnds == null ? Collections.EMPTY_LIST
831:                        : associationEnds;
832:            }
833:
834:            /**
835:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isEqualValidator()
836:             */
837:            protected boolean handleIsEqualValidator() {
838:                final String equal = JSFUtils
839:                        .getEqual((ModelElementFacade) this .THIS());
840:                return equal != null && equal.trim().length() > 0;
841:            }
842:
843:            /**
844:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#isEqualValidator()
845:             */
846:            protected boolean handleIsBackingValueRequired() {
847:                boolean required = false;
848:                if (this .isActionParameter()) {
849:                    required = this .isInputTable();
850:                    final ClassifierFacade type = this .getType();
851:
852:                    if (!required && type != null) {
853:                        final String name = this .getName();
854:                        final String typeName = type.getFullyQualifiedName();
855:
856:                        // - if the backing value is not required for this parameter but on 
857:                        //   a targetting page it IS selectable we must allow the user to set the backing value as well                 
858:                        final Collection views = this .getAction()
859:                                .getTargetViews();
860:                        for (final Iterator iterator = views.iterator(); iterator
861:                                .hasNext()
862:                                && !required;) {
863:                            final FrontEndView view = (FrontEndView) iterator
864:                                    .next();
865:                            final Collection parameters = view
866:                                    .getAllActionParameters();
867:                            for (final Iterator parameterIterator = parameters
868:                                    .iterator(); parameterIterator.hasNext()
869:                                    && !required;) {
870:                                final Object object = parameterIterator.next();
871:                                if (object instanceof  JSFParameter) {
872:                                    final JSFParameter parameter = (JSFParameter) object;
873:                                    final String parameterName = parameter
874:                                            .getName();
875:                                    final ClassifierFacade parameterType = parameter
876:                                            .getType();
877:                                    if (parameterType != null) {
878:                                        final String parameterTypeName = parameterType
879:                                                .getFullyQualifiedName();
880:                                        if (name.equals(parameterName)
881:                                                && typeName
882:                                                        .equals(parameterTypeName)) {
883:                                            required = parameter.isInputTable();
884:                                        }
885:                                    }
886:                                }
887:                            }
888:                        }
889:                    }
890:                } else if (this .isControllerOperationArgument()) {
891:                    final String name = this .getName();
892:                    final Collection actions = this .getControllerOperation()
893:                            .getDeferringActions();
894:                    for (final Iterator actionIterator = actions.iterator(); actionIterator
895:                            .hasNext();) {
896:                        final JSFAction action = (JSFAction) actionIterator
897:                                .next();
898:                        final Collection formFields = action.getFormFields();
899:                        for (final Iterator fieldIterator = formFields
900:                                .iterator(); fieldIterator.hasNext()
901:                                && !required;) {
902:                            final Object object = fieldIterator.next();
903:                            if (object instanceof  JSFParameter) {
904:                                final JSFParameter parameter = (JSFParameter) object;
905:                                if (!parameter.equals(this )) {
906:                                    if (name.equals(parameter.getName())) {
907:                                        required = parameter
908:                                                .isBackingValueRequired();
909:                                    }
910:                                }
911:                            }
912:                        }
913:                    }
914:                }
915:                return required;
916:            }
917:
918:            /**
919:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getInputTableIdentifierColumns()
920:             */
921:            protected String handleGetInputTableIdentifierColumns() {
922:                return ObjectUtils
923:                        .toString(
924:                                this 
925:                                        .findTaggedValue(JSFProfile.TAGGEDVALUE_INPUT_TABLE_IDENTIFIER_COLUMNS))
926:                        .trim();
927:            }
928:
929:            /**
930:             * @see org.andromda.cartridges.jsf.metafacades.JSFParameter#getTableColumnActions(java.lang.String)
931:             */
932:            protected List handleGetTableColumnActions(final String columnName) {
933:                final List columnActions = new ArrayList();
934:
935:                if (columnName != null) {
936:                    final Set actions = new LinkedHashSet(this 
937:                            .getTableHyperlinkActions());
938:                    actions.addAll(this .getTableFormActions());
939:                    for (final Iterator iterator = actions.iterator(); iterator
940:                            .hasNext();) {
941:                        final JSFAction action = (JSFAction) iterator.next();
942:                        if (columnName.equals(action.getTableLinkColumnName())) {
943:                            columnActions.add(action);
944:                        }
945:                    }
946:                }
947:
948:                return columnActions;
949:            }
950:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.