if (!workflowState().equals (State.OPEN)) {
throw new UpdateNotAllowedException
("Process is not in state open.");
}
// verify first to avoid partial change.
ProcessDataInfo sig = getPaProcessDef().contextSignature ();
for (Iterator i = newValues.keySet().iterator(); i.hasNext();) {
String name = (String)i.next();
Object type = sig.get (name);
if (type == null) {
throw new InvalidDataException ("No such data field: " + name);
}
Object v = newValues.get(name);
if (v == null) {
continue;
}
if ((type instanceof ExternalReference)
&& XPDLUtil.isJavaType((ExternalReference)type)) {
Class vc = null;
try {
vc = XPDLUtil.getJavaType((ExternalReference)type);
} catch (ClassNotFoundException e) {
throw (InvalidDataException)
(new InvalidDataException
("Required Java class no longer available: "
+ e.getMessage())).initCause(e);
}
if (vc.isAssignableFrom(v.getClass())) {
continue;
} else {
throw new InvalidDataException
("Context entry " + name + " is "
+ v.getClass().getName() + " must be instance of "
+ vc.getName());
}
}
if ((type instanceof SAXEventBuffer)
|| (type instanceof ExternalReference)
|| type.equals(org.w3c.dom.Element.class)) {
boolean elemList = false;
if (v instanceof List) {
if (((List)v).size() == 0) {
elemList = true;
} else {
Iterator ti = ((List)v).iterator ();
if (ti.next() instanceof Element) {
elemList = true;
}
}
}
if (! ((v instanceof Element)
|| (v instanceof Document)
|| elemList
|| (v instanceof org.w3c.dom.Element)
|| (v instanceof org.w3c.dom.DocumentFragment)
|| (v instanceof org.w3c.dom.Document)
|| (v instanceof SAXEventBuffer))) {
throw new InvalidDataException
("Not a usable XML representation: " + name);
}
continue;
}
if (type instanceof Class) {
Class vc = v.getClass();
if (v instanceof Float) {
vc = Double.class;
} else if (v instanceof Integer) {
vc = Long.class;
}
if (type == Participant.class) {
type = String.class;
}
if (! ((Class)type).isAssignableFrom (vc)) {
throw new InvalidDataException
("Values for data field \"" + name
+ "\" must be of type " + ((Class)type).getName ()
+ " (is " + v.getClass().getName () + ")");
}
continue;
}
throw new InvalidDataException
("Invalid type for data field \"" + name
+ "\": " + ((Class)type).getName ());
}
// now do changes
DOMBuilder builder = null;
ProcessData oldValues = new DefaultProcessData();
for (Iterator i = (new ArrayList (newValues.keySet())).iterator();
i.hasNext();) {
String name = (String)i.next();
oldValues.put(name, getPaProcessData().get(name));
Object v = newValues.get(name);
if (logger.isDebugEnabled ()) {
logger.debug ("Setting context data item " + name + " = " + v);
}
Object type = sig.get (name);
if ((type instanceof ExternalReference)
&& XPDLUtil.isJavaType((ExternalReference)type)) {
// accept literally
} else if (v instanceof Float) {
v = new Double (((Float)v).doubleValue ());