View Javadoc
1   package org.andromda.metafacades.uml14;
2   
3   import java.util.Collection;
4   import java.util.Iterator;
5   import org.apache.commons.collections.Predicate;
6   import org.omg.uml.behavioralelements.activitygraphs.ActionState;
7   import org.omg.uml.behavioralelements.activitygraphs.ObjectFlowState;
8   import org.omg.uml.behavioralelements.usecases.UseCase;
9   import org.omg.uml.behavioralelements.activitygraphs.ActivityGraph;
10  
11  /**
12   * Metaclass facade implementation.
13   * @author Bob Fields
14   */
15  public class ActivityGraphFacadeLogicImpl
16      extends ActivityGraphFacadeLogic
17  {
18      private static final long serialVersionUID = 3098736925534206256L;
19  
20      /**
21       * @param metaObject
22       * @param context
23       */
24      public ActivityGraphFacadeLogicImpl(
25          ActivityGraph metaObject,
26          String context)
27      {
28          super(metaObject, context);
29      }
30  
31      /**
32       * @see org.andromda.metafacades.uml.ActivityGraphFacade#getActionStates()
33       */
34      @Override
35      public Collection handleGetActionStates()
36      {
37          final Predicate filter =
38              new Predicate()
39              {
40                  public boolean evaluate(Object object)
41                  {
42                      return object instanceof ActionState;
43                  }
44              };
45          return getSubvertices(filter);
46      }
47  
48      /**
49       * @see org.andromda.metafacades.uml.ActivityGraphFacade#getObjectFlowStates()
50       */
51      @Override
52      public Collection handleGetObjectFlowStates()
53      {
54          final Predicate filter =
55              new Predicate()
56              {
57                  public boolean evaluate(Object object)
58                  {
59                      return object instanceof ObjectFlowState;
60                  }
61              };
62          return getSubvertices(filter);
63      }
64  
65      /**
66       * @see org.andromda.metafacades.uml.ActivityGraphFacade#getUseCase()
67       */
68      @Override
69      protected Object handleGetUseCase()
70      {
71          UseCase stateMachineUseCase = null;
72  
73          final Collection<UseCase> useCases = UML14MetafacadeUtils.getModel().getUseCases().getUseCase().refAllOfType();
74          for (final Iterator<UseCase> useCaseIterator = useCases.iterator();
75               useCaseIterator.hasNext() && stateMachineUseCase == null;)
76          {
77              // loop over all use-cases
78              final UseCase useCase = useCaseIterator.next();
79              if (useCase.getOwnedElement().contains(metaObject))
80              {
81                  stateMachineUseCase = useCase;
82              }
83          }
84  
85          return stateMachineUseCase;
86      }
87  
88      /**
89       * @see org.andromda.metafacades.uml.ActivityGraphFacade#getPartitions()
90       */
91      @Override
92      protected Collection handleGetPartitions()
93      {
94          return metaObject.getPartition();
95      }
96  
97      /**
98       * @see org.andromda.core.metafacade.MetafacadeBase#getValidationOwner()
99       */
100     public Object getValidationOwner()
101     {
102         Object validationOwner = getUseCase();
103 
104         if (validationOwner == null)
105         {
106             validationOwner = getStateMachineContext();
107         }
108         if (validationOwner == null)
109         {
110             validationOwner = getPackage();
111         }
112 
113         return validationOwner;
114     }
115 }