001package org.andromda.cartridges.jbpm.metafacades;
002
003import org.andromda.cartridges.jbpm.JBpmProfile;
004import org.andromda.metafacades.uml.ActivityGraphFacade;
005import org.andromda.metafacades.uml.ModelElementFacade;
006import org.andromda.metafacades.uml.OperationFacade;
007import org.andromda.metafacades.uml.StateMachineFacade;
008import org.apache.commons.lang.StringUtils;
009
010/**
011 * MetafacadeLogic implementation for org.andromda.cartridges.jbpm.metafacades.JBpmAction.
012 *
013 * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction
014 */
015public class JBpmActionLogicImpl
016        extends JBpmActionLogic
017{
018    private static final long serialVersionUID = 34L;
019    /**
020     * @param metaObject
021     * @param context
022     */
023    public JBpmActionLogicImpl(Object metaObject, String context)
024    {
025        super(metaObject, context);
026    }
027
028    /**
029     * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsContainedInBusinessProcess()
030     */
031    protected boolean handleIsContainedInBusinessProcess()
032    {
033        boolean containedInBusinessProcess = false;
034        if (this.getState() != null)
035        {
036            final StateMachineFacade stateMachine = this.getState().getStateMachine();
037            if (stateMachine instanceof ActivityGraphFacade)
038            {
039                final ActivityGraphFacade activityGraph = (ActivityGraphFacade)stateMachine;
040                containedInBusinessProcess = activityGraph.getUseCase() instanceof JBpmProcessDefinition;
041            }
042        }
043        else
044        {
045            containedInBusinessProcess = this.getTransition() instanceof JBpmTransition;
046        }
047        return containedInBusinessProcess;
048    }
049
050    /**
051     * We override this method in order to be able to return the call-event's operation name
052     * when the event's name itself has not been specified.
053     * @return name
054     */
055    @Override
056    public String getName()
057    {
058        String name = super.getName();
059
060        if (StringUtils.isBlank(name))
061        {
062            final ModelElementFacade operation = getOperation();
063            if (operation != null)
064            {
065                name = operation.getName();
066            }
067        }
068
069        return name;
070    }
071
072    /**
073     * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsBeforeSignal()
074     * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#isBeforeSignal()
075     */
076    protected boolean handleIsBeforeSignal()
077    {
078        return this.hasStereotype(JBpmProfile.STEREOTYPE_BEFORE_SIGNAL);
079    }
080
081    /**
082     * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsAfterSignal()
083     * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#isAfterSignal()
084     */
085    protected boolean handleIsAfterSignal()
086    {
087        return this.hasStereotype(JBpmProfile.STEREOTYPE_AFTER_SIGNAL);
088    }
089
090    /**
091     * @see org.andromda.cartridges.jbpm.metafacades.JBpmActionLogic#handleIsNodeEnter()
092     * @see org.andromda.cartridges.jbpm.metafacades.JBpmAction#isNodeEnter()
093     */
094    protected boolean handleIsNodeEnter()
095    {
096        return this.hasStereotype(JBpmProfile.STEREOTYPE_NODE_ENTER);
097    }
098
099    /**
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}