001: package org.andromda.cartridges.jbpm.metafacades;
002:
003: import org.andromda.utils.StringUtilsHelper;
004: import org.andromda.metafacades.uml.ActivityGraphFacade;
005: import org.andromda.metafacades.uml.EventFacade;
006: import org.andromda.metafacades.uml.StateFacade;
007: import org.andromda.metafacades.uml.StateMachineFacade;
008: import org.andromda.metafacades.uml.TransitionFacade;
009: import org.apache.commons.lang.StringUtils;
010:
011: import java.util.ArrayList;
012: import java.util.Collection;
013: import java.util.Iterator;
014: import java.util.List;
015:
016: /**
017: * MetafacadeLogic implementation for org.andromda.cartridges.jbpm.metafacades.JBpmHandler.
018: *
019: * @see org.andromda.cartridges.jbpm.metafacades.JBpmHandler
020: */
021: public class JBpmHandlerLogicImpl extends JBpmHandlerLogic {
022: public JBpmHandlerLogicImpl(Object metaObject, String context) {
023: super (metaObject, context);
024: }
025:
026: protected boolean handleIsContainedInBusinessProcess() {
027: return this .getOwner().getStateMachineContext() instanceof ActivityGraphFacade
028: && ((ActivityGraphFacade) this .getOwner()
029: .getStateMachineContext()).getUseCase() instanceof JBpmProcessDefinition;
030: }
031:
032: protected boolean handleIsAssignmentHandler() {
033: boolean assignmentHandler = false;
034:
035: final List actions = internalJBpmActions();
036: for (int i = 0; i < actions.size() && !assignmentHandler; i++) {
037: final JBpmAction action = (JBpmAction) actions.get(i);
038: assignmentHandler = action.isTask();
039: }
040:
041: return assignmentHandler;
042: }
043:
044: protected boolean handleIsActionHandler() {
045: boolean actionHandler = false;
046:
047: final List actions = internalJBpmActions();
048: for (int i = 0; i < actions.size() && !actionHandler; i++) {
049: final JBpmAction action = (JBpmAction) actions.get(i);
050: actionHandler = action.isAfterSignal()
051: || action.isBeforeSignal() || action.isNodeEnter()
052: || action.isNodeLeave() || action.isTimer();
053: }
054:
055: return actionHandler;
056: }
057:
058: private List internalActions = null;
059:
060: private List internalJBpmActions() {
061: if (this .internalActions == null) {
062: internalActions = new ArrayList();
063:
064: final StateMachineFacade stateMachine = getOwner()
065: .getStateMachineContext();
066: if (stateMachine instanceof ActivityGraphFacade) {
067: final ActivityGraphFacade graph = (ActivityGraphFacade) stateMachine;
068: final Collection states = graph.getStates();
069: for (final Iterator stateIterator = states.iterator(); stateIterator
070: .hasNext();) {
071: final StateFacade state = (StateFacade) stateIterator
072: .next();
073: final Collection events = state
074: .getDeferrableEvents();
075: for (final Iterator eventIterator = events
076: .iterator(); eventIterator.hasNext();) {
077: final EventFacade event = (EventFacade) eventIterator
078: .next();
079: if (event instanceof JBpmAction) {
080: final JBpmAction action = (JBpmAction) event;
081: if (this .equals(action.getOperation())) {
082: internalActions.add(event);
083: }
084: }
085: }
086: }
087:
088: final Collection transitions = graph.getTransitions();
089: for (final Iterator transitionIterator = transitions
090: .iterator(); transitionIterator.hasNext();) {
091: final TransitionFacade transition = (TransitionFacade) transitionIterator
092: .next();
093: final EventFacade event = transition.getTrigger();
094: if (event != null) {
095: if (event instanceof JBpmAction) {
096: final JBpmAction action = (JBpmAction) event;
097: if (this .equals(action.getOperation())) {
098: internalActions.add(event);
099: }
100: }
101: }
102: }
103: }
104: }
105:
106: return internalActions;
107: }
108:
109: protected String handleGetHandlerPackageName() {
110: return this .getOwner().getPackageName();
111: }
112:
113: protected String handleGetHandlerFullPath() {
114: return StringUtils.replace(this .getClazz(), ".", "/");
115: }
116:
117: protected String handleGetHandlerClassName() {
118: return StringUtilsHelper.upperCamelCaseName(this .getName());
119: }
120:
121: protected String handleGetClazz() {
122: String handlerClass = null;
123:
124: final StringBuffer clazzBuffer = new StringBuffer();
125: if (StringUtils.isNotBlank(this .getHandlerPackageName())) {
126: clazzBuffer.append(this .getHandlerPackageName());
127: clazzBuffer.append('.');
128: }
129: clazzBuffer.append(this.getHandlerClassName());
130: handlerClass = clazzBuffer.toString();
131:
132: return handlerClass;
133: }
134: }
|