001: package org.andromda.metafacades.emf.uml2;
002:
003: import org.andromda.metafacades.uml.AssociationEndFacade;
004: import org.andromda.metafacades.uml.AttributeFacade;
005: import org.andromda.metafacades.uml.ClassifierFacade;
006: import org.andromda.metafacades.uml.DependencyFacade;
007: import org.andromda.metafacades.uml.FilteredCollection;
008: import org.andromda.metafacades.uml.ModelElementFacade;
009: import org.andromda.metafacades.uml.NameMasker;
010: import org.andromda.metafacades.uml.OperationFacade;
011: import org.andromda.metafacades.uml.PackageFacade;
012: import org.andromda.metafacades.uml.ParameterFacade;
013: import org.andromda.metafacades.uml.TypeMappings;
014: import org.andromda.metafacades.uml.UMLMetafacadeProperties;
015: import org.andromda.metafacades.uml.UMLMetafacadeUtils;
016: import org.andromda.metafacades.uml.UMLProfile;
017: import org.andromda.metafacades.uml.GeneralizableElementFacade;
018: import org.apache.commons.collections.CollectionUtils;
019: import org.apache.commons.collections.Predicate;
020: import org.apache.commons.collections.Transformer;
021: import org.apache.commons.lang.StringUtils;
022: import org.eclipse.uml2.Abstraction;
023: import org.eclipse.uml2.AssociationClass;
024: import org.eclipse.uml2.DataType;
025: import org.eclipse.uml2.Enumeration;
026: import org.eclipse.uml2.Interface;
027: import org.eclipse.uml2.PrimitiveType;
028:
029: import java.security.MessageDigest;
030: import java.security.NoSuchAlgorithmException;
031: import java.util.ArrayList;
032: import java.util.Collection;
033: import java.util.Collections;
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
041: * org.andromda.metafacades.uml.ClassifierFacade.
042: *
043: * @see org.andromda.metafacades.uml.ClassifierFacade
044: */
045: public class ClassifierFacadeLogicImpl extends ClassifierFacadeLogic {
046: public ClassifierFacadeLogicImpl(
047: final org.eclipse.uml2.Classifier metaObject,
048: final String context) {
049: super (metaObject, context);
050: }
051:
052: /**
053: * Overridden to provide name masking.
054: *
055: * @see org.andromda.metafacades.uml.ModelElementFacade#getName()
056: */
057: protected String handleGetName() {
058: final String nameMask = String
059: .valueOf(this
060: .getConfiguredProperty(UMLMetafacadeProperties.CLASSIFIER_NAME_MASK));
061: return NameMasker.mask(super .handleGetName(), nameMask);
062: }
063:
064: /**
065: * @see org.andromda.metafacades.uml.ClassifierFacade#isPrimitive()
066: */
067: protected boolean handleIsPrimitive() {
068: // If this type has a wrapper then its a primitive,
069: // otherwise it isn't
070: return this .getWrapperMappings() != null
071: && this .getWrapperMappings().getMappings()
072: .containsFrom(this .getFullyQualifiedName());
073: }
074:
075: /**
076: *
077: * @see org.andromda.metafacades.uml.ClassifierFacade#getOperationCallFromAttributes()
078: */
079: protected java.lang.String handleGetOperationCallFromAttributes() {
080: final StringBuffer call = new StringBuffer();
081: String separator = "";
082: call.append("(");
083: for (final Iterator iterator = this .getAttributes().iterator(); iterator
084: .hasNext();) {
085: AttributeFacade attribute = (AttributeFacade) iterator
086: .next();
087:
088: call.append(separator);
089: String typeName = attribute.getType()
090: .getFullyQualifiedName();
091: call.append(typeName);
092: call.append(" ");
093: call.append(attribute.getName());
094: separator = ", ";
095: }
096: call.append(")");
097: return call.toString();
098: }
099:
100: /**
101: * @see org.andromda.metafacades.uml.ClassifierFacade#isAbstract()
102: */
103: protected boolean handleIsAbstract() {
104: return this .metaObject.isAbstract();
105: }
106:
107: /**
108: * @see org.andromda.metafacades.uml.ClassifierFacade#getProperties()
109: */
110: protected java.util.Collection handleGetProperties() {
111: return this .getProperties(false);
112: }
113:
114: /**
115: * @see org.andromda.metafacades.uml.ClassifierFacade#getAllProperties()
116: */
117: public Collection handleGetAllProperties() {
118: return this .getProperties(true);
119: }
120:
121: /**
122: * @see org.andromda.metafacades.uml.ClassifierFacade#getAllRequiredConstructorParameters()
123: */
124: public Collection handleGetAllRequiredConstructorParameters() {
125: final Collection allRequiredConstructorParameters = new ArrayList();
126:
127: final Collection generalizations = this .getGeneralizations();
128: for (Iterator parents = generalizations.iterator(); parents
129: .hasNext();) {
130: final Object parent = parents.next();
131: if (parent instanceof ClassifierFacade) {
132: allRequiredConstructorParameters
133: .addAll(((ClassifierFacade) parent)
134: .getAllRequiredConstructorParameters());
135: }
136: }
137:
138: allRequiredConstructorParameters.addAll(this
139: .getRequiredConstructorParameters());
140:
141: return allRequiredConstructorParameters;
142: }
143:
144: /**
145: * @see org.andromda.metafacades.uml.ClassifierFacade#getRequiredConstructorParameters()
146: */
147: public Collection handleGetRequiredConstructorParameters() {
148: final Collection requiredConstructorParameters = new ArrayList();
149:
150: final Collection properties = this .getProperties();
151: for (Iterator propertyIterator = properties.iterator(); propertyIterator
152: .hasNext();) {
153: final Object property = propertyIterator.next();
154: if (property instanceof AttributeFacade) {
155: final AttributeFacade attribute = (AttributeFacade) property;
156: if (attribute.isRequired() || attribute.isReadOnly()) {
157: requiredConstructorParameters.add(attribute);
158: }
159: } else if (property instanceof AssociationEndFacade) {
160: final AssociationEndFacade associationEnd = (AssociationEndFacade) property;
161: if (associationEnd.isRequired()
162: || associationEnd.isReadOnly()) {
163: requiredConstructorParameters.add(associationEnd);
164: }
165: }
166: }
167:
168: return requiredConstructorParameters;
169: }
170:
171: /**
172: * @see org.andromda.metafacades.uml.ClassifierFacade#isDataType()
173: */
174: protected boolean handleIsDataType() {
175: return this .metaObject instanceof DataType;
176: }
177:
178: /**
179: * @see org.andromda.metafacades.uml.ClassifierFacade#isArrayType()
180: */
181: protected boolean handleIsArrayType() {
182: return this .getFullyQualifiedName(true).endsWith(
183: this .getArraySuffix());
184: }
185:
186: /**
187: * Gets the array suffix from the configured metafacade properties.
188: *
189: * @return the array suffix.
190: */
191: private String getArraySuffix() {
192: return String
193: .valueOf(this
194: .getConfiguredProperty(UMLMetafacadeProperties.ARRAY_NAME_SUFFIX));
195: }
196:
197: /**
198: * @see org.andromda.metafacades.uml.ClassifierFacade#isCollectionType()
199: */
200: protected boolean handleIsCollectionType() {
201: return UMLMetafacadeUtils.isType(this ,
202: UMLProfile.COLLECTION_TYPE_NAME);
203: }
204:
205: /**
206: * @see org.andromda.metafacades.uml.ClassifierFacade#getWrapperName()
207: */
208: protected String handleGetWrapperName() {
209: String wrapperName = null;
210: if (this .getWrapperMappings() != null) {
211: if (this .getWrapperMappings().getMappings().containsFrom(
212: this .getFullyQualifiedName())) {
213: wrapperName = this .getWrapperMappings().getTo(
214: this .getFullyQualifiedName());
215: }
216: }
217: return wrapperName;
218: }
219:
220: /**
221: * Gets the mappings from primitive types to wrapper types. Some languages
222: * have primitives (i.e., Java) and some languages don't, so therefore this
223: * property is optional.
224: *
225: * @return the wrapper mappings
226: */
227: protected TypeMappings getWrapperMappings() {
228: final String propertyName = UMLMetafacadeProperties.WRAPPER_MAPPINGS_URI;
229: final Object property = this
230: .getConfiguredProperty(propertyName);
231: TypeMappings mappings = null;
232: String uri;
233: if (property instanceof String) {
234: uri = (String) property;
235: try {
236: mappings = TypeMappings.getInstance(uri);
237: this .setProperty(propertyName, mappings);
238: } catch (final Throwable throwable) {
239: final String errMsg = "Error getting '" + propertyName
240: + "' --> '" + uri + "'";
241: this .logger.error(errMsg, throwable);
242:
243: // don't throw the exception
244: }
245: } else {
246: mappings = (TypeMappings) property;
247: }
248: return mappings;
249: }
250:
251: /**
252: * @see org.andromda.metafacades.uml.ClassifierFacade#isDateType()
253: */
254: protected boolean handleIsDateType() {
255: return UMLMetafacadeUtils.isType(this ,
256: UMLProfile.DATE_TYPE_NAME);
257: }
258:
259: /**
260: * @see org.andromda.metafacades.uml.ClassifierFacade#isInterface()
261: */
262: protected boolean handleIsInterface() {
263: return this .metaObject instanceof Interface;
264: }
265:
266: /**
267: * @see org.andromda.metafacades.uml.ClassifierFacade#getJavaNullString()
268: */
269: protected String handleGetJavaNullString() {
270: String javaNullString;
271: if (this .isPrimitive()) {
272: if (UMLMetafacadeUtils.isType(this ,
273: UMLProfile.BOOLEAN_TYPE_NAME)) {
274: javaNullString = "false";
275: } else {
276: javaNullString = "0";
277: }
278: } else {
279: javaNullString = "null";
280: }
281: return javaNullString;
282: }
283:
284: /**
285: * @see org.andromda.metafacades.uml.ClassifierFacade#isListType()
286: */
287: protected boolean handleIsListType() {
288: return UMLMetafacadeUtils.isType(this ,
289: UMLProfile.LIST_TYPE_NAME);
290: }
291:
292: /**
293: * @see org.andromda.metafacades.uml.ClassifierFacade#isSetType()
294: */
295: protected boolean handleIsSetType() {
296: return UMLMetafacadeUtils
297: .isType(this , UMLProfile.SET_TYPE_NAME);
298: }
299:
300: /**
301: * @see org.andromda.metafacades.uml.ClassifierFacade#isFileType()
302: */
303: protected boolean handleIsFileType() {
304: return UMLMetafacadeUtils.isType(this ,
305: UMLProfile.FILE_TYPE_NAME);
306: }
307:
308: /**
309: * @see org.andromda.metafacades.uml.ClassifierFacade#isMapType()
310: */
311: public boolean handleIsMapType() {
312: return UMLMetafacadeUtils
313: .isType(this , UMLProfile.MAP_TYPE_NAME);
314: }
315:
316: /**
317: * @see org.andromda.metafacades.uml.ClassifierFacade#isStringType()
318: */
319: protected boolean handleIsStringType() {
320: return UMLMetafacadeUtils.isType(this ,
321: UMLProfile.STRING_TYPE_NAME);
322: }
323:
324: /**
325: * @see org.andromda.metafacades.uml.ClassifierFacade#isEnumeration()
326: */
327: protected boolean handleIsEnumeration() {
328: return (this .hasStereotype(UMLProfile.STEREOTYPE_ENUMERATION))
329: || (this .metaObject instanceof Enumeration);
330: }
331:
332: /**
333: * @see org.andromda.metafacades.uml.ClassifierFacade#getArrayName()
334: */
335: protected String handleGetArrayName() {
336: return this .getName() + this .getArraySuffix();
337: }
338:
339: /**
340: * @see org.andromda.metafacades.uml.ClassifierFacade#getFullyQualifiedArrayName()
341: */
342: protected String handleGetFullyQualifiedArrayName() {
343: return this .getFullyQualifiedName() + this .getArraySuffix();
344: }
345:
346: /**
347: * Calculates the serial version UID of this classifier based on the
348: * signature of the classifier (name, visibility, attributes and methods).
349: * The algorithm is inspired by
350: * {@link java.io.ObjectStreamClass#getSerialVersionUID()}.
351: *
352: * The value should be stable as long as the classifier remains unchanged
353: * and should change as soon as there is any change in the signature of the
354: * classifier.
355: *
356: * @return the serial version UID of this classifier.
357: */
358: private Long calculateDefaultSUID() {
359: final StringBuffer buffer = new StringBuffer();
360:
361: // class name
362: buffer.append(this .getName());
363:
364: // generalizations
365: for (final Iterator iterator = this .getAllGeneralizations()
366: .iterator(); iterator.hasNext();) {
367: ClassifierFacade classifier = (ClassifierFacade) iterator
368: .next();
369: buffer.append(classifier.getName());
370: }
371:
372: // declared fields
373: for (final Iterator iterator = this .getAttributes().iterator(); iterator
374: .hasNext();) {
375: AttributeFacade attribute = (AttributeFacade) iterator
376: .next();
377: buffer.append(attribute.getName());
378: buffer.append(attribute.getVisibility());
379: buffer.append(attribute.getType().getName());
380: }
381:
382: // operations
383: for (final Iterator iter = this .getOperations().iterator(); iter
384: .hasNext();) {
385: OperationFacade operation = (OperationFacade) iter.next();
386: buffer.append(operation.getName());
387: buffer.append(operation.getVisibility());
388: buffer.append(operation.getReturnType().getName());
389: for (final Iterator iterator = operation.getArguments()
390: .iterator(); iterator.hasNext();) {
391: final ParameterFacade parameter = (ParameterFacade) iterator
392: .next();
393: buffer.append(parameter.getName());
394: buffer.append(parameter.getType().getName());
395: }
396: }
397: final String signature = buffer.toString();
398:
399: Long serialVersionUID = new Long(0L);
400: try {
401: MessageDigest md = MessageDigest.getInstance("SHA");
402: byte[] hashBytes = md.digest(signature.getBytes());
403:
404: long hash = 0;
405: for (int ctr = Math.min(hashBytes.length, 8) - 1; ctr >= 0; ctr--) {
406: hash = (hash << 8) | (hashBytes[ctr] & 0xFF);
407: }
408: serialVersionUID = new Long(hash);
409: } catch (final NoSuchAlgorithmException exception) {
410: final String errMsg = "Error performing ModelElementFacadeImpl.getSerialVersionUID";
411: this .logger.error(errMsg, exception);
412: }
413: if (this .logger.isDebugEnabled()) {
414: this .logger.debug("Default UID for "
415: + this .metaObject.getQualifiedName() + " is "
416: + serialVersionUID);
417: }
418: return serialVersionUID;
419: }
420:
421: /**
422: * @see org.andromda.metafacades.uml.ClassifierFacade#getSerialVersionUID()
423: */
424: protected java.lang.Long handleGetSerialVersionUID() {
425: if (this .logger.isDebugEnabled()) {
426: this .logger.debug("Starting get serial UID");
427: }
428: Long serialVersionUID;
429: String serialVersionString = UmlUtilities
430: .getSerialVersionUID(this );
431: if (serialVersionString != null) {
432: serialVersionUID = Long.valueOf(serialVersionString);
433: } else {
434: serialVersionUID = this .calculateDefaultSUID();
435: }
436: if (this .logger.isDebugEnabled()) {
437: this .logger.debug("SerialVersionUID for "
438: + this .metaObject.getQualifiedName() + " is "
439: + serialVersionUID);
440: }
441: return serialVersionUID;
442: }
443:
444: /**
445: * @see org.andromda.metafacades.uml.ClassifierFacade#isBlobType()
446: */
447: protected boolean handleIsBlobType() {
448: return UMLMetafacadeUtils.isType(this ,
449: UMLProfile.BLOB_TYPE_NAME);
450: }
451:
452: /**
453: * @see org.andromda.metafacades.uml.ClassifierFacade#isClobType()
454: */
455: protected boolean handleIsClobType() {
456: return UMLMetafacadeUtils.isType(this ,
457: UMLProfile.CLOB_TYPE_NAME);
458: }
459:
460: /**
461: * @see org.andromda.metafacades.uml.ClassifierFacade#isBooleanType()
462: */
463: protected boolean handleIsBooleanType() {
464: return UMLMetafacadeUtils.isType(this ,
465: UMLProfile.BOOLEAN_TYPE_NAME);
466: }
467:
468: /**
469: * @see org.andromda.metafacades.uml.ClassifierFacade#isTimeType()
470: */
471: protected boolean handleIsTimeType() {
472: return UMLMetafacadeUtils.isType(this ,
473: UMLProfile.TIME_TYPE_NAME);
474: }
475:
476: /**
477: * @see org.andromda.metafacades.uml.ClassifierFacade#getAttributes(boolean)
478: */
479: protected java.util.Collection handleGetAttributes(
480: final boolean follow) {
481: return this .shieldedElements(UmlUtilities.getAttributes(
482: this .metaObject, follow));
483: }
484:
485: /**
486: * @see org.andromda.metafacades.uml.ClassifierFacade#findAttribute(java.lang.String)
487: */
488: protected org.andromda.metafacades.uml.AttributeFacade handleFindAttribute(
489: final java.lang.String name) {
490: return (AttributeFacade) CollectionUtils.find(this
491: .getAttributes(), new Predicate() {
492: public boolean evaluate(final Object object) {
493: final AttributeFacade attribute = (AttributeFacade) object;
494: return StringUtils.trimToEmpty(attribute.getName())
495: .equals(name);
496: }
497: });
498: }
499:
500: /**
501: * @see org.andromda.metafacades.uml.ClassifierFacade#getProperties(boolean)
502: */
503: protected java.util.Collection handleGetProperties(
504: final boolean follow) {
505: final List properties = new ArrayList();
506: if (follow && !this .getGeneralizations().isEmpty()) {
507: for (Iterator iterator = this .getGeneralizations()
508: .iterator(); iterator.hasNext();) {
509: final Object generalization = iterator.next();
510: if (generalization instanceof ClassifierFacade) {
511: properties
512: .addAll(((ClassifierFacade) generalization)
513: .getAllProperties());
514: }
515: }
516: }
517: properties.addAll(this .getAttributes(false));
518: properties.addAll(this .getNavigableConnectingEnds(false));
519: return properties;
520: }
521:
522: protected Collection handleGetOperations() {
523: final Collection operations;
524:
525: if (this .metaObject instanceof org.eclipse.uml2.Class) {
526: operations = ((org.eclipse.uml2.Class) this .metaObject)
527: .getOwnedOperations();
528: } else if (this .metaObject instanceof org.eclipse.uml2.Interface) {
529: operations = new LinkedHashSet(
530: ((org.eclipse.uml2.Interface) this .metaObject)
531: .getOwnedOperations());
532: } else {
533: operations = Collections.EMPTY_LIST;
534: }
535:
536: return operations;
537: }
538:
539: /**
540: * Note: if this instance represents an actual class we resolve any realized interfaces recursively, in case this
541: * instance represents an interface we return only the owned operations.
542: *
543: * @see org.andromda.metafacades.uml.ClassifierFacade#getOperations()
544: */
545: protected java.util.Collection handleGetImplementationOperations() {
546: final Collection operations;
547:
548: if (this .metaObject instanceof org.eclipse.uml2.Class) {
549: operations = new LinkedHashSet(
550: ((org.eclipse.uml2.Class) this .metaObject)
551: .getOwnedOperations());
552:
553: final Collection dependencies = new FilteredCollection(
554: this .metaObject.getClientDependencies()) {
555: public boolean evaluate(Object object) {
556: return object instanceof Abstraction;
557: }
558: };
559:
560: for (Iterator abstractionIterator = dependencies.iterator(); abstractionIterator
561: .hasNext();) {
562: final Abstraction abstraction = (Abstraction) abstractionIterator
563: .next();
564: final List suppliers = abstraction.getSuppliers();
565: for (int i = 0; i < suppliers.size(); i++) {
566: final Object supplierObject = suppliers.get(i);
567: if (supplierObject instanceof Interface) {
568: operations
569: .addAll(resolveInterfaceOperationsRecursively((Interface) supplierObject));
570: }
571: }
572: }
573: } else if (this .metaObject instanceof org.eclipse.uml2.Interface) {
574: operations = new LinkedHashSet(
575: ((org.eclipse.uml2.Interface) this .metaObject)
576: .getOwnedOperations());
577: } else {
578: operations = Collections.EMPTY_LIST;
579: }
580:
581: return operations;
582: }
583:
584: private static Collection resolveInterfaceOperationsRecursively(
585: Interface classifier) {
586: final Collection operations = new LinkedHashSet(classifier
587: .getOwnedOperations()); // preserve ordering
588:
589: final List generals = classifier.getGenerals();
590: for (int i = 0; i < generals.size(); i++) {
591: final Object generalObject = generals.get(i);
592: if (generalObject instanceof Interface) {
593: operations
594: .addAll(resolveInterfaceOperationsRecursively((Interface) generalObject));
595: }
596: }
597:
598: return operations;
599: }
600:
601: /**
602: * @see org.andromda.metafacades.uml.ClassifierFacade#getAttributes()
603: */
604: protected java.util.Collection handleGetAttributes() {
605: return UmlUtilities.getAttributes(this .metaObject, false);
606: }
607:
608: /**
609: * @see org.andromda.metafacades.uml.ClassifierFacade#getAssociationEnds()
610: */
611: protected java.util.List handleGetAssociationEnds() {
612: return UmlUtilities.getAssociationEnds(this .metaObject, false);
613: }
614:
615: /**
616: * @see org.andromda.metafacades.uml.ClassifierFacade#getNonArray()
617: */
618: protected Object handleGetNonArray() {
619: ClassifierFacade nonArrayType = this ;
620:
621: String arraySuffix = this .getArraySuffix();
622:
623: if (this .getFullyQualifiedName().indexOf(arraySuffix) != -1) {
624: PackageFacade rootPF = this .getRootPackage();
625: String fullQualifiedName = this .getFullyQualifiedName(true);
626:
627: if (this .logger.isDebugEnabled()) {
628: this .logger
629: .debug("Looking for non-array type of element "
630: + fullQualifiedName
631: + " with array suffix " + arraySuffix
632: + ", root: " + rootPF);
633: this .logger.debug("Metaobject: " + this .metaObject
634: + " its model is : "
635: + this .metaObject.getModel());
636: }
637: nonArrayType = (ClassifierFacade) rootPF
638: .findModelElement(StringUtils.replace(
639: fullQualifiedName, arraySuffix, ""));
640: }
641: return nonArrayType;
642: }
643:
644: /**
645: * @see org.andromda.metafacades.uml.ClassifierFacade#getArray()
646: */
647: protected Object handleGetArray() {
648: if (this .logger.isDebugEnabled()) {
649: this .logger
650: .debug("Entered getArray for " + this .metaObject);
651: }
652: ClassifierFacade arrayType = this ;
653: if (this .metaObject instanceof PrimitiveType) {
654: String name = this .getFullyQualifiedName(true);
655: if (name.indexOf(this .getArraySuffix()) == -1) {
656: name = name + this .getArraySuffix();
657: arrayType = (ClassifierFacade) this .getRootPackage()
658: .findModelElement(name);
659: }
660: } else {
661: arrayType = null;
662: }
663: return arrayType;
664: }
665:
666: /**
667: * @see org.andromda.metafacades.uml.ClassifierFacade#getStaticAttributes()
668: */
669: protected java.util.Collection handleGetStaticAttributes() {
670: Collection attributes = this .getAttributes();
671: CollectionUtils.filter(attributes, new Predicate() {
672: public boolean evaluate(final Object object) {
673: return ((AttributeFacade) object).isStatic();
674: }
675: });
676:
677: return attributes;
678: }
679:
680: /**
681: * @see org.andromda.metafacades.uml.ClassifierFacade#getInstanceAttributes()
682: */
683: protected java.util.Collection handleGetInstanceAttributes() {
684: Collection attributes = this .getAttributes();
685: CollectionUtils.filter(attributes, new Predicate() {
686: public boolean evaluate(final Object object) {
687: return !((AttributeFacade) object).isStatic();
688: }
689: });
690: return attributes;
691: }
692:
693: /**
694: * @see org.andromda.metafacades.uml.ClassifierFacade#getStaticOperations()
695: */
696: protected java.util.Collection handleGetStaticOperations() {
697: Collection operations = this .getOperations();
698: CollectionUtils.filter(operations, new Predicate() {
699: public boolean evaluate(final Object object) {
700: return ((OperationFacade) object).isStatic();
701: }
702: });
703: return operations;
704: }
705:
706: /**
707: * @see org.andromda.metafacades.uml.ClassifierFacade#getInstanceOperations()
708: */
709: protected java.util.Collection handleGetInstanceOperations() {
710: Collection operations = this .getOperations();
711: CollectionUtils.filter(operations, new Predicate() {
712: public boolean evaluate(final Object object) {
713: return !((OperationFacade) object).isStatic();
714: }
715: });
716: return operations;
717: }
718:
719: /**
720: * @see org.andromda.metafacades.uml.ClassifierFacade#getAbstractions()
721: */
722: protected java.util.Collection handleGetAbstractions() {
723: final Collection dependencies = new ArrayList(this .metaObject
724: .getClientDependencies());
725: CollectionUtils.filter(dependencies, new Predicate() {
726: public boolean evaluate(final Object object) {
727: return object instanceof Abstraction;
728: }
729: });
730: return dependencies;
731: }
732:
733: /**
734: * @see org.andromda.metafacades.uml.ClassifierFacade#getNavigableConnectingEnds()
735: */
736: protected java.util.Collection handleGetNavigableConnectingEnds() {
737: final Collection connectingEnds = new ArrayList(this
738: .getAssociationEnds());
739: CollectionUtils.transform(connectingEnds, new Transformer() {
740: public Object transform(final Object object) {
741: return ((AssociationEndFacade) object).getOtherEnd();
742: }
743: });
744: CollectionUtils.filter(connectingEnds, new Predicate() {
745: public boolean evaluate(final Object object) {
746: return ((AssociationEndFacade) object).isNavigable();
747: }
748: });
749: return connectingEnds;
750: }
751:
752: /**
753: * @see org.andromda.metafacades.uml.ClassifierFacade#getNavigableConnectingEnds(boolean)
754: */
755: protected Collection handleGetNavigableConnectingEnds(
756: final boolean follow) {
757: final Collection connectingEnds = this
758: .shieldedElements(UmlUtilities.getAssociationEnds(
759: this .metaObject, follow));
760: CollectionUtils.transform(connectingEnds, new Transformer() {
761: public Object transform(final Object object) {
762: return ((AssociationEndFacade) object).getOtherEnd();
763: }
764: });
765: CollectionUtils.filter(connectingEnds, new Predicate() {
766: public boolean evaluate(final Object object) {
767: return ((AssociationEndFacade) object).isNavigable();
768: }
769: });
770: return connectingEnds;
771: }
772:
773: protected boolean handleIsLeaf() {
774: return this .metaObject.isLeaf();
775: }
776:
777: protected Collection handleGetInterfaceAbstractions() {
778: final Collection interfaceAbstractions = new LinkedHashSet();
779: if (this .getAbstractions() != null) {
780: for (Iterator abstractionIterator = this .getAbstractions()
781: .iterator(); abstractionIterator.hasNext();) {
782: final DependencyFacade abstraction = (DependencyFacade) abstractionIterator
783: .next();
784: final ModelElementFacade element = abstraction
785: .getTargetElement();
786:
787: if (element instanceof ClassifierFacade) {
788: final ClassifierFacade classifier = (ClassifierFacade) element;
789: if (classifier.isInterface()) {
790: interfaceAbstractions.add(classifier);
791: }
792: }
793: }
794: }
795:
796: return interfaceAbstractions;
797: }
798:
799: protected String handleGetImplementedInterfaceList() {
800: final String interfaceList;
801:
802: final Collection interfaces = this .getInterfaceAbstractions();
803: if (interfaces.isEmpty()) {
804: interfaceList = "";
805: } else {
806: final StringBuffer list = new StringBuffer();
807: for (final Iterator iterator = interfaces.iterator(); iterator
808: .hasNext();) {
809: final ModelElementFacade element = (ModelElementFacade) iterator
810: .next();
811: list.append(element.getFullyQualifiedName());
812: if (iterator.hasNext()) {
813: list.append(", ");
814: }
815: }
816: interfaceList = list.toString();
817: }
818:
819: return interfaceList;
820: }
821:
822: /* protected Object handleFindTaggedValue(final String tagName, final boolean follow)
823: {
824: // TODO: This methode has been overriden. Why ?
825: return null;
826: }
827:
828: protected boolean handleIsBindingDependenciesPresent()
829: {
830: // TODO: This methode has been overriden. Why ?
831: return false;
832: }
833:
834: protected boolean handleIsTemplateParametersPresent()
835: {
836: // TODO: This methode has been overriden. Why ?
837: return false;
838: }
839:
840: protected void handleCopyTaggedValues(final ModelElementFacade element)
841: {
842: // TODO: This methode has been overriden. Why ?
843: }
844:
845: protected Object handleGetTemplateParameter(final String parameterName)
846: {
847: // TODO: This methode has been overriden. Why ?
848: return null;
849: }
850:
851: protected Collection handleGetTemplateParameters()
852: {
853: // TODO: This methode has been overriden. Why ?
854: return null;
855: }*/
856:
857: /**
858: * @see org.andromda.metafacades.emf.uml2.ClassifierFacadeLogic#handleIsAssociationClass()
859: */
860: protected boolean handleIsAssociationClass() {
861: // TODO: Check it's working.
862: return AssociationClass.class.isAssignableFrom(this .metaObject
863: .getClass());
864: }
865:
866: protected Collection handleGetAssociatedClasses() {
867: final Set associatedClasses = new LinkedHashSet();
868:
869: final List associationEnds = this .getAssociationEnds();
870: for (int i = 0; i < associationEnds.size(); i++) {
871: final AssociationEndFacade associationEndFacade = (AssociationEndFacade) associationEnds
872: .get(i);
873: associatedClasses.add(associationEndFacade.getOtherEnd()
874: .getType());
875: }
876:
877: return associatedClasses;
878: }
879:
880: protected Collection handleGetAllAssociatedClasses() {
881: final Set associatedClasses = new LinkedHashSet();
882: associatedClasses.addAll(this .getAssociatedClasses());
883: for (Iterator parentIterator = this .getGeneralizations()
884: .iterator(); parentIterator.hasNext();) {
885: final ClassifierFacade parent = (ClassifierFacade) parentIterator
886: .next();
887: associatedClasses.addAll(parent.getAllAssociatedClasses());
888: }
889:
890: return associatedClasses;
891: }
892:
893: protected Object handleGetSuperClass() {
894: final GeneralizableElementFacade super Class = this
895: .getGeneralization();
896: return super Class instanceof ClassifierFacade ? superClass
897: : null;
898: }
899: }
|