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.Iterator;
027: import java.util.List;
028:
029: import org.jbpm.graph.exe.ExecutionContext;
030: import org.jbpm.util.ClassLoaderUtil;
031:
032: public class ExceptionHandler implements Serializable {
033:
034: private static final long serialVersionUID = 1L;
035:
036: long id = 0;
037: protected String exceptionClassName = null;
038: protected GraphElement graphElement = null;
039: protected List actions = null;
040:
041: public ExceptionHandler() {
042: }
043:
044: public boolean matches(Throwable exception) {
045: boolean matches = true;
046: if (exceptionClassName != null) {
047: Class clazz = ClassLoaderUtil.loadClass(exceptionClassName);
048: if (!clazz.isAssignableFrom(exception.getClass())) {
049: matches = false;
050: }
051: }
052: return matches;
053: }
054:
055: public void handleException(GraphElement graphElement,
056: ExecutionContext executionContext) throws Exception {
057: if (actions != null) {
058: Iterator iter = actions.iterator();
059: while (iter.hasNext()) {
060: Action action = (Action) iter.next();
061: graphElement.executeAction(action, executionContext);
062: }
063: }
064: }
065:
066: // actions
067: /////////////////////////////////////////////////////////////////////////////
068: public List getActions() {
069: return actions;
070: }
071:
072: public void addAction(Action action) {
073: if (actions == null)
074: actions = new ArrayList();
075: actions.add(action);
076: }
077:
078: public void removeAction(Action action) {
079: if (actions != null) {
080: actions.remove(action);
081: }
082: }
083:
084: public void reorderAction(int oldIndex, int newIndex) {
085: if (actions != null) {
086: actions.add(newIndex, actions.remove(oldIndex));
087: }
088: }
089:
090: // getters and setters
091: /////////////////////////////////////////////////////////////////////////////
092:
093: public String getExceptionClassName() {
094: return exceptionClassName;
095: }
096:
097: public void setExceptionClassName(String exceptionClassName) {
098: this .exceptionClassName = exceptionClassName;
099: }
100:
101: public GraphElement getGraphElement() {
102: return graphElement;
103: }
104: }
|