001: /*
002: * JBoss, Home of Professional Open Source
003: * Copyright 2005, JBoss Inc., and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jbpm.graph.def;
023:
024: import java.io.Serializable;
025: import java.util.ArrayList;
026: import java.util.List;
027:
028: import org.jbpm.util.EqualsUtil;
029:
030: public class Event implements Serializable {
031:
032: private static final long serialVersionUID = 1L;
033:
034: public static final String EVENTTYPE_TRANSITION = "transition";
035: public static final String EVENTTYPE_BEFORE_SIGNAL = "before-signal";
036: public static final String EVENTTYPE_AFTER_SIGNAL = "after-signal";
037: public static final String EVENTTYPE_PROCESS_START = "process-start";
038: public static final String EVENTTYPE_PROCESS_END = "process-end";
039: public static final String EVENTTYPE_NODE_ENTER = "node-enter";
040: public static final String EVENTTYPE_NODE_LEAVE = "node-leave";
041: public static final String EVENTTYPE_SUPERSTATE_ENTER = "superstate-enter";
042: public static final String EVENTTYPE_SUPERSTATE_LEAVE = "superstate-leave";
043: public static final String EVENTTYPE_SUBPROCESS_CREATED = "subprocess-created";
044: public static final String EVENTTYPE_SUBPROCESS_END = "subprocess-end";
045: public static final String EVENTTYPE_TASK_CREATE = "task-create";
046: public static final String EVENTTYPE_TASK_ASSIGN = "task-assign";
047: public static final String EVENTTYPE_TASK_START = "task-start";
048: public static final String EVENTTYPE_TASK_END = "task-end";
049: public static final String EVENTTYPE_TIMER = "timer";
050:
051: long id = 0;
052: protected String eventType = null;
053: protected GraphElement graphElement = null;
054: protected List actions = null;
055:
056: // constructors /////////////////////////////////////////////////////////////
057:
058: public Event() {
059: }
060:
061: public Event(String eventType) {
062: this .eventType = eventType;
063: }
064:
065: public Event(GraphElement graphElement, String eventType) {
066: this .graphElement = graphElement;
067: this .eventType = eventType;
068: }
069:
070: // actions //////////////////////////////////////////////////////////////////
071:
072: /**
073: * is the list of actions associated to this event.
074: * @return an empty list if no actions are associated.
075: */
076: public List getActions() {
077: return actions;
078: }
079:
080: public boolean hasActions() {
081: return ((actions != null) && (actions.size() > 0));
082: }
083:
084: public Action addAction(Action action) {
085: if (action == null)
086: throw new IllegalArgumentException(
087: "can't add a null action to an event");
088: if (actions == null)
089: actions = new ArrayList();
090: actions.add(action);
091: action.event = this ;
092: return action;
093: }
094:
095: public void removeAction(Action action) {
096: if (action == null)
097: throw new IllegalArgumentException(
098: "can't remove a null action from an event");
099: if (actions != null) {
100: if (actions.remove(action)) {
101: action.event = null;
102: }
103: }
104: }
105:
106: public String toString() {
107: return eventType;
108: }
109:
110: // equals ///////////////////////////////////////////////////////////////////
111: // hack to support comparing hibernate proxies against the real objects
112: // since this always falls back to ==, we don't need to overwrite the hashcode
113: public boolean equals(Object o) {
114: return EqualsUtil.equals(this , o);
115: }
116:
117: // getters and setters //////////////////////////////////////////////////////
118:
119: public String getEventType() {
120: return eventType;
121: }
122:
123: public GraphElement getGraphElement() {
124: return graphElement;
125: }
126:
127: public long getId() {
128: return id;
129: }
130:
131: // private static final Log log = LogFactory.getLog(Event.class);
132: }
|