001: package org.andromda.metafacades.emf.uml2;
002:
003: import java.util.Collection;
004: import java.util.Collections;
005: import java.util.Iterator;
006:
007: import org.andromda.metafacades.uml.ActionStateFacade;
008: import org.andromda.metafacades.uml.ActivityGraphFacade;
009: import org.andromda.metafacades.uml.UseCaseFacade;
010: import org.apache.commons.collections.CollectionUtils;
011: import org.apache.commons.collections.Predicate;
012: import org.eclipse.uml2.Actor;
013: import org.eclipse.uml2.FinalState;
014: import org.eclipse.uml2.State;
015: import org.eclipse.uml2.StateMachine;
016: import org.eclipse.uml2.UseCase;
017:
018: /**
019: * MetafacadeLogic implementation for org.andromda.metafacades.uml.ModelFacade.
020: *
021: * @see org.andromda.metafacades.uml.ModelFacade
022: */
023: public class ModelFacadeLogicImpl extends ModelFacadeLogic {
024: public ModelFacadeLogicImpl(
025: final org.eclipse.uml2.util.UML2Resource metaObject,
026: final String context) {
027: super (metaObject, context);
028: }
029:
030: /**
031: * @see org.andromda.metafacades.uml.ModelFacade#findUseCaseWithTaggedValueOrHyperlink(java.lang.String,
032: * java.lang.String)
033: */
034: protected org.andromda.metafacades.uml.UseCaseFacade handleFindUseCaseWithTaggedValueOrHyperlink(
035: final java.lang.String tag, final java.lang.String value) {
036: // TODO
037: throw new UnsupportedOperationException();
038: }
039:
040: /**
041: *
042: * @see org.andromda.metafacades.uml.ModelFacade#findClassWithTaggedValueOrHyperlink(java.lang.String,
043: * java.lang.String)
044: */
045: protected org.andromda.metafacades.uml.ClassifierFacade handleFindClassWithTaggedValueOrHyperlink(
046: final java.lang.String tag, final java.lang.String value) {
047: // TODO
048: throw new UnsupportedOperationException();
049: }
050:
051: /**
052: * @see org.andromda.metafacades.uml.ModelFacade#findActivityGraphByName(java.lang.String)
053: */
054: protected org.andromda.metafacades.uml.ActivityGraphFacade handleFindActivityGraphByName(
055: final java.lang.String name) {
056: return this .findActivityGraphByNameAndStereotype(name, null);
057: }
058:
059: /**
060: * @see org.andromda.metafacades.uml.ModelFacade#findActivityGraphByNameAndStereotype(java.lang.String,
061: * java.lang.String)
062: */
063: protected org.andromda.metafacades.uml.ActivityGraphFacade handleFindActivityGraphByNameAndStereotype(
064: final java.lang.String name,
065: final java.lang.String stereotypeName) {
066: ActivityGraphFacade agfFound = null;
067:
068: Collection agfCollection = UmlUtilities
069: .getAllMetaObjectsInstanceOf(StateMachine.class,
070: UmlUtilities.findModel(this .metaObject));
071:
072: for (Iterator it = agfCollection.iterator(); it.hasNext()
073: && agfFound == null;) {
074: ActivityGraphFacade agf = (ActivityGraphFacade) this
075: .shieldedElement(it.next());
076: if (agf.getName().equals(name)) {
077: if (stereotypeName == null
078: || agf.hasStereotype(stereotypeName)) {
079: agfFound = agf;
080: }
081: }
082: }
083: return agfFound;
084: }
085:
086: /**
087: * @see org.andromda.metafacades.uml.ModelFacade#findUseCaseByName(java.lang.String)
088: */
089: protected org.andromda.metafacades.uml.UseCaseFacade handleFindUseCaseByName(
090: final java.lang.String name) {
091: return this .findUseCaseWithNameAndStereotype(name, null);
092: }
093:
094: /**
095: * @see org.andromda.metafacades.uml.ModelFacade#findUseCaseWithNameAndStereotype(java.lang.String,
096: * java.lang.String)
097: */
098: protected org.andromda.metafacades.uml.UseCaseFacade handleFindUseCaseWithNameAndStereotype(
099: final java.lang.String name,
100: final java.lang.String stereotypeName) {
101: UseCaseFacade ucfFound = null;
102: Collection ucCollections = this .getAllUseCases();
103: for (Iterator it = ucCollections.iterator(); it.hasNext()
104: && ucfFound == null;) {
105: UseCaseFacade ucf = (UseCaseFacade) it.next();
106: if (ucf.getName().equals(name)) {
107: if (stereotypeName == null
108: || ucf.hasStereotype(stereotypeName)) {
109: ucfFound = ucf;
110: }
111: }
112: }
113: return ucfFound;
114: }
115:
116: /**
117: * @see org.andromda.metafacades.uml.ModelFacade#findFinalStatesWithNameOrHyperlink(org.andromda.metafacades.uml.UseCaseFacade)
118: */
119: protected java.util.Collection handleFindFinalStatesWithNameOrHyperlink(
120: final org.andromda.metafacades.uml.UseCaseFacade useCase) {
121: Collection fsCollection = UmlUtilities
122: .getAllMetaObjectsInstanceOf(FinalState.class,
123: UmlUtilities.findModel(this .metaObject));
124: CollectionUtils.filter(fsCollection, new Predicate() {
125: public boolean evaluate(final Object candidate) {
126: FinalState fs = (FinalState) candidate;
127: return fs.getName().equals(useCase.getName());
128: }
129: });
130:
131: return fsCollection;
132: }
133:
134: /**
135: * @see org.andromda.metafacades.uml.ModelFacade#getAllActionStatesWithStereotype(org.andromda.metafacades.uml.ActivityGraphFacade,
136: * java.lang.String)
137: */
138: protected java.util.Collection handleGetAllActionStatesWithStereotype(
139: final org.andromda.metafacades.uml.ActivityGraphFacade activityGraph,
140: final java.lang.String stereotypeName) {
141: Collection asCollection = this .getAllActionStates();
142: CollectionUtils.filter(asCollection, new Predicate() {
143: public boolean evaluate(final Object candidate) {
144: ActionStateFacade asf = (ActionStateFacade) candidate;
145: return asf.hasStereotype(stereotypeName)
146: && asf.getPartition().getActivityGraph()
147: .equals(activityGraph);
148: }
149: });
150:
151: return asCollection;
152: }
153:
154: /**
155: * @see org.andromda.metafacades.uml.ModelFacade#getRootPackage()
156: */
157: protected java.lang.Object handleGetRootPackage() {
158: Object model = UmlUtilities.findModel(this .metaObject);
159: if (this .logger.isDebugEnabled()) {
160: this .logger.debug("Root package " + model);
161: }
162: return model;
163: }
164:
165: /**
166: * @see org.andromda.metafacades.uml.ModelFacade#getAllActors()
167: */
168: protected java.util.Collection handleGetAllActors() {
169: return UmlUtilities.getAllMetaObjectsInstanceOf(Actor.class,
170: UmlUtilities.findModel(this .metaObject));
171: }
172:
173: /**
174: * @see org.andromda.metafacades.uml.ModelFacade#getAllUseCases()
175: */
176: protected java.util.Collection handleGetAllUseCases() {
177: return UmlUtilities.getAllMetaObjectsInstanceOf(UseCase.class,
178: UmlUtilities.findModel(this .metaObject));
179: }
180:
181: /**
182: * @see org.andromda.metafacades.uml.ModelFacade#getAllActionStates()
183: */
184: protected java.util.Collection handleGetAllActionStates() {
185: // cf documentation, action states are mapped to uml2 normal state
186: Collection allActionStates = UmlUtilities
187: .getAllMetaObjectsInstanceOf(State.class, UmlUtilities
188: .findModel(this .metaObject));
189: CollectionUtils.filter(allActionStates, new Predicate() {
190: public boolean evaluate(final Object candidate) {
191: return (!(candidate instanceof FinalState));
192: }
193: });
194: return allActionStates;
195: }
196:
197: /**
198: * @see org.andromda.metafacades.uml.ModelFacade#getAllObjectFlowStates()
199: */
200: protected java.util.Collection handleGetAllObjectFlowStates() {
201: // TODO: Not implemented
202: return Collections.EMPTY_LIST;
203: }
204:
205: /**
206: * @see org.andromda.metafacades.uml.ModelFacade#getAllClasses()
207: */
208: protected java.util.Collection handleGetAllClasses() {
209: return UmlUtilities.getAllMetaObjectsInstanceOf(
210: org.eclipse.uml2.Class.class, UmlUtilities
211: .findModel(this.metaObject));
212: }
213: }
|