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


001:        package org.andromda.metafacades.uml14;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collection;
005:        import java.util.Iterator;
006:
007:        import org.andromda.core.metafacade.MetafacadeBase;
008:        import org.andromda.core.metafacade.MetafacadeConstants;
009:        import org.andromda.core.metafacade.MetafacadeFactory;
010:        import org.andromda.metafacades.uml.BindingFacade;
011:        import org.andromda.metafacades.uml.ConstraintFacade;
012:        import org.andromda.metafacades.uml.EnumerationLiteralFacade;
013:        import org.andromda.metafacades.uml.ModelElementFacade;
014:        import org.andromda.metafacades.uml.ParameterFacade;
015:        import org.andromda.metafacades.uml.StereotypeFacade;
016:        import org.andromda.metafacades.uml.TaggedValueFacade;
017:        import org.andromda.metafacades.uml.TemplateParameterFacade;
018:        import org.andromda.metafacades.uml.TypeMappings;
019:        import org.andromda.metafacades.uml.UMLMetafacadeProperties;
020:        import org.andromda.metafacades.uml.UMLMetafacadeUtils;
021:        import org.andromda.metafacades.uml.UMLProfile;
022:        import org.andromda.translation.ocl.ExpressionKinds;
023:        import org.andromda.utils.StringUtilsHelper;
024:        import org.apache.commons.collections.CollectionUtils;
025:        import org.apache.commons.collections.Predicate;
026:        import org.apache.commons.lang.BooleanUtils;
027:        import org.apache.commons.lang.ObjectUtils;
028:        import org.apache.commons.lang.StringUtils;
029:        import org.apache.commons.lang.SystemUtils;
030:        import org.omg.uml.behavioralelements.statemachines.StateMachine;
031:        import org.omg.uml.foundation.core.Abstraction;
032:        import org.omg.uml.foundation.core.Comment;
033:        import org.omg.uml.foundation.core.Dependency;
034:        import org.omg.uml.foundation.core.ModelElement;
035:        import org.omg.uml.foundation.datatypes.VisibilityKind;
036:        import org.omg.uml.foundation.datatypes.VisibilityKindEnum;
037:
038:        /**
039:         * Metaclass facade implementation.
040:         */
041:        public class ModelElementFacadeLogicImpl extends
042:                ModelElementFacadeLogic {
043:            public ModelElementFacadeLogicImpl(
044:                    org.omg.uml.foundation.core.ModelElement metaObject,
045:                    String context) {
046:                super (metaObject, context);
047:            }
048:
049:            /**
050:             * @see org.andromda.metafacades.uml.ModelElementFacade#getTaggedValues()
051:             */
052:            protected java.util.Collection handleGetTaggedValues() {
053:                return metaObject.getTaggedValue();
054:            }
055:
056:            /**
057:             * @see org.andromda.metafacades.uml.ModelElementFacade#getPackageName()
058:             */
059:            protected String handleGetPackageName() {
060:                final boolean modelName = false;
061:                return UML14MetafacadeUtils.getPackageName(this .metaObject,
062:                        this .getNamespaceScope(modelName), modelName);
063:            }
064:
065:            /**
066:             * @see org.andromda.metafacades.uml.ModelElementFacade#getPackageName(boolean)
067:             */
068:            protected String handleGetPackageName(boolean modelName) {
069:                String packageName = this .getPackageName();
070:                if (modelName) {
071:                    packageName = StringUtils
072:                            .replace(
073:                                    packageName,
074:                                    ObjectUtils
075:                                            .toString(this 
076:                                                    .getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR)),
077:                                    MetafacadeConstants.NAMESPACE_SCOPE_OPERATOR);
078:                }
079:                return packageName;
080:            }
081:
082:            /**
083:             * @see org.andromda.metafacades.uml.ModelElementFacade#getFullyQualifiedName(boolean)
084:             */
085:            protected java.lang.String handleGetFullyQualifiedName(
086:                    boolean modelName) {
087:                String fullName = StringUtils.trimToEmpty(this .getName());
088:                final String packageName = this .getPackageName(true);
089:                final String metafacadeNamespaceScopeOperator = MetafacadeConstants.NAMESPACE_SCOPE_OPERATOR;
090:                if (StringUtils.isNotBlank(packageName)) {
091:                    fullName = packageName + metafacadeNamespaceScopeOperator
092:                            + fullName;
093:                }
094:                if (!modelName) {
095:                    if (this .getLanguageMappings() != null) {
096:                        fullName = StringUtils.trimToEmpty(this 
097:                                .getLanguageMappings().getTo(fullName));
098:
099:                        // now replace the metafacade scope operators
100:                        // with the mapped scope operators
101:                        final String namespaceScopeOperator = String
102:                                .valueOf(this 
103:                                        .getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR));
104:                        fullName = StringUtils.replace(fullName,
105:                                metafacadeNamespaceScopeOperator,
106:                                namespaceScopeOperator);
107:                    }
108:                }
109:
110:                if (this .isTemplateParametersPresent()
111:                        && BooleanUtils
112:                                .toBoolean(ObjectUtils
113:                                        .toString(this 
114:                                                .getConfiguredProperty(UMLMetafacadeProperties.ENABLE_TEMPLATING)))) {
115:                    // we'll be constructing the parameter list in this buffer
116:                    final StringBuffer buffer = new StringBuffer();
117:
118:                    // add the name we've constructed so far
119:                    buffer.append(fullName);
120:
121:                    // start the parameter list
122:                    buffer.append("<");
123:
124:                    // loop over the parameters, we are so to have at least one (see outer condition)
125:                    final Collection templateParameters = this 
126:                            .getTemplateParameters();
127:                    for (Iterator parameterIterator = templateParameters
128:                            .iterator(); parameterIterator.hasNext();) {
129:                        final ModelElementFacade modelElement = ((TemplateParameterFacade) parameterIterator
130:                                .next()).getParameter();
131:
132:                        if (modelElement instanceof  ParameterFacade) {
133:                            buffer.append(((ParameterFacade) modelElement)
134:                                    .getType().getFullyQualifiedName());
135:                        } else {
136:                            buffer.append(modelElement.getFullyQualifiedName());
137:                        }
138:
139:                        if (parameterIterator.hasNext()) {
140:                            buffer.append(", ");
141:                        }
142:                    }
143:
144:                    // we're finished listing the parameters
145:                    buffer.append(">");
146:
147:                    // we have constructed the full name in the buffer
148:                    fullName = buffer.toString();
149:                }
150:
151:                return fullName;
152:            }
153:
154:            /**
155:             * Gets the appropriate namespace property for retrieve the namespace scope operation (dependng on the given
156:             * <code>modelName</code> flag.
157:             *
158:             * @param modelName whether or not the scope operation for the model should be retrieved as oppposed to the mapped
159:             *                  scope operator.
160:             * @return the scope operator.
161:             */
162:            private String getNamespaceScope(boolean modelName) {
163:                String namespaceScope = MetafacadeConstants.NAMESPACE_SCOPE_OPERATOR;
164:                if (!modelName) {
165:                    namespaceScope = ObjectUtils
166:                            .toString(this 
167:                                    .getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR));
168:                }
169:                return namespaceScope;
170:            }
171:
172:            /**
173:             * @see org.andromda.metafacades.uml.ModelElementFacade#getFullyQualifiedName()
174:             */
175:            protected java.lang.String handleGetFullyQualifiedName() {
176:                return this .getFullyQualifiedName(false);
177:            }
178:
179:            /**
180:             * @see org.andromda.metafacades.uml.ModelElementFacade#findTaggedValues(java.lang.String)
181:             */
182:            protected Collection handleFindTaggedValues(String name) {
183:                final Collection values = new ArrayList();
184:
185:                // only search a tagged value when it actually has a name
186:                if (StringUtils.isNotBlank(name)) {
187:                    // trim the name, we don't want leading/trailing spaces
188:                    name = StringUtils.trimToEmpty(name);
189:
190:                    // loop over the tagged values
191:                    final Collection taggedValues = this .getTaggedValues();
192:                    for (final Iterator taggedValueIterator = taggedValues
193:                            .iterator(); taggedValueIterator.hasNext();) {
194:                        TaggedValueFacade taggedValue = (TaggedValueFacade) taggedValueIterator
195:                                .next();
196:
197:                        // does this name match the argument tagged value name ?
198:                        if (name.equals(taggedValue.getName())) {
199:                            for (final Iterator valueIterator = taggedValue
200:                                    .getValues().iterator(); valueIterator
201:                                    .hasNext();) {
202:                                // only process tagged values when they actually have a
203:                                // non-empty value
204:                                final Object value = valueIterator.next();
205:                                if (value != null) {
206:                                    // if an enumeration literal is referenced we assume
207:                                    // its name
208:                                    if (value instanceof  EnumerationLiteralFacade) {
209:                                        values
210:                                                .add(((EnumerationLiteralFacade) value)
211:                                                        .getValue(true));
212:                                    } else if (value instanceof  String) {
213:                                        // only add String when they are not blank
214:                                        String valueString = (String) value;
215:                                        if (StringUtils.isNotBlank(valueString)) {
216:                                            values.add(value);
217:                                        }
218:                                    } else {
219:                                        values.add(value);
220:                                    }
221:                                }
222:                            }
223:                        }
224:                    }
225:                }
226:                return values;
227:            }
228:
229:            /**
230:             * @see org.andromda.metafacades.uml.ModelElementFacade#findTaggedValue(java.lang.String)
231:             */
232:            protected Object handleFindTaggedValue(String name) {
233:                Collection taggedValues = findTaggedValues(name);
234:                return taggedValues.isEmpty() ? null : taggedValues.iterator()
235:                        .next();
236:            }
237:
238:            /**
239:             * @see org.andromda.metafacades.uml.ModelElementFacade#hasStereotype(java.lang.String)
240:             */
241:            protected boolean handleHasStereotype(final String stereotypeName) {
242:                Collection stereotypes = this .getStereotypes();
243:
244:                boolean hasStereotype = StringUtils.isNotBlank(stereotypeName)
245:                        && stereotypes != null && !stereotypes.isEmpty();
246:
247:                if (hasStereotype) {
248:                    class StereotypeFilter implements  Predicate {
249:                        public boolean evaluate(Object object) {
250:                            boolean valid;
251:                            StereotypeFacade facade = (StereotypeFacade) object;
252:                            String name = StringUtils.trimToEmpty(facade
253:                                    .getName());
254:                            valid = stereotypeName.equals(name);
255:                            while (!valid && facade != null) {
256:                                facade = (StereotypeFacade) facade
257:                                        .getGeneralization();
258:                                valid = facade != null
259:                                        && StringUtils.trimToEmpty(
260:                                                facade.getName()).equals(
261:                                                stereotypeName);
262:                            }
263:                            return valid;
264:                        }
265:                    }
266:                    hasStereotype = CollectionUtils.find(this .getStereotypes(),
267:                            new StereotypeFilter()) != null;
268:                }
269:                return hasStereotype;
270:            }
271:
272:            /**
273:             * @see org.andromda.metafacades.uml.ModelElementFacade#getId()
274:             */
275:            protected String handleGetId() {
276:                return this .metaObject.refMofId();
277:            }
278:
279:            /**
280:             * @see org.andromda.metafacades.uml.ModelElementFacade#hasExactStereotype(java.lang.String)
281:             */
282:            protected boolean handleHasExactStereotype(String stereotypeName) {
283:                return this .getStereotypeNames().contains(
284:                        StringUtils.trimToEmpty(stereotypeName));
285:            }
286:
287:            /**
288:             * @see org.andromda.metafacades.uml.ModelElementFacade#getVisibility()
289:             */
290:            protected String handleGetVisibility() {
291:                String visibility;
292:
293:                final VisibilityKind visibilityKind = metaObject
294:                        .getVisibility();
295:                if (visibilityKind == null
296:                        || VisibilityKindEnum.VK_PRIVATE.equals(visibilityKind)) {
297:                    visibility = "private";
298:                } else if (VisibilityKindEnum.VK_PROTECTED
299:                        .equals(visibilityKind)) {
300:                    visibility = "protected";
301:                } else if (VisibilityKindEnum.VK_PUBLIC.equals(visibilityKind)) {
302:                    visibility = "public";
303:                } else // VisibilityKindEnum.VK_PACKAGE
304:                {
305:                    visibility = "package";
306:                }
307:
308:                final TypeMappings languageMappings = this 
309:                        .getLanguageMappings();
310:                if (languageMappings != null) {
311:                    visibility = languageMappings.getTo(visibility);
312:                }
313:
314:                return visibility;
315:            }
316:
317:            /**
318:             * @see org.andromda.metafacades.uml.ModelElementFacade#getStereotypeNames()
319:             */
320:            protected java.util.Collection handleGetStereotypeNames() {
321:                Collection stereotypeNames = new ArrayList();
322:
323:                Collection stereotypes = metaObject.getStereotype();
324:                for (final Iterator stereotypeIt = stereotypes.iterator(); stereotypeIt
325:                        .hasNext();) {
326:                    ModelElement stereotype = (ModelElement) stereotypeIt
327:                            .next();
328:                    if (stereotype != null) {
329:                        stereotypeNames.add(StringUtils.trimToEmpty(stereotype
330:                                .getName()));
331:                    }
332:                }
333:                return stereotypeNames;
334:            }
335:
336:            /**
337:             * @see org.andromda.metafacades.uml.ModelElementFacade#getFullyQualifiedNamePath()
338:             */
339:            protected String handleGetFullyQualifiedNamePath() {
340:                return StringUtils
341:                        .replace(
342:                                this .getFullyQualifiedName(),
343:                                String
344:                                        .valueOf(this 
345:                                                .getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR)),
346:                                "/");
347:            }
348:
349:            /**
350:             * @see org.andromda.metafacades.uml.ModelElementFacade#getPackagePath()
351:             */
352:            protected String handleGetPackagePath() {
353:                return StringUtils
354:                        .replace(
355:                                this .getPackageName(),
356:                                String
357:                                        .valueOf(this 
358:                                                .getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR)),
359:                                "/");
360:            }
361:
362:            /**
363:             * @see org.andromda.metafacades.uml.ModelElementFacade#getDocumentation(java.lang.String)
364:             */
365:            protected String handleGetDocumentation(String indent) {
366:                return getDocumentation(indent, 64);
367:            }
368:
369:            /**
370:             * @see org.andromda.metafacades.uml.ModelElementFacade#getDocumentation(java.lang.String, int)
371:             */
372:            protected String handleGetDocumentation(String indent,
373:                    int lineLength) {
374:                return getDocumentation(indent, lineLength, true);
375:            }
376:
377:            /**
378:             * @see org.andromda.metafacades.uml.ModelElementFacade#getDocumentation(java.lang.String, int, boolean)
379:             */
380:            protected String handleGetDocumentation(String indent,
381:                    int lineLength, boolean htmlStyle) {
382:                final StringBuffer documentation = new StringBuffer();
383:
384:                if (lineLength < 1) {
385:                    lineLength = Integer.MAX_VALUE;
386:                }
387:
388:                final Collection comments = this .metaObject.getComment();
389:                if (comments != null && !comments.isEmpty()) {
390:                    for (final Iterator commentIterator = comments.iterator(); commentIterator
391:                            .hasNext();) {
392:                        final Comment comment = (Comment) commentIterator
393:                                .next();
394:                        String commentString = StringUtils.trimToEmpty(comment
395:                                .getBody());
396:
397:                        // if there isn't anything in the body, try the name
398:                        if (StringUtils.isEmpty(commentString)) {
399:                            commentString = StringUtils.trimToEmpty(comment
400:                                    .getName());
401:                        }
402:                        documentation.append(StringUtils
403:                                .trimToEmpty(commentString));
404:                        documentation.append(SystemUtils.LINE_SEPARATOR);
405:                    }
406:                }
407:
408:                // if there still isn't anything, try a tagged value
409:                if (StringUtils.isEmpty(documentation.toString())) {
410:                    documentation
411:                            .append(StringUtils
412:                                    .trimToEmpty((String) this 
413:                                            .findTaggedValue(UMLProfile.TAGGEDVALUE_DOCUMENTATION)));
414:                }
415:
416:                return StringUtilsHelper.format(StringUtils
417:                        .trimToEmpty(documentation.toString()), indent,
418:                        lineLength, htmlStyle);
419:            }
420:
421:            /**
422:             * @see org.andromda.metafacades.uml.ModelElementFacade#getName()
423:             */
424:            protected String handleGetName() {
425:                return metaObject.getName();
426:            }
427:
428:            /**
429:             * Gets the array suffix from the configured metafacade properties.
430:             *
431:             * @return the array suffix.
432:             */
433:            private String getArraySuffix() {
434:                return String
435:                        .valueOf(this 
436:                                .getConfiguredProperty(UMLMetafacadeProperties.ARRAY_NAME_SUFFIX));
437:            }
438:
439:            /**
440:             * @see org.andromda.metafacades.uml.ModelElementFacade#getLanguageMappings()
441:             */
442:            protected TypeMappings handleGetLanguageMappings() {
443:                final String propertyName = UMLMetafacadeProperties.LANGUAGE_MAPPINGS_URI;
444:                Object property = this .getConfiguredProperty(propertyName);
445:                TypeMappings mappings = null;
446:                String uri;
447:                if (property instanceof  String) {
448:                    uri = (String) property;
449:                    try {
450:                        mappings = TypeMappings.getInstance(uri);
451:                        mappings.setArraySuffix(this .getArraySuffix());
452:                        this .setProperty(propertyName, mappings);
453:                    } catch (Throwable throwable) {
454:                        final String message = "Error getting '" + propertyName
455:                                + "' --> '" + uri + "'";
456:                        logger.error(message, throwable);
457:
458:                        // don't throw the exception
459:                    }
460:                } else {
461:                    mappings = (TypeMappings) property;
462:                }
463:                return mappings;
464:            }
465:
466:            /**
467:             * @see org.andromda.metafacades.uml.ModelElementFacade#getPackage()
468:             */
469:            protected Object handleGetPackage() {
470:                return metaObject.getNamespace();
471:            }
472:
473:            /**
474:             * @see org.andromda.metafacades.uml.ModelElementFacade#getRootPackage()
475:             */
476:            protected Object handleGetRootPackage() {
477:                return UML14MetafacadeUtils.getRootPackage();
478:            }
479:
480:            /**
481:             * @see org.andromda.metafacades.uml.ModelElementFacade#getSourceDependencies()
482:             */
483:            protected java.util.Collection handleGetSourceDependencies() {
484:                Collection dependencies = new ArrayList();
485:                Collection clientDependencies = UML14MetafacadeUtils
486:                        .getCorePackage().getAClientClientDependency()
487:                        .getClientDependency(this .metaObject);
488:                if (clientDependencies != null) {
489:                    dependencies.addAll(clientDependencies);
490:                }
491:                CollectionUtils.filter(dependencies, new Predicate() {
492:                    public boolean evaluate(Object object) {
493:                        return (object instanceof  Dependency)
494:                                && !(object instanceof  Abstraction);
495:                    }
496:                });
497:                return dependencies;
498:            }
499:
500:            /**
501:             * @see org.andromda.metafacades.uml.ModelElementFacade#getTargetDependencies()
502:             */
503:            protected Collection handleGetTargetDependencies() {
504:                Collection dependencies = new ArrayList();
505:                Collection supplierDependencies = UML14MetafacadeUtils
506:                        .getCorePackage().getASupplierSupplierDependency()
507:                        .getSupplierDependency(this .metaObject);
508:                if (supplierDependencies != null) {
509:                    dependencies.addAll(supplierDependencies);
510:                }
511:                CollectionUtils.filter(dependencies, new Predicate() {
512:                    public boolean evaluate(Object object) {
513:                        return (object instanceof  Dependency)
514:                                && !(object instanceof  Abstraction);
515:                    }
516:                });
517:                return dependencies;
518:            }
519:
520:            /**
521:             * @see org.andromda.metafacades.uml.ModelElementFacade#getStereotypes()
522:             */
523:            protected java.util.Collection handleGetStereotypes() {
524:                return this .metaObject.getStereotype();
525:            }
526:
527:            /**
528:             * @see org.andromda.metafacades.uml.ModelElementFacade#getModel()
529:             */
530:            protected Object handleGetModel() {
531:                return MetafacadeFactory.getInstance().getModel().getModel();
532:            }
533:
534:            /**
535:             * @see org.andromda.metafacades.uml.ModelElementFacade#getConstraints()
536:             */
537:            protected Collection handleGetConstraints() {
538:                return this .metaObject.getConstraint();
539:            }
540:
541:            /**
542:             * @see org.andromda.metafacades.uml.ModelElementFacade#getConstraints(java.lang.String)
543:             */
544:            protected Collection handleGetConstraints(final String kind) {
545:                return CollectionUtils.select(getConstraints(),
546:                        new Predicate() {
547:                            public boolean evaluate(Object object) {
548:                                if (object instanceof  ConstraintFacade) {
549:                                    ConstraintFacade constraint = (ConstraintFacade) object;
550:                                    return ((ExpressionKinds.BODY.equals(kind) && constraint
551:                                            .isBodyExpression())
552:                                            || (ExpressionKinds.DEF
553:                                                    .equals(kind) && constraint
554:                                                    .isDefinition())
555:                                            || (ExpressionKinds.INV
556:                                                    .equals(kind) && constraint
557:                                                    .isInvariant())
558:                                            || (ExpressionKinds.PRE
559:                                                    .equals(kind) && constraint
560:                                                    .isPreCondition()) || (ExpressionKinds.POST
561:                                            .equals(kind) && constraint
562:                                            .isPostCondition()));
563:                                }
564:                                return false;
565:                            }
566:                        });
567:            }
568:
569:            /**
570:             * @see org.andromda.metafacades.uml.ModelElementFacade#translateConstraint(java.lang.String, java.lang.String)
571:             */
572:            protected String handleTranslateConstraint(final String name,
573:                    String translation) {
574:                String translatedExpression = "";
575:                ConstraintFacade constraint = (ConstraintFacade) CollectionUtils
576:                        .find(this .getConstraints(), new Predicate() {
577:                            public boolean evaluate(Object object) {
578:                                ConstraintFacade constraint = (ConstraintFacade) object;
579:                                return StringUtils.trimToEmpty(
580:                                        constraint.getName()).equals(
581:                                        StringUtils.trimToEmpty(name));
582:                            }
583:                        });
584:
585:                if (constraint != null) {
586:                    translatedExpression = constraint
587:                            .getTranslation(translation);
588:                }
589:                return translatedExpression;
590:            }
591:
592:            /**
593:             * @see org.andromda.metafacades.uml.ModelElementFacade#translateConstraints(java.lang.String)
594:             */
595:            protected java.lang.String[] handleTranslateConstraints(
596:                    String translation) {
597:                return this .translateConstraints(this .getConstraints(),
598:                        translation);
599:            }
600:
601:            /**
602:             * Private helper that translates all the expressions contained in the <code>constraints</code>, and returns an
603:             * array of the translated expressions.
604:             *
605:             * @param constraints the constraints to translate
606:             * @param translation the translation to transate <code>to</code>.
607:             * @return String[] the translated expressions, or null if no constraints were found
608:             */
609:            private String[] translateConstraints(Collection constraints,
610:                    String translation) {
611:                String[] translatedExpressions = null;
612:                if (constraints != null && !constraints.isEmpty()) {
613:                    translatedExpressions = new String[constraints.size()];
614:                    Iterator constraintIt = constraints.iterator();
615:                    for (int ctr = 0; constraintIt.hasNext(); ctr++) {
616:                        ConstraintFacade constraint = (ConstraintFacade) constraintIt
617:                                .next();
618:                        translatedExpressions[ctr] = constraint
619:                                .getTranslation(translation);
620:                    }
621:                }
622:                return translatedExpressions;
623:            }
624:
625:            /**
626:             * @see org.andromda.metafacades.uml.ModelElementFacade#translateConstraints(java.lang.String, java.lang.String)
627:             */
628:            protected java.lang.String[] handleTranslateConstraints(
629:                    final String kind, String translation) {
630:                Collection constraints = this .getConstraints();
631:                CollectionUtils.filter(constraints, new Predicate() {
632:                    public boolean evaluate(Object object) {
633:                        ConstraintFacade constraint = (ConstraintFacade) object;
634:                        return UMLMetafacadeUtils.isConstraintKind(constraint
635:                                .getBody(), kind);
636:                    }
637:                });
638:                return this .translateConstraints(constraints, translation);
639:            }
640:
641:            /**
642:             * @see org.andromda.metafacades.uml.ModelElementFacade#getStateMachineContext()
643:             */
644:            protected Object handleGetStateMachineContext() {
645:                StateMachine machineContext = null;
646:
647:                final Collection machines = UML14MetafacadeUtils.getModel()
648:                        .getStateMachines().getStateMachine().refAllOfType();
649:                for (final Iterator machineIterator = machines.iterator(); machineIterator
650:                        .hasNext();) {
651:                    final StateMachine machine = (StateMachine) machineIterator
652:                            .next();
653:                    final ModelElement contextElement = machine.getContext();
654:                    if (metaObject.equals(contextElement)) {
655:                        machineContext = machine;
656:                    }
657:                }
658:
659:                return machineContext;
660:            }
661:
662:            /**
663:             * @see org.andromda.metafacades.uml.ModelElementFacade#getTemplateParameters()
664:             */
665:            protected Collection handleGetTemplateParameters() {
666:                return metaObject.getTemplateParameter();
667:            }
668:
669:            /**
670:             * @see org.andromda.core.metafacade.MetafacadeBase#getValidationName()
671:             */
672:            public String getValidationName() {
673:                final StringBuffer validationName = new StringBuffer();
674:                final Object seperator = MetafacadeConstants.NAMESPACE_SCOPE_OPERATOR;
675:                for (ModelElement namespace = metaObject.getNamespace(); namespace != null; namespace = namespace
676:                        .getNamespace()) {
677:                    if (validationName.length() == 0) {
678:                        validationName.append(namespace.getName());
679:                    } else {
680:                        validationName.insert(0, seperator);
681:                        validationName.insert(0, namespace.getName());
682:                    }
683:                }
684:                if (validationName.length() > 0) {
685:                    validationName.append(seperator);
686:                }
687:                if (StringUtils.isNotEmpty(this .getName())) {
688:                    validationName.append(this .getName());
689:                } else {
690:                    validationName
691:                            .append(this 
692:                                    .getConfiguredProperty(UMLMetafacadeProperties.UNDEFINED_NAME));
693:                }
694:                return validationName.toString();
695:            }
696:
697:            /**
698:             * @see org.andromda.metafacades.uml.ModelElementFacade#isConstraintsPresent()
699:             */
700:            protected boolean handleIsConstraintsPresent() {
701:                return this .getConstraints() != null
702:                        && !this .getConstraints().isEmpty();
703:            }
704:
705:            /**
706:             * @see org.andromda.metafacades.uml.ModelElementFacade#isBindingDependenciesPresent()
707:             */
708:            protected boolean handleIsBindingDependenciesPresent() {
709:                Collection dependencies = this .getSourceDependencies();
710:                CollectionUtils.filter(dependencies, new Predicate() {
711:                    public boolean evaluate(Object object) {
712:                        return object instanceof  BindingFacade;
713:                    }
714:                });
715:                return !dependencies.isEmpty();
716:            }
717:
718:            /**
719:             * @see org.andromda.metafacades.uml.ModelElementFacade#isTemplateParametersPresent()
720:             */
721:            protected boolean handleIsTemplateParametersPresent() {
722:                final Collection params = this .getTemplateParameters();
723:                return params != null && !params.isEmpty();
724:            }
725:
726:            /**
727:             * @see org.andromda.metafacades.uml.ModelElementFacade#copyTaggedValues(org.andromda.metafacades.uml.ModelElementFacade)
728:             */
729:            protected void handleCopyTaggedValues(ModelElementFacade element) {
730:                org.omg.uml.foundation.core.ModelElement elementMetaObject;
731:                if (element instanceof  MetafacadeBase) {
732:                    final MetafacadeBase metafacade = (MetafacadeBase) element;
733:                    final Object metaObject = metafacade.getMetaObject();
734:                    if (metaObject instanceof  ModelElement) {
735:                        elementMetaObject = (ModelElement) metaObject;
736:                        this .metaObject.getTaggedValue().addAll(
737:                                elementMetaObject.getTaggedValue());
738:                    }
739:                }
740:            }
741:
742:            /**
743:             * @see org.andromda.metafacades.uml.ModelElementFacade#getTemplateParameter(java.lang.String)
744:             */
745:            protected Object handleGetTemplateParameter(String parameterName) {
746:                TemplateParameterFacade templateParameter = null;
747:                if (StringUtils.isNotEmpty(parameterName)) {
748:                    parameterName = StringUtils.trimToEmpty(parameterName);
749:                    final Collection parameters = this .getTemplateParameters();
750:                    if (parameters != null && !parameters.isEmpty()) {
751:                        for (final Iterator iterator = parameters.iterator(); iterator
752:                                .hasNext();) {
753:                            final TemplateParameterFacade currentTemplateParameter = (TemplateParameterFacade) iterator
754:                                    .next();
755:                            if (currentTemplateParameter.getParameter() != null) {
756:                                final ModelElementFacade parameter = currentTemplateParameter
757:                                        .getParameter();
758:
759:                                // there should not be two template parameters with the same parameter name, but nothing
760:                                // prevents the model from allowing that.  So return the first instance if found.
761:                                if (parameterName.equals(parameter.getName())) {
762:                                    templateParameter = currentTemplateParameter;
763:                                    break;
764:                                }
765:                            }
766:                        }
767:                    }
768:                }
769:
770:                return templateParameter;
771:            }
772:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.