/** searches for an event up the process element parent hierarchy starting * from the given process element and returns an event or null if no such * event exists. */ EventImpl findEvent(String eventName, ObservableElementImpl observableElement) { EventImpl event = null; while ( (event==null) && (observableElement!=null) ) { event = (EventImpl) observableElement.getEvent(eventName); if (event==null) { observableElement = observableElement.getParent(); } } return event; }
/** collects the full stack of parent in a list. This node is the * first element in the chain. The process definition will be the last element. * the chain will never be null. */ public List<ObservableElementImpl> getParentChain() { List<ObservableElementImpl> chain = new ArrayList<ObservableElementImpl>(); ObservableElementImpl processElement = this; while (processElement!=null) { chain.add(processElement); processElement = processElement.getParent(); } return chain; }
public boolean hasEvent(String eventName) { return (getEvent(eventName)!=null); }
/** event factory method that also establishes the bidirectional relation. */ public EventImpl createEvent(String eventName) { EventImpl event = new EventImpl(); event.setName(eventName); return addEvent(event); }
/** adds a configuration to the current process element */ public ProcessFactory property(Descriptor descriptor) { if (exceptionHandler!=null) { throw new PvmException("exceptionHandler needs to be closed with exceptionHandlerEnd"); } if (observableElement==null) { throw new PvmException("no current process element"); } if (event!=null) { event.addProperty(descriptor); } else { observableElement.addProperty(descriptor); } return this; }
/** creates the given event on the current process element. * This method requires a process element. A process element is * either a process definition or a node. This method doesn't need to be * called for transitions. If you have exception handlers and listeners * on an event, make sure that you put the invocations of * {@link #exceptionHandler(Class)} first. */ public ProcessFactory event(String eventName) { if (exceptionHandler!=null) { throw new PvmException("exceptionHandler needs to be closed with exceptionHandlerEnd"); } if (observableElement==null) { throw new PvmException("no current process element"); } if (observableElement instanceof Transition) { throw new PvmException("for actions on transitions, you don't need to call event"); } event = observableElement.createEvent(eventName); exceptionHandler = null; return this; }
&& (! transitionParent.equals(processDefinition)) ) { node = (NodeImpl) processDefinition.findNode(transitionParent.getName());
/** this method enables specific process languages to overwrite the event propagation behaviour */ protected void propagateEvent(String eventName, ObservableElement eventSource, ObservableElementImpl observableElement) { fire(eventName, eventSource, observableElement.getParent()); }
/** fires the event on the given *processElement* and then propagates the event * up to the *processElement* parent chain. */ void fire(String eventName, ObservableElement eventSource, ObservableElementImpl observableElement) { if (observableElement!=null) { EventImpl event = (EventImpl) observableElement.getEvent(eventName); if (event!=null) { if (log.isTraceEnabled()) { if (observableElement==eventSource) { log.trace("firing "+event+" on "+eventSource); } else { log.trace("firing "+event+" on "+observableElement+", propagated from source "+eventSource); } } fire(event, eventSource, observableElement); } propagateEvent(eventName, eventSource, observableElement); } }
observableElement = observableElement.getParent();