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