001: package org.andromda.metafacades.uml14;
002:
003: import org.apache.commons.collections.Predicate;
004: import org.omg.uml.behavioralelements.statemachines.FinalState;
005: import org.omg.uml.behavioralelements.statemachines.CompositeState;
006: import org.omg.uml.behavioralelements.statemachines.Pseudostate;
007: import org.omg.uml.behavioralelements.statemachines.State;
008: import org.omg.uml.foundation.datatypes.PseudostateKindEnum;
009: import org.andromda.metafacades.uml.PseudostateFacade;
010:
011: import java.util.Collection;
012: import java.util.Set;
013: import java.util.LinkedHashSet;
014: import java.util.Iterator;
015:
016: /**
017: * MetafacadeLogic implementation for org.andromda.metafacades.uml.StateMachineFacade.
018: *
019: * @see org.andromda.metafacades.uml.StateMachineFacade
020: */
021: public class StateMachineFacadeLogicImpl extends
022: StateMachineFacadeLogic {
023:
024: public StateMachineFacadeLogicImpl(
025: org.omg.uml.behavioralelements.statemachines.StateMachine metaObject,
026: String context) {
027: super (metaObject, context);
028: }
029:
030: /**
031: * @see org.andromda.metafacades.uml.StateMachineFacade#getContextElement()
032: */
033: protected java.lang.Object handleGetContextElement() {
034: return metaObject.getContext();
035: }
036:
037: /**
038: * @see org.andromda.metafacades.uml.StateMachineFacade#getFinalStates()
039: */
040: protected java.util.Collection handleGetFinalStates() {
041: final Predicate filter = new Predicate() {
042: public boolean evaluate(Object object) {
043: return object instanceof FinalState;
044: }
045: };
046: return getSubvertices(filter);
047: }
048:
049: /**
050: * @see org.andromda.metafacades.uml.StateMachineFacade#getStates()
051: */
052: protected java.util.Collection handleGetStates() {
053: final Predicate filter = new Predicate() {
054: public boolean evaluate(Object object) {
055: return object instanceof State;
056: }
057: };
058: return getSubvertices(filter);
059: }
060:
061: /**
062: * @see org.andromda.metafacades.uml.StateMachineFacade#getInitialTransition()
063: */
064: protected java.lang.Object handleGetInitialTransition() {
065: Object transition = null;
066:
067: final PseudostateFacade initialState = getInitialState();
068: if (initialState != null) {
069: final Collection transitions = initialState.getOutgoing();
070: if (!transitions.isEmpty()) {
071: transition = transitions.iterator().next();
072: }
073: }
074:
075: return transition;
076: }
077:
078: /**
079: * @see org.andromda.metafacades.uml.StateMachineFacade#getTransitions()
080: */
081: protected java.util.Collection handleGetTransitions() {
082: return metaObject.getTransitions();
083: }
084:
085: /**
086: * @see org.andromda.metafacades.uml.StateMachineFacade#getInitialStates()
087: */
088: protected java.util.Collection handleGetInitialStates() {
089: final Predicate filter = new Predicate() {
090: public boolean evaluate(Object object) {
091: return (object instanceof Pseudostate)
092: && (PseudostateKindEnum.PK_INITIAL
093: .equals(((Pseudostate) object)
094: .getKind()));
095: }
096: };
097: return getSubvertices(filter);
098: }
099:
100: /**
101: * @see org.andromda.metafacades.uml.StateMachineFacade#getInitialState()
102: */
103: protected java.lang.Object handleGetInitialState() {
104: Object initialState = null;
105:
106: final Collection initialStates = getInitialStates();
107: if (!initialStates.isEmpty()) {
108: initialState = initialStates.iterator().next();
109: }
110:
111: return initialState;
112: }
113:
114: /**
115: * @see org.andromda.metafacades.uml.StateMachineFacade#getPseudostates()
116: */
117: protected java.util.Collection handleGetPseudostates() {
118: final Predicate filter = new Predicate() {
119: public boolean evaluate(Object object) {
120: return (object instanceof Pseudostate);
121: }
122: };
123: return getSubvertices(filter);
124: }
125:
126: protected Collection getSubvertices(Predicate collectionFilter) {
127: final CompositeState compositeState = (CompositeState) metaObject
128: .getTop();
129: return filter(compositeState.getSubvertex(), collectionFilter);
130: }
131:
132: private Collection filter(Collection collection,
133: Predicate collectionFilter) {
134: final Set filteredCollection = new LinkedHashSet();
135: for (final Iterator iterator = collection.iterator(); iterator
136: .hasNext();) {
137: final Object object = iterator.next();
138: if (collectionFilter.evaluate(object)) {
139: filteredCollection.add(object);
140: }
141: }
142: return filteredCollection;
143: }
144:
145: public Object getValidationOwner() {
146: return getPackage();
147: }
148: }
|