1 /*
2 * Copyright 2003 - 2013 The eFaps Team
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Revision: $Rev$
17 * Last Changed: $Date$
18 * Last Changed By: $Author$
19 */
20
21 package org.efaps.bpm.workitem;
22
23 import org.kie.api.runtime.process.WorkItem;
24 import org.kie.api.runtime.process.WorkItemHandler;
25 import org.kie.api.runtime.process.WorkItemManager;
26
27 /**
28 * TODO comment!
29 *
30 * @author The eFaps Team
31 * @version $Id$
32 */
33 public abstract class AbstractExceptionWorkItemHandler
34 implements WorkItemHandler
35 {
36
37 /**
38 * The original Task Handler wrapped for Exception Handling.
39 */
40 private final WorkItemHandler originalTaskHandler;
41
42 /**
43 * @param _originalTaskHandler task handler that will be wrapped in
44 */
45 public AbstractExceptionWorkItemHandler(final WorkItemHandler _originalTaskHandler)
46 {
47 this.originalTaskHandler = _originalTaskHandler;
48 }
49
50 /**
51 * The given work item should be executed.
52 *
53 * @param _workItem the work item that should be executed
54 * @param _manager the manager that requested the work item to be executed
55 */
56 @Override
57 public void executeWorkItem(final WorkItem _workItem,
58 final WorkItemManager _manager)
59 {
60 try {
61 this.originalTaskHandler.executeWorkItem(_workItem, _manager);
62 // CHECKSTYLE:OFF
63 } catch (final Throwable e) {
64 // CHECKSTYLE:ON
65 handleExecuteException(e, _workItem, _manager);
66 }
67 }
68
69 /**
70 * The given work item should be aborted.
71 *
72 * @param _workItem the work item that should be aborted
73 * @param _manager the manager that requested the work item to be aborted
74 */
75 @Override
76 public void abortWorkItem(final WorkItem _workItem,
77 final WorkItemManager _manager)
78 {
79 try {
80 this.originalTaskHandler.abortWorkItem(_workItem, _manager);
81 // CHECKSTYLE:OFF
82 } catch (final Throwable e) {
83 // CHECKSTYLE:ON
84 handleAbortException(e, _workItem, _manager);
85 }
86 }
87
88 /**
89 * @return the original WorkItem
90 */
91 public WorkItemHandler getOriginalTaskHandler()
92 {
93 return this.originalTaskHandler;
94 }
95
96 /**
97 * @param _cause cause of the exception
98 * @param _workItem workitem the exception belongs to
99 * @param _manager manager for the workItem
100 */
101 public abstract void handleExecuteException(final Throwable _cause,
102 final WorkItem _workItem,
103 final WorkItemManager _manager);
104
105 /**
106 * @param _cause cause of the exception
107 * @param _workItem workitem the exception belongs to
108 * @param _manager manager for the workItem
109 */
110 public abstract void handleAbortException(final Throwable _cause,
111 final WorkItem _workItem,
112 final WorkItemManager _manager);
113 }