View Javadoc
1   package org.andromda.cartridges.jbpm.metafacades;
2   
3   import org.andromda.cartridges.jbpm.JBpmProfile;
4   import org.andromda.metafacades.uml.ActivityGraphFacade;
5   import org.andromda.metafacades.uml.ModelElementFacade;
6   import org.andromda.metafacades.uml.OperationFacade;
7   import org.andromda.metafacades.uml.StateMachineFacade;
8   import org.apache.commons.lang.StringUtils;
9   
10  /**
11   * MetafacadeLogic implementation for org.andromda.cartridges.jbpm.metafacades.JBpmAction.
12   *
13   * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction
14   */
15  public class JBpmActionLogicImpl
16          extends JBpmActionLogic
17  {
18      private static final long serialVersionUID = 34L;
19      /**
20       * @param metaObject
21       * @param context
22       */
23      public JBpmActionLogicImpl(Object metaObject, String context)
24      {
25          super(metaObject, context);
26      }
27  
28      /**
29       * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsContainedInBusinessProcess()
30       */
31      protected boolean handleIsContainedInBusinessProcess()
32      {
33          boolean containedInBusinessProcess = false;
34          if (this.getState() != null)
35          {
36              final StateMachineFacade stateMachine = this.getState().getStateMachine();
37              if (stateMachine instanceof ActivityGraphFacade)
38              {
39                  final ActivityGraphFacade activityGraph = (ActivityGraphFacade)stateMachine;
40                  containedInBusinessProcess = activityGraph.getUseCase() instanceof JBpmProcessDefinition;
41              }
42          }
43          else
44          {
45              containedInBusinessProcess = this.getTransition() instanceof JBpmTransition;
46          }
47          return containedInBusinessProcess;
48      }
49  
50      /**
51       * We override this method in order to be able to return the call-event's operation name
52       * when the event's name itself has not been specified.
53       * @return name
54       */
55      @Override
56      public String getName()
57      {
58          String name = super.getName();
59  
60          if (StringUtils.isBlank(name))
61          {
62              final ModelElementFacade operation = getOperation();
63              if (operation != null)
64              {
65                  name = operation.getName();
66              }
67          }
68  
69          return name;
70      }
71  
72      /**
73       * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsBeforeSignal()
74       * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#isBeforeSignal()
75       */
76      protected boolean handleIsBeforeSignal()
77      {
78          return this.hasStereotype(JBpmProfile.STEREOTYPE_BEFORE_SIGNAL);
79      }
80  
81      /**
82       * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsAfterSignal()
83       * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#isAfterSignal()
84       */
85      protected boolean handleIsAfterSignal()
86      {
87          return this.hasStereotype(JBpmProfile.STEREOTYPE_AFTER_SIGNAL);
88      }
89  
90      /**
91       * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsNodeEnter()
92       * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#isNodeEnter()
93       */
94      protected boolean handleIsNodeEnter()
95      {
96          return this.hasStereotype(JBpmProfile.STEREOTYPE_NODE_ENTER);
97      }
98  
99      /**
100      * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsNodeLeave()
101      * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#isNodeLeave()
102      */
103     protected boolean handleIsNodeLeave()
104     {
105         return this.hasStereotype(JBpmProfile.STEREOTYPE_NODE_LEAVE);
106     }
107 
108     /**
109      * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsTask()
110      * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#isTask()
111      */
112     protected boolean handleIsTask()
113     {
114         // tasks may only be used on a node, not on a wait-state
115         return this.hasStereotype(JBpmProfile.STEREOTYPE_TASK) && this.getState() instanceof JBpmNode;
116     }
117 
118     /**
119      * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsTimer()
120      * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#isTimer()
121      */
122     protected boolean handleIsTimer()
123     {
124         return this.hasStereotype(JBpmProfile.STEREOTYPE_TIMER);
125     }
126 
127     /**
128      * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsBlocking()
129      * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#isBlocking()
130      */
131     protected boolean handleIsBlocking()
132     {
133         final String blocking = (String)this.findTaggedValue(JBpmProfile.TAGGEDVALUE_TASK_BLOCKING);
134         return blocking == null || Boolean.valueOf(blocking).booleanValue();
135     }
136 
137     /**
138      * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleGetDueDate()
139      * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#getDueDate()
140      */
141     protected String handleGetDueDate()
142     {
143         return isTimer() ? (String)findTaggedValue(JBpmProfile.TAGGEDVALUE_TIMER_DUEDATE) : null;
144     }
145 
146     /**
147      * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleGetTimerRepeat()
148      */
149     protected String handleGetTimerRepeat()
150     {
151         return (String)findTaggedValue(JBpmProfile.TAGGEDVALUE_TIMER_REPEAT);
152     }
153 
154     /**
155      * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleGetTimerTransition()
156      */
157     protected String handleGetTimerTransition()
158     {
159         return (String)findTaggedValue(JBpmProfile.TAGGEDVALUE_TIMER_TRANSITION);
160     }
161 
162     /**
163      * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleGetClazz()
164      * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#getClazz()
165      */
166     protected String handleGetClazz()
167     {
168         String clazz = null;
169         if (this.isAssignment() || this.isTimer())
170         {
171             final OperationFacade handler = this.getOperation();
172 
173             if (handler instanceof JBpmHandler)
174             {
175                 final StringBuilder clazzBuffer = new StringBuilder();
176                 final String packageName = handler.getOwner().getPackageName();
177                 clazzBuffer.append(packageName);
178                 if (StringUtils.isNotBlank(packageName))
179                 {
180                     clazzBuffer.append('.');
181                 }
182                 clazzBuffer.append(((JBpmHandler)handler).getHandlerClassName());
183                 clazz = clazzBuffer.toString();
184             }
185         }
186 
187         return clazz;
188     }
189 
190     /**
191      * return null
192      * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleGetConfigType()
193      * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#getConfigType()
194      */
195     protected String handleGetConfigType()
196     {
197         // TODO
198         return null;
199     }
200 
201     /**
202      * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsAssignment()
203      * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#isAssignment()
204      */
205     protected boolean handleIsAssignment()
206     {
207         return this.getOperation() != null;
208     }
209 }