Ejemplo n.º 1
0
  public static void writeWorkItem(MarshallerWriteContext context, WorkItem workItem)
      throws IOException {
    ObjectOutputStream stream = context.stream;
    stream.writeLong(workItem.getId());
    stream.writeLong(workItem.getProcessInstanceId());
    stream.writeUTF(workItem.getName());
    stream.writeInt(workItem.getState());

    // Work Item Parameters
    Map<String, Object> parameters = workItem.getParameters();
    Collection<Object> notNullValues = new ArrayList<Object>();
    for (Object value : parameters.values()) {
      if (value != null) {
        notNullValues.add(value);
      }
    }

    stream.writeInt(notNullValues.size());
    for (String key : parameters.keySet()) {
      Object object = parameters.get(key);
      if (object != null) {
        stream.writeUTF(key);

        ObjectMarshallingStrategy strategy =
            context.objectMarshallingStrategyStore.getStrategyObject(object);
        String strategyClassName = strategy.getClass().getName();
        stream.writeInt(-2); // backwards compatibility
        stream.writeUTF(strategyClassName);
        if (strategy.accept(object)) {
          strategy.write(stream, object);
        }
      }
    }
  }
 @PreUpdate
 public void update() {
   this.state = workItem.getState();
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   try {
     MarshallerWriteContext context = new MarshallerWriteContext(baos, null, null, null, null);
     OutputMarshaller.writeWorkItem(context, workItem);
     context.close();
     this.workItemByteArray = baos.toByteArray();
   } catch (IOException e) {
     throw new IllegalArgumentException(
         "IOException while storing workItem " + workItem.getId() + ": " + e.getMessage());
   }
 }