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