01: /*
02: * JBoss, Home of Professional Open Source
03: * Copyright 2005, JBoss Inc., and individual contributors as indicated
04: * by the @authors tag. See the copyright.txt in the distribution for a
05: * full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jbpm.svc.save;
23:
24: import java.util.Collection;
25: import java.util.Iterator;
26: import java.util.Map;
27:
28: import org.jbpm.JbpmContext;
29: import org.jbpm.JbpmException;
30: import org.jbpm.context.exe.VariableContainer;
31: import org.jbpm.context.exe.VariableInstance;
32: import org.jbpm.context.exe.variableinstance.UnpersistableInstance;
33: import org.jbpm.graph.exe.ProcessInstance;
34:
35: public class CheckUnpersistableVariablesOperation implements
36: SaveOperation {
37:
38: private static final long serialVersionUID = 1L;
39:
40: public void save(ProcessInstance processInstance,
41: JbpmContext jbpmContext) {
42: Collection updatedVariableContainers = VariableContainer
43: .getUpdatedVariableContainers(processInstance);
44: if (updatedVariableContainers != null) {
45:
46: // loop over all updated variable containers
47: Iterator iter = updatedVariableContainers.iterator();
48: while (iter.hasNext()) {
49: VariableContainer variableContainer = (VariableContainer) iter
50: .next();
51: Map variableInstances = variableContainer
52: .getVariableInstances();
53: if (variableInstances != null) {
54:
55: // loop over all variable instances in the container
56: Iterator varInstancesIter = variableInstances
57: .entrySet().iterator();
58: while (varInstancesIter.hasNext()) {
59: Map.Entry entry = (Map.Entry) varInstancesIter
60: .next();
61: String name = (String) entry.getKey();
62: VariableInstance variableInstance = (VariableInstance) entry
63: .getValue();
64:
65: // if the variable is of the unpersistable type... booom!
66: if (variableInstance instanceof UnpersistableInstance) {
67: Object value = variableInstance.getValue();
68: if (value != null) {
69: throw new JbpmException(
70: "variable '"
71: + name
72: + "' in '"
73: + variableContainer
74: + "' contains '"
75: + value
76: + "': type '"
77: + value.getClass()
78: .getName()
79: + "' is unpersistable according to the jbpm.varmapping.xml configuration");
80: } else {
81: throw new JbpmException(
82: "variable '"
83: + name
84: + "' in '"
85: + variableContainer
86: + "' was created with a non persistable value");
87: }
88: }
89: }
90: }
91: }
92: }
93: }
94:
95: // private static Log log = LogFactory.getLog(CheckUnpersistableVariablesOperation.class);
96: }
|