001: package org.andromda.metafacades.emf.uml2;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005: import java.util.Iterator;
006: import java.util.LinkedHashSet;
007: import java.util.Set;
008:
009: import org.andromda.metafacades.uml.GeneralizableElementFacade;
010: import org.andromda.metafacades.uml.ModelElementFacade;
011: import org.eclipse.uml2.Classifier;
012: import org.eclipse.uml2.Generalization;
013:
014: /**
015: * MetafacadeLogic implementation for
016: * org.andromda.metafacades.uml.GeneralizableElementFacade.
017: *
018: * @see org.andromda.metafacades.uml.GeneralizableElementFacade
019: */
020: public class GeneralizableElementFacadeLogicImpl extends
021: GeneralizableElementFacadeLogic {
022: public GeneralizableElementFacadeLogicImpl(final Object metaObject,
023: final String context) {
024: super (metaObject, context);
025: }
026:
027: /**
028: * @see org.andromda.metafacades.uml.GeneralizableElementFacade#getGeneralizationList()
029: */
030: protected java.lang.String handleGetGeneralizationList() {
031: final StringBuffer list = new StringBuffer();
032: if (this .getGeneralizations() != null) {
033: for (final Iterator iterator = this .getGeneralizations()
034: .iterator(); iterator.hasNext();) {
035: final ModelElementFacade element = (ModelElementFacade) iterator
036: .next();
037: list.append(element.getFullyQualifiedName());
038: if (iterator.hasNext()) {
039: list.append(", ");
040: }
041: }
042: }
043: return list.toString();
044: }
045:
046: /**
047: * @see org.andromda.metafacades.uml.GeneralizableElementFacade#getGeneralization()
048: */
049: protected java.lang.Object handleGetGeneralization() {
050: Object parent = null;
051: final Collection generalizations = ((Classifier) this .metaObject)
052: .getGeneralizations();
053: if (generalizations != null && !generalizations.isEmpty()) {
054: parent = ((Generalization) generalizations.iterator()
055: .next()).getGeneral();
056: }
057: return parent;
058: }
059:
060: /**
061: * @see org.andromda.metafacades.uml.GeneralizableElementFacade#getSpecializations()
062: */
063: protected java.util.Collection handleGetSpecializations() {
064: return UmlUtilities
065: .getSpecializations((Classifier) this .metaObject);
066: }
067:
068: /**
069: * @see org.andromda.metafacades.uml.GeneralizableElementFacade#getGeneralizations()
070: */
071: protected java.util.Collection handleGetGeneralizations() {
072: Collection parents = new LinkedHashSet();
073: Collection generalizations = ((Classifier) this .metaObject)
074: .getGeneralizations();
075: if (generalizations != null && !generalizations.isEmpty()) {
076: for (final Iterator iterator = generalizations.iterator(); iterator
077: .hasNext();) {
078: parents.add(((Generalization) iterator.next())
079: .getGeneral());
080: }
081: }
082: return parents;
083: }
084:
085: /**
086: * @see org.andromda.metafacades.uml.GeneralizableElementFacade#getGeneralizationLinks()
087: */
088: protected java.util.Collection handleGetGeneralizationLinks() {
089: return ((Classifier) this .metaObject).getGeneralizations();
090: }
091:
092: /**
093: * @see org.andromda.metafacades.uml.GeneralizableElementFacade#getAllSpecializations()
094: */
095: protected java.util.Collection handleGetAllSpecializations() {
096: final Set allSpecializations = new LinkedHashSet();
097: if (this .getSpecializations() != null) {
098: allSpecializations.addAll(this .getSpecializations());
099: for (final Iterator iterator = this .getSpecializations()
100: .iterator(); iterator.hasNext();) {
101: final GeneralizableElementFacade element = (GeneralizableElementFacade) iterator
102: .next();
103: allSpecializations.addAll(element
104: .getAllSpecializations());
105: }
106: }
107: return allSpecializations;
108: }
109:
110: /**
111: * @see org.andromda.metafacades.uml.GeneralizableElementFacade#getAllGeneralizations()
112: */
113: protected java.util.Collection handleGetAllGeneralizations() {
114: Collection generalizations = new ArrayList();
115: for (GeneralizableElementFacade element = this
116: .getGeneralization(); element != null; element = element
117: .getGeneralization()) {
118: generalizations.add(element);
119: }
120: return generalizations;
121: }
122:
123: protected Object handleFindTaggedValue(final String tagName,
124: final boolean follow) {
125: Object value = this .findTaggedValue(tagName);
126: if (value == null) //TODO: If follow ?
127: {
128: for (GeneralizableElementFacade element = this
129: .getGeneralization(); value == null
130: && element != null; element = element
131: .getGeneralization()) {
132: value = element.findTaggedValue(tagName, follow);
133: }
134: }
135: return value;
136: }
137:
138: protected Object handleGetGeneralizationRoot() {
139: GeneralizableElementFacade generalizableElement = this;
140:
141: while (generalizableElement.getGeneralization() != null) {
142: generalizableElement = generalizableElement
143: .getGeneralization();
144: }
145:
146: return generalizableElement;
147: }
148: }
|