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


001:        package org.andromda.metafacades.emf.uml2;
002:
003:        import org.andromda.core.metafacade.MetafacadeConstants;
004:        import org.andromda.core.metafacade.MetafacadeException;
005:        import org.andromda.metafacades.uml.AssociationEndFacade;
006:        import org.andromda.metafacades.uml.AttributeFacade;
007:        import org.andromda.metafacades.uml.ClassifierFacade;
008:        import org.andromda.metafacades.uml.DependencyFacade;
009:        import org.andromda.metafacades.uml.Entity;
010:        import org.andromda.metafacades.uml.EntityAssociationEnd;
011:        import org.andromda.metafacades.uml.EntityAttribute;
012:        import org.andromda.metafacades.uml.EntityMetafacadeUtils;
013:        import org.andromda.metafacades.uml.EntityQueryOperation;
014:        import org.andromda.metafacades.uml.FilteredCollection;
015:        import org.andromda.metafacades.uml.MetafacadeUtils;
016:        import org.andromda.metafacades.uml.ModelElementFacade;
017:        import org.andromda.metafacades.uml.NameMasker;
018:        import org.andromda.metafacades.uml.UMLMetafacadeProperties;
019:        import org.andromda.metafacades.uml.UMLProfile;
020:        import org.andromda.utils.StringUtilsHelper;
021:        import org.apache.commons.collections.Closure;
022:        import org.apache.commons.collections.CollectionUtils;
023:        import org.apache.commons.collections.Predicate;
024:        import org.apache.commons.collections.Transformer;
025:        import org.apache.commons.lang.ObjectUtils;
026:        import org.apache.commons.lang.StringUtils;
027:        import org.eclipse.uml2.Property;
028:        import org.eclipse.uml2.Stereotype;
029:        import org.eclipse.uml2.Type;
030:        import org.eclipse.uml2.VisibilityKind;
031:
032:        import java.util.ArrayList;
033:        import java.util.Collection;
034:        import java.util.Iterator;
035:        import java.util.LinkedHashSet;
036:        import java.util.List;
037:        import java.util.Set;
038:
039:        /**
040:         * MetafacadeLogic implementation for org.andromda.metafacades.uml.Entity.
041:         *
042:         * @see org.andromda.metafacades.uml.Entity
043:         */
044:        public class EntityLogicImpl extends EntityLogic {
045:            public EntityLogicImpl(final Object metaObject, final String context) {
046:                super (metaObject, context);
047:            }
048:
049:            /**
050:             * A collection of MOF ids for entities that have dynamic identifiers
051:             * present.
052:             */
053:            private static final Collection dynamicIdentifiersPresent = new ArrayList();
054:
055:            /**
056:             * @see org.andromda.core.metafacade.MetafacadeBase#initialize()
057:             */
058:            public void initialize() {
059:                super .initialize();
060:
061:                // if there are no identifiers on this entity, create and add one.
062:                // enumerations don't have identifiers since they are not entities
063:                if (!this .isIdentifiersPresent()
064:                        && this .isAllowDefaultIdentifiers()) {
065:                    this .createIdentifier();
066:                    dynamicIdentifiersPresent.add(this .getId());
067:                }
068:            }
069:
070:            /**
071:             * Overridden to provide name masking.
072:             *
073:             * @see org.andromda.metafacades.uml.ModelElementFacade#getName()
074:             */
075:            protected String handleGetName() {
076:                final String nameMask = String
077:                        .valueOf(this 
078:                                .getConfiguredProperty(UMLMetafacadeProperties.ENTITY_NAME_MASK));
079:                return NameMasker.mask(super .handleGetName(), nameMask);
080:            }
081:
082:            /**
083:             * @see org.andromda.metafacades.uml.Entity#getQueryOperations()
084:             */
085:            protected java.util.Collection handleGetQueryOperations() {
086:                return this .getQueryOperations(false);
087:            }
088:
089:            /**
090:             * @see org.andromda.metafacades.uml.Entity#getQueryOperations(boolean)
091:             */
092:            protected java.util.Collection handleGetQueryOperations(
093:                    final boolean follow) {
094:                final Collection queryOperations = new ArrayList(this 
095:                        .getOperations());
096:
097:                MetafacadeUtils.filterByType(queryOperations,
098:                        EntityQueryOperation.class);
099:                for (ClassifierFacade super Class = (ClassifierFacade) this 
100:                        .getGeneralization(); super Class != null && follow; super Class = (ClassifierFacade) super Class
101:                        .getGeneralization()) {
102:                    if (Entity.class.isAssignableFrom(super Class.getClass())) {
103:                        Entity entity = (Entity) super Class;
104:                        queryOperations.addAll(entity.getQueryOperations());
105:                    }
106:                }
107:                return queryOperations;
108:            }
109:
110:            /**
111:             * @see org.andromda.metafacades.uml.Entity#getIdentifiers()
112:             */
113:            protected java.util.Collection handleGetIdentifiers() {
114:                return this .getIdentifiers(true);
115:            }
116:
117:            /**
118:             * @see org.andromda.metafacades.uml.Entity#getIdentifiers(boolean)
119:             */
120:            protected java.util.Collection handleGetIdentifiers(
121:                    final boolean follow) {
122:                return EntityMetafacadeUtils.getIdentifiers(this , follow);
123:            }
124:
125:            /**
126:             * Creates an identifier from the default identifier properties specified
127:             * within a namespace.
128:             */
129:            private void createIdentifier() {
130:                // first check if the foreign identifier flag is set, and
131:                // let those taken precedence if so
132:                if (!this .checkForAndAddForeignIdentifiers()) {
133:                    this .createIdentifier(this .getDefaultIdentifier(), this 
134:                            .getDefaultIdentifierType(), this 
135:                            .getDefaultIdentifierVisibility());
136:                }
137:            }
138:
139:            /**
140:             * Creates a new identifier and adds it to the underlying meta model
141:             * classifier instance.
142:             *
143:             * @param name
144:             *            the name to give the identifier
145:             * @param type
146:             *            the type to give the identifier
147:             * @param visibility
148:             *            the visibility to give the identifier
149:             */
150:            private void createIdentifier(final String name, final String type,
151:                    final String visibility) {
152:                final org.eclipse.uml2.Class umlClass = (org.eclipse.uml2.Class) this .metaObject;
153:
154:                // if we auto-create entity identifiers it will only be on hierarchy roots,
155:                // problems would arise when calls to #checkForAndAddForeignIdentifiers()
156:                // navigate over associated entities, effectively initializing their facade instances:
157:                // this results in subclasses having an identifier generated before their ancestors
158:                // ideally the method mentioned above would not make use of facades but meta-classes only,
159:                // if one is to refactor it that way this comment may be removed together with the line of code under it
160:                //
161:                // notice how the next line of code does not make use of facades, this is done on purpose in order
162:                // to avoid using uninitialized facades
163:                //
164:                // (Wouter, Sept. 20 2006) also see other UML implementations
165:                if (!umlClass.getGeneralizations().isEmpty())
166:                    return;
167:
168:                if (umlClass.getAttribute(name) == null) {
169:                    // ((org.eclipse.uml2.Classifier)metaObject).getModel();
170:                    final Object modelElement = UmlUtilities
171:                            .findByFullyQualifiedName(
172:                                    umlClass.eResource().getResourceSet(),
173:                                    type,
174:                                    MetafacadeConstants.NAMESPACE_SCOPE_OPERATOR,
175:                                    true);
176:                    if (modelElement instanceof  Type) {
177:                        Type element = (Type) modelElement;
178:                        final Property property = umlClass
179:                                .createOwnedAttribute(name, element, 1, 1);
180:                        VisibilityKind kind = VisibilityKind.PUBLIC_LITERAL;
181:                        if (visibility.equalsIgnoreCase("package")) {
182:                            kind = VisibilityKind.PACKAGE_LITERAL;
183:                        }
184:                        if (visibility.equalsIgnoreCase("private")) {
185:                            kind = VisibilityKind.PRIVATE_LITERAL;
186:                        }
187:                        if (visibility.equalsIgnoreCase("protected")) {
188:                            kind = VisibilityKind.PROTECTED_LITERAL;
189:                        }
190:                        property.setVisibility(kind);
191:                        Stereotype stereotype = UmlUtilities
192:                                .findApplicableStereotype(property,
193:                                        UMLProfile.STEREOTYPE_IDENTIFIER);
194:                        if (stereotype == null) {
195:                            throw new MetafacadeException("Could not apply '"
196:                                    + UMLProfile.STEREOTYPE_IDENTIFIER
197:                                    + "' to " + property
198:                                    + ", the stereotype could not be found");
199:                        }
200:                        property.apply(stereotype);
201:                    }
202:                }
203:            }
204:
205:            /**
206:             * @see org.andromda.metafacades.uml.Entity#isIdentifiersPresent()
207:             */
208:            protected boolean handleIsIdentifiersPresent() {
209:                final Collection identifiers = this .getIdentifiers(true);
210:                return identifiers != null && !identifiers.isEmpty();
211:            }
212:
213:            /**
214:             * @see org.andromda.metafacades.uml.Entity#isDynamicIdentifiersPresent()
215:             */
216:            protected boolean handleIsDynamicIdentifiersPresent() {
217:                return dynamicIdentifiersPresent.contains(this .getId());
218:            }
219:
220:            /**
221:             * @see org.andromda.metafacades.uml.Entity#getTableName()
222:             */
223:            protected String handleGetTableName() {
224:                final String prefixProperty = UMLMetafacadeProperties.TABLE_NAME_PREFIX;
225:                final String tableNamePrefix = this 
226:                        .isConfiguredProperty(prefixProperty) ? ObjectUtils
227:                        .toString(this .getConfiguredProperty(prefixProperty))
228:                        : null;
229:                return EntityMetafacadeUtils
230:                        .getSqlNameFromTaggedValue(
231:                                tableNamePrefix,
232:                                this ,
233:                                UMLProfile.TAGGEDVALUE_PERSISTENCE_TABLE,
234:                                this .getMaxSqlNameLength(),
235:                                this 
236:                                        .getConfiguredProperty(UMLMetafacadeProperties.SQL_NAME_SEPARATOR));
237:            }
238:
239:            /**
240:             * @see org.andromda.metafacades.uml.Entity#getOperationCallFromAttributes(boolean)
241:             */
242:            protected String handleGetOperationCallFromAttributes(
243:                    final boolean withIdentifiers) {
244:                return this .getOperationCallFromAttributes(withIdentifiers,
245:                        false);
246:            }
247:
248:            /**
249:             * @see org.andromda.metafacades.uml.Entity#getOperationCallFromAttributes(boolean,
250:             *      boolean)
251:             */
252:            protected String handleGetOperationCallFromAttributes(
253:                    final boolean withIdentifiers, final boolean follow) {
254:                final StringBuffer buffer = new StringBuffer();
255:                String separator = "";
256:                buffer.append("(");
257:
258:                final Set attributes = new LinkedHashSet(this .getAttributes());
259:
260:                for (ClassifierFacade super Class = (ClassifierFacade) this 
261:                        .getGeneralization(); super Class != null && follow; super Class = (ClassifierFacade) super Class
262:                        .getGeneralization()) {
263:                    if (super Class instanceof  Entity) {
264:                        final Entity entity = (Entity) super Class;
265:                        attributes.addAll(entity.getAttributes());
266:                    }
267:                }
268:
269:                if (!attributes.isEmpty()) {
270:                    for (final Iterator iterator = attributes.iterator(); iterator
271:                            .hasNext();) {
272:                        final EntityAttribute attribute = (EntityAttribute) iterator
273:                                .next();
274:                        if (withIdentifiers || !attribute.isIdentifier()) {
275:                            buffer.append(separator);
276:                            if (attribute.getType() != null) {
277:                                buffer.append(attribute.getType()
278:                                        .getFullyQualifiedName());
279:                            }
280:                            buffer.append(" ");
281:                            buffer.append(attribute.getName());
282:                            separator = ", ";
283:                        }
284:                    }
285:                }
286:                buffer.append(")");
287:                return buffer.toString();
288:            }
289:
290:            /**
291:             * @see org.andromda.metafacades.uml.Entity#getAttributeTypeList(boolean,
292:             *      boolean)
293:             */
294:            protected String handleGetAttributeTypeList(final boolean follow,
295:                    final boolean withIdentifiers) {
296:                return this .getTypeList(this .getAttributes(follow,
297:                        withIdentifiers));
298:            }
299:
300:            /**
301:             * @see org.andromda.metafacades.uml.Entity#getAttributeNameList(boolean,
302:             *      boolean)
303:             */
304:            protected String handleGetAttributeNameList(final boolean follow,
305:                    final boolean withIdentifiers) {
306:                return this .getNameList(this .getAttributes(follow,
307:                        withIdentifiers));
308:            }
309:
310:            /**
311:             * @see org.andromda.metafacades.uml.Entity#getRequiredAttributeTypeList(boolean,
312:             *      boolean)
313:             */
314:            protected String handleGetRequiredAttributeTypeList(
315:                    final boolean follow, final boolean withIdentifiers) {
316:                return this .getTypeList(this .getRequiredAttributes(follow,
317:                        withIdentifiers));
318:            }
319:
320:            /**
321:             * @see org.andromda.metafacades.uml.Entity#getRequiredAttributeNameList(boolean,
322:             *      boolean)
323:             */
324:            protected String handleGetRequiredAttributeNameList(
325:                    final boolean follow, final boolean withIdentifiers) {
326:                return this .getNameList(this .getRequiredAttributes(follow,
327:                        withIdentifiers));
328:            }
329:
330:            /**
331:             * @see org.andromda.metafacades.uml.Entity#getRequiredPropertyTypeList(boolean,
332:             *      boolean)
333:             */
334:            protected String handleGetRequiredPropertyTypeList(
335:                    final boolean follow, final boolean withIdentifiers) {
336:                return this .getTypeList(this .getRequiredProperties(follow,
337:                        withIdentifiers));
338:            }
339:
340:            /**
341:             * @see org.andromda.metafacades.uml.Entity#getRequiredPropertyNameList(boolean,
342:             *      boolean)
343:             */
344:            protected String handleGetRequiredPropertyNameList(
345:                    final boolean follow, final boolean withIdentifiers) {
346:                return this .getNameList(this .getRequiredProperties(follow,
347:                        withIdentifiers));
348:            }
349:
350:            /**
351:             * Constructs a comma seperated list of attribute type names from the passed
352:             * in collection of <code>attributes</code>.
353:             *
354:             * @param attributes
355:             *            the attributes to construct the list from.
356:             * @return the comma seperated list of attribute types.
357:             */
358:            private String getTypeList(final Collection attributes) {
359:                final StringBuffer list = new StringBuffer();
360:                final String comma = ", ";
361:                CollectionUtils.forAllDo(attributes, new Closure() {
362:                    public void execute(final Object object) {
363:                        if (object instanceof  AttributeFacade) {
364:                            final AttributeFacade attribute = (AttributeFacade) object;
365:                            if (attribute.getType() != null) {
366:                                list.append(attribute.getType()
367:                                        .getFullyQualifiedName());
368:                                list.append(comma);
369:                            }
370:                        }
371:                        if (object instanceof  AssociationEndFacade) {
372:                            final AssociationEndFacade associationEnd = (AssociationEndFacade) object;
373:                            if (associationEnd.getType() != null) {
374:                                list.append(associationEnd.getType()
375:                                        .getFullyQualifiedName());
376:                                list.append(comma);
377:                            }
378:                        }
379:                    }
380:                });
381:                if (list.toString().endsWith(comma)) {
382:                    list.delete(list.lastIndexOf(comma), list.length());
383:                }
384:                return list.toString();
385:            }
386:
387:            /**
388:             * Constructs a comma seperated list of attribute names from the passed in
389:             * collection of <code>attributes</code>.
390:             *
391:             * @param properties
392:             *            the attributes to construct the list from.
393:             * @return the comma seperated list of attribute names.
394:             */
395:            private String getNameList(final Collection properties) {
396:                final StringBuffer list = new StringBuffer();
397:                final String comma = ", ";
398:                CollectionUtils.forAllDo(properties, new Closure() {
399:                    public void execute(final Object object) {
400:                        if (object instanceof  EntityAttribute) {
401:                            list.append(((AttributeFacade) object).getName());
402:                            list.append(comma);
403:                        }
404:                        if (object instanceof  EntityAssociationEnd) {
405:                            list.append(((AssociationEndFacade) object)
406:                                    .getName());
407:                            list.append(comma);
408:                        }
409:                    }
410:                });
411:                if (list.toString().endsWith(comma)) {
412:                    list.delete(list.lastIndexOf(comma), list.length());
413:                }
414:                return list.toString();
415:            }
416:
417:            /**
418:             * @see org.andromda.metafacades.uml.Entity#isChild()
419:             */
420:            protected boolean handleIsChild() {
421:                return CollectionUtils.find(this .getAssociationEnds(),
422:                        new Predicate() {
423:                            public boolean evaluate(final Object object) {
424:                                return ((AssociationEndFacade) object)
425:                                        .getOtherEnd().isComposition();
426:                            }
427:                        }) != null;
428:            }
429:
430:            /**
431:             * @see org.andromda.metafacades.uml.Entity#getParentEnd()
432:             */
433:            protected Object handleGetParentEnd() {
434:                Object parentEnd = null;
435:                final AssociationEndFacade end = (AssociationEndFacade) CollectionUtils
436:                        .find(this .getAssociationEnds(), new Predicate() {
437:                            public boolean evaluate(Object object) {
438:                                return ((AssociationEndFacade) object)
439:                                        .getOtherEnd().isComposition();
440:                            }
441:                        });
442:                if (end != null) {
443:                    parentEnd = end.getOtherEnd();
444:                }
445:                return parentEnd;
446:            }
447:
448:            /**
449:             * @see org.andromda.metafacades.uml.Entity#getChildEnds()
450:             */
451:            protected Collection handleGetChildEnds() {
452:                final Collection childEnds = new FilteredCollection(this 
453:                        .getAssociationEnds()) {
454:                    public boolean evaluate(Object object) {
455:                        return ((AssociationEndFacade) object).isComposition();
456:                    }
457:                };
458:                CollectionUtils.transform(childEnds, new Transformer() {
459:                    public Object transform(final Object object) {
460:                        return ((AssociationEndFacade) object).getOtherEnd();
461:                    }
462:                });
463:                return childEnds;
464:            }
465:
466:            /**
467:             * @see org.andromda.metafacades.uml.Entity#getBusinessOperations()
468:             */
469:            protected Collection handleGetBusinessOperations() {
470:                final Collection businessOperations = new ArrayList(this 
471:                        .getImplementationOperations());
472:                MetafacadeUtils.filterByNotType(businessOperations,
473:                        EntityQueryOperation.class);
474:                return businessOperations;
475:            }
476:
477:            /**
478:             * @see org.andromda.metafacades.uml.Entity#getEntityReferences()
479:             */
480:            protected Collection handleGetEntityReferences() {
481:                return new FilteredCollection(this .getSourceDependencies()) {
482:                    public boolean evaluate(final Object object) {
483:                        ModelElementFacade targetElement = ((DependencyFacade) object)
484:                                .getTargetElement();
485:                        return targetElement instanceof  Entity;
486:                    }
487:                };
488:            }
489:
490:            /**
491:             * @see org.andromda.metafacades.uml.Entity#getAttributes(boolean, boolean)
492:             */
493:            protected Collection handleGetAttributes(final boolean follow,
494:                    final boolean withIdentifiers) {
495:                final Collection attributes = this .getAttributes(follow);
496:                CollectionUtils.filter(attributes, new Predicate() {
497:                    public boolean evaluate(final Object object) {
498:                        boolean valid = true;
499:                        if (!withIdentifiers
500:                                && object instanceof  EntityAttribute) {
501:                            valid = !((EntityAttribute) object).isIdentifier();
502:                        }
503:                        return valid;
504:                    }
505:                });
506:                return attributes;
507:            }
508:
509:            /**
510:             * @see org.andromda.metafacades.uml.Entity#getProperties(boolean, boolean)
511:             */
512:            protected Collection handleGetProperties(final boolean follow,
513:                    final boolean withIdentifiers) {
514:                final Collection properties = this .getProperties(follow);
515:
516:                // only filter when we don't want identifiers
517:                if (!withIdentifiers) {
518:                    CollectionUtils.filter(properties, new Predicate() {
519:                        public boolean evaluate(final Object object) {
520:                            return !(object instanceof  EntityAttribute)
521:                                    || !((EntityAttribute) object)
522:                                            .isIdentifier();
523:                        }
524:                    });
525:                }
526:
527:                return properties;
528:            }
529:
530:            /**
531:             * @see org.andromda.metafacades.uml.Entity#getRequiredAttributes(boolean,
532:             *      boolean)
533:             */
534:            protected Collection handleGetRequiredAttributes(
535:                    final boolean follow, final boolean withIdentifiers) {
536:                final Collection attributes = this .getAttributes(follow,
537:                        withIdentifiers);
538:
539:                // only filter when we don't want identifiers
540:                if (!withIdentifiers) {
541:                    CollectionUtils.filter(attributes, new Predicate() {
542:                        public boolean evaluate(final Object object) {
543:                            final AttributeFacade attribute = (AttributeFacade) object;
544:                            return attribute.isRequired()
545:                                    && (!(object instanceof  EntityAttribute) || !((EntityAttribute) object)
546:                                            .isIdentifier());
547:                        }
548:                    });
549:                }
550:
551:                return attributes;
552:            }
553:
554:            /**
555:             * @see org.andromda.metafacades.uml.Entity#getRequiredProperties(boolean,
556:             *      boolean)
557:             */
558:            protected Collection handleGetRequiredProperties(
559:                    final boolean follow, final boolean withIdentifiers) {
560:                final Set properties = new LinkedHashSet(this .getProperties(
561:                        follow, withIdentifiers));
562:                CollectionUtils.filter(properties, new Predicate() {
563:                    public boolean evaluate(final Object object) {
564:                        boolean valid = false;
565:                        if (object instanceof  AttributeFacade) {
566:                            valid = ((AttributeFacade) object).isRequired();
567:                            if (valid && !withIdentifiers
568:                                    && object instanceof  EntityAttribute) {
569:                                valid = !((EntityAttribute) object)
570:                                        .isIdentifier();
571:                            }
572:                        } else if (object instanceof  AssociationEndFacade) {
573:                            valid = ((AssociationEndFacade) object)
574:                                    .isRequired();
575:                        }
576:                        return valid;
577:                    }
578:                });
579:
580:                List sortedProperties = new ArrayList(properties);
581:                MetafacadeUtils.sortByFullyQualifiedName(sortedProperties);
582:                return sortedProperties;
583:            }
584:
585:            /**
586:             * Gets the maximum name length SQL names may be
587:             */
588:            protected Short handleGetMaxSqlNameLength() {
589:                return Short
590:                        .valueOf((String) this 
591:                                .getConfiguredProperty(UMLMetafacadeProperties.MAX_SQL_NAME_LENGTH));
592:            }
593:
594:            /**
595:             * Returns true/false on whether or not default identifiers are allowed
596:             */
597:            private boolean isAllowDefaultIdentifiers() {
598:                return Boolean
599:                        .valueOf(
600:                                (String) this 
601:                                        .getConfiguredProperty(UMLMetafacadeProperties.ALLOW_DEFAULT_IDENTITIFIERS))
602:                        .booleanValue();
603:            }
604:
605:            /**
606:             * Gets the name of the default identifier.
607:             */
608:            private String getDefaultIdentifier() {
609:                return ObjectUtils
610:                        .toString(
611:                                this 
612:                                        .getConfiguredProperty(UMLMetafacadeProperties.DEFAULT_IDENTIFIER_PATTERN))
613:                        .replaceAll(
614:                                "\\{0\\}",
615:                                StringUtilsHelper.lowerCamelCaseName(this 
616:                                        .getName()));
617:            }
618:
619:            /**
620:             * Gets the name of the default identifier type.
621:             */
622:            private String getDefaultIdentifierType() {
623:                return (String) this 
624:                        .getConfiguredProperty(UMLMetafacadeProperties.DEFAULT_IDENTIFIER_TYPE);
625:            }
626:
627:            /**
628:             * Gets the default identifier visibility.
629:             */
630:            private String getDefaultIdentifierVisibility() {
631:                return (String) this 
632:                        .getConfiguredProperty(UMLMetafacadeProperties.DEFAULT_IDENTIFIER_VISIBILITY);
633:            }
634:
635:            /**
636:             * Checks to see if this entity has any associations where the foreign
637:             * identifier flag may be set, and if so creates and adds identifiers just
638:             * like the foreign entity to this entity.
639:             *
640:             * @return true if any identifiers were added, false otherwise
641:             */
642:            private boolean checkForAndAddForeignIdentifiers() {
643:                boolean identifiersAdded = false;
644:                final EntityAssociationEnd end = this .getForeignIdentifierEnd();
645:                if (end != null && end.getType() instanceof  Entity) {
646:                    final Entity foreignEntity = (Entity) end.getOtherEnd()
647:                            .getType();
648:                    final Collection identifiers = EntityMetafacadeUtils
649:                            .getIdentifiers(foreignEntity, true);
650:                    for (final Iterator iterator = identifiers.iterator(); iterator
651:                            .hasNext();) {
652:                        final AttributeFacade identifier = (AttributeFacade) iterator
653:                                .next();
654:                        this .createIdentifier(identifier.getName(), identifier
655:                                .getType().getFullyQualifiedName(true),
656:                                identifier.getVisibility());
657:                        identifiersAdded = true;
658:                    }
659:                }
660:                return identifiersAdded;
661:            }
662:
663:            /**
664:             * Override to filter out any association ends that point to model elements
665:             * other than other entities.
666:             *
667:             * @see org.andromda.metafacades.uml.ClassifierFacade#getAssociationEnds()
668:             */
669:            public List handleGetAssociationEnds() {
670:                final List associationEnds = (List) this .shieldedElements(super 
671:                        .handleGetAssociationEnds());
672:                CollectionUtils.filter(associationEnds, new Predicate() {
673:                    public boolean evaluate(final Object object) {
674:                        return ((AssociationEndFacade) object).getOtherEnd()
675:                                .getType() instanceof  Entity;
676:                    }
677:                });
678:                return associationEnds;
679:            }
680:
681:            /**
682:             * @see org.andromda.metafacades.emf.uml2.EntityLogic#handleIsUsingForeignIdentifier()
683:             */
684:            protected boolean handleIsUsingForeignIdentifier() {
685:                return this .getForeignIdentifierEnd() != null;
686:            }
687:
688:            /**
689:             * Gets the association end that is flagged as having the foreign identifier
690:             * set (or null if none is).
691:             */
692:            private EntityAssociationEnd getForeignIdentifierEnd() {
693:                return (EntityAssociationEnd) CollectionUtils.find(this 
694:                        .getAssociationEnds(), new Predicate() {
695:                    public boolean evaluate(final Object object) {
696:                        boolean valid = false;
697:                        if (object != null
698:                                && EntityAssociationEnd.class
699:                                        .isAssignableFrom(object.getClass())) {
700:                            EntityAssociationEnd end = (EntityAssociationEnd) object;
701:                            valid = end.isForeignIdentifier();
702:                        }
703:                        return valid;
704:                    }
705:                });
706:            }
707:
708:            /**
709:             * @see org.andromda.metafacades.uml.Entity#isUsingAssignedIdentifier()
710:             */
711:            protected boolean handleIsUsingAssignedIdentifier() {
712:                boolean assigned = false;
713:                final Collection identifiers = this .getIdentifiers();
714:                if (identifiers != null && !identifiers.isEmpty()) {
715:                    final Object id = identifiers.iterator().next();
716:                    AttributeFacade identifier = (AttributeFacade) id;
717:                    assigned = Boolean
718:                            .valueOf(
719:                                    ObjectUtils
720:                                            .toString(identifier
721:                                                    .findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_ASSIGNED_IDENTIFIER)))
722:                            .booleanValue();
723:                }
724:                return assigned;
725:            }
726:
727:            /**
728:             * @see org.andromda.metafacades.uml.Entity#getSchema()
729:             */
730:            protected String handleGetSchema() {
731:                String schemaName = ObjectUtils
732:                        .toString(this 
733:                                .findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_SCHEMA));
734:                if (StringUtils.isBlank(schemaName)) {
735:                    schemaName = ObjectUtils
736:                            .toString(this 
737:                                    .getConfiguredProperty(UMLMetafacadeProperties.SCHEMA_NAME));
738:                }
739:                return schemaName;
740:            }
741:
742:            /**
743:             * @see org.andromda.metafacades.uml.Entity#getIdentifierAssociationEnds()
744:             */
745:            protected Collection handleGetIdentifierAssociationEnds() {
746:                Collection associationEnds = new ArrayList(this 
747:                        .getAssociationEnds());
748:                if (associationEnds != null) {
749:                    MetafacadeUtils.filterByStereotype(associationEnds,
750:                            UMLProfile.STEREOTYPE_IDENTIFIER);
751:                }
752:                return associationEnds;
753:            }
754:
755:            /**
756:             * @see org.andromda.metafacades.uml.Entity#isCompositeIdentifier()
757:             */
758:            protected boolean handleIsCompositeIdentifier() {
759:                int identifiers = (!this .getIdentifiers().isEmpty()) ? this 
760:                        .getIdentifiers().size() : 0;
761:                identifiers = identifiers
762:                        + (!this .getIdentifierAssociationEnds().isEmpty() ? this 
763:                                .getIdentifierAssociationEnds().size()
764:                                : 0);
765:                return identifiers >= 2;
766:            }
767:
768:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.