}
public static WorkItem readWorkItem( MarshallerReaderContext context ) throws IOException {
ObjectInputStream stream = context.stream;
WorkItemImpl workItem = new WorkItemImpl();
workItem.setId( stream.readLong() );
workItem.setProcessInstanceId( stream.readLong() );
workItem.setName( stream.readUTF() );
workItem.setState( stream.readInt() );
//WorkItem Paramaters
int nbVariables = stream.readInt();
if (nbVariables > 0) {
for (int i = 0; i < nbVariables; i++) {
String name = stream.readUTF();
try {
int index = stream.readInt();
ObjectMarshallingStrategy strategy = null;
// Old way of retrieving strategy objects
if (index >= 0) {
strategy = context.resolverStrategyFactory.getStrategy( index );
if (strategy == null) {
throw new IllegalStateException( "No strategy of with index " + index + " available." );
}
}
// New way
else if (index == -2) {
String strategyClassName = stream.readUTF();
strategy = context.resolverStrategyFactory.getStrategyObject( strategyClassName );
if (strategy == null) {
throw new IllegalStateException( "No strategy of type " + strategyClassName + " available." );
}
}
Object value = strategy.read( stream );
workItem.setParameter( name,
value );
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(
"Could not reload variable " + name );
}