001: package org.andromda.metafacades.uml14;
002:
003: import java.util.Collection;
004: import java.util.Iterator;
005: import java.util.LinkedHashSet;
006: import java.util.Set;
007:
008: import org.andromda.metafacades.uml.ActivityGraphFacade;
009: import org.andromda.metafacades.uml.ClassifierFacade;
010: import org.andromda.metafacades.uml.UseCaseFacade;
011: import org.apache.commons.collections.Predicate;
012: import org.omg.uml.behavioralelements.activitygraphs.ActionState;
013: import org.omg.uml.behavioralelements.activitygraphs.ActivityGraph;
014: import org.omg.uml.behavioralelements.statemachines.CompositeState;
015: import org.omg.uml.behavioralelements.usecases.UseCase;
016: import org.omg.uml.foundation.core.ModelElement;
017:
018: /**
019: * Metaclass facade implementation.
020: */
021: public class ModelFacadeLogicImpl extends ModelFacadeLogic {
022: // ---------------- constructor -------------------------------
023: public ModelFacadeLogicImpl(org.omg.uml.UmlPackage metaObject,
024: String context) {
025: super (metaObject, context);
026: }
027:
028: /**
029: * @see org.andromda.metafacades.uml.ModelFacade#getRootPackage()
030: */
031: protected Object handleGetRootPackage() {
032: Collection rootPackages = metaObject.getModelManagement()
033: .getModel().refAllOfType();
034: return rootPackages.iterator().next();
035: }
036:
037: /**
038: * @see org.andromda.metafacades.uml.ModelFacade#getAllActors()
039: */
040: protected Collection handleGetAllActors() {
041: return metaObject.getUseCases().getActor().refAllOfType();
042: }
043:
044: /**
045: * @see org.andromda.metafacades.uml.ModelFacade#getAllActionStates()
046: */
047: protected Collection handleGetAllActionStates() {
048: return metaObject.getActivityGraphs().getActionState()
049: .refAllOfType();
050: }
051:
052: /**
053: * @see org.andromda.metafacades.uml.ModelFacade#getAllUseCases()
054: */
055: protected Collection handleGetAllUseCases() {
056: return metaObject.getUseCases().getUseCase().refAllOfType();
057: }
058:
059: /**
060: * @see org.andromda.metafacades.uml.ModelFacade#getAllClasses()
061: */
062: protected Collection handleGetAllClasses() {
063: return metaObject.getCore().getUmlClass().refAllOfType();
064: }
065:
066: /**
067: * @see org.andromda.metafacades.uml.ModelFacade#getAllObjectFlowStates()
068: */
069: protected Collection handleGetAllObjectFlowStates() {
070: return metaObject.getActivityGraphs().getObjectFlowState()
071: .refAllOfType();
072: }
073:
074: /**
075: * @see org.andromda.metafacades.uml.ModelFacade#findUseCaseWithTaggedValueOrHyperlink(java.lang.String, java.lang.String)
076: */
077: protected UseCaseFacade handleFindUseCaseWithTaggedValueOrHyperlink(
078: String tag, String value) {
079: return (UseCaseFacade) shieldedElement(UML14MetafacadeUtils
080: .findUseCaseWithTaggedValueOrHyperlink(tag, value));
081: }
082:
083: /**
084: * @see org.andromda.metafacades.uml.ModelFacade#findClassWithTaggedValueOrHyperlink(java.lang.String, java.lang.String)
085: */
086: protected ClassifierFacade handleFindClassWithTaggedValueOrHyperlink(
087: String tag, String value) {
088: return (ClassifierFacade) shieldedElement(UML14MetafacadeUtils
089: .findClassWithTaggedValueOrHyperlink(tag, value));
090: }
091:
092: /**
093: * @see org.andromda.metafacades.uml.ModelFacade#findActivityGraphByName(java.lang.String)
094: */
095: protected ActivityGraphFacade handleFindActivityGraphByName(
096: String name) {
097: return (ActivityGraphFacade) shieldedElement(UML14MetafacadeUtils
098: .findFirstActivityGraphWithName(name));
099: }
100:
101: /**
102: * @see org.andromda.metafacades.uml.ModelFacade#findActivityGraphByNameAndStereotype(java.lang.String, java.lang.String)
103: */
104: protected ActivityGraphFacade handleFindActivityGraphByNameAndStereotype(
105: String name, String stereotypeName) {
106: return (ActivityGraphFacade) shieldedElement(UML14MetafacadeUtils
107: .findFirstActivityGraphWithNameAndStereotype(name,
108: stereotypeName));
109: }
110:
111: /**
112: * @see org.andromda.metafacades.uml.ModelFacade#findUseCaseByName(java.lang.String)
113: */
114: protected UseCaseFacade handleFindUseCaseByName(String name) {
115: return (UseCaseFacade) shieldedElement(UML14MetafacadeUtils
116: .findFirstUseCaseWithName(name));
117: }
118:
119: /**
120: * @see org.andromda.metafacades.uml.ModelFacade#findUseCaseWithNameAndStereotype(java.lang.String, java.lang.String)
121: */
122: protected UseCaseFacade handleFindUseCaseWithNameAndStereotype(
123: String name, String stereotypeName) {
124: return (UseCaseFacade) shieldedElement(UML14MetafacadeUtils
125: .findFirstUseCaseWithNameAndStereotype(name,
126: stereotypeName));
127: }
128:
129: /**
130: * @see org.andromda.metafacades.uml.ModelFacade#findFinalStatesWithNameOrHyperlink(org.andromda.metafacades.uml.UseCaseFacade)
131: */
132: protected Collection handleFindFinalStatesWithNameOrHyperlink(
133: UseCaseFacade useCase) {
134: UseCase useCaseMetaClass = UML14MetafacadeUtils
135: .getMetaClass(useCase);
136: return shieldedElements(UML14MetafacadeUtils
137: .findFinalStatesWithNameOrHyperlink(useCaseMetaClass));
138: }
139:
140: /**
141: * @see org.andromda.metafacades.uml.ModelFacade#getAllActionStatesWithStereotype(org.andromda.metafacades.uml.ActivityGraphFacade, java.lang.String)
142: */
143: protected Collection handleGetAllActionStatesWithStereotype(
144: ActivityGraphFacade activityGraph, String stereotypeName) {
145: ActivityGraph activityGraphMetaClass = UML14MetafacadeUtils
146: .getMetaClass(activityGraph);
147:
148: CompositeState compositeState = (CompositeState) activityGraphMetaClass
149: .getTop();
150: return filter(compositeState.getSubvertex(),
151: new ActionStateWithStereotypeFilter(stereotypeName));
152: }
153:
154: private final static class ActionStateWithStereotypeFilter
155: implements Predicate {
156: private String stereotypeName = null;
157:
158: public ActionStateWithStereotypeFilter(
159: final String stereotypeName) {
160: this .stereotypeName = stereotypeName;
161: }
162:
163: public boolean evaluate(final Object object) {
164: return (object instanceof ActionState)
165: && UML14MetafacadeUtils.isStereotypePresent(
166: (ModelElement) object, stereotypeName);
167: }
168: }
169:
170: private Collection filter(Collection collection,
171: Predicate collectionFilter) {
172: final Set filteredCollection = new LinkedHashSet();
173: for (final Iterator iterator = collection.iterator(); iterator
174: .hasNext();) {
175: Object object = iterator.next();
176: if (collectionFilter.evaluate(object)) {
177: filteredCollection.add(object);
178: }
179: }
180: return filteredCollection;
181: }
182: }
|