blob: 2bbc425df2fb902d8fa0cf18fdb3919627a23d50 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*
*/
package org.eclipse.osbp.vaaclipse.addons.softwarefactory.bpmImpl;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.osbp.dsl.common.datatypes.IDto;
import org.jbpm.task.query.TaskSummary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BPMTaskVariablesCache {
private static Logger log = LoggerFactory.getLogger(BPMTaskVariablesCache.class);
private final Map<Long,Map<String, Object>> cache;
protected BPMTaskVariablesCache() {
cache = new HashMap<Long, Map<String,Object>>();
}
protected void clear(long taskId) {
log.debug("clear for task:"+taskId);
cache.remove(taskId);
}
protected boolean contains(Object taskInformationObject) {
return cache.containsKey(getProcessInstanceId(taskInformationObject));
}
protected Map<String,Object> initialize(Object taskInformationObject, Map<String, Object> source) {
Map<String,Object> variables = new HashMap<String, Object>();
long taskId = getProcessInstanceId(taskInformationObject);
log.debug("init for task:"+taskId);
if (source != null) {
variables.putAll(source);
}
cache.put(taskId, variables);
return variables;
}
protected Map<String,Object> getVariables(Object taskInformationObject) {
long taskId = getProcessInstanceId(taskInformationObject);
log.debug("got for task:"+taskId);
return cache.get(taskId);
}
protected Object getVariable(Object taskInformationObject, String variable) {
long taskId = getProcessInstanceId(taskInformationObject);
log.debug("got for task:"+taskId+" variable:"+variable);
Object value = cache.get(taskId).get(variable);
// if (value instanceof IDto) {
// ticket576_testSerializeObject((IDto) value);
// }
return value;
}
protected void setVariable(Object taskInformationObject, String variable, Object value) {
// if (value instanceof IDto) {
// ticket576_testSerializeObject((IDto) value);
// }
long taskId = getProcessInstanceId(taskInformationObject);
log.debug("set for task:"+taskId+" variable:"+variable);
getVariables(taskInformationObject).put(variable, value);
}
protected static long getProcessInstanceId(Object taskInformationObject) {
if (taskInformationObject instanceof Long) {
return (Long) taskInformationObject;
}
else if (taskInformationObject instanceof Integer) {
return (Integer) taskInformationObject;
}
else if (taskInformationObject instanceof TaskSummary) {
return ((TaskSummary) taskInformationObject).getProcessInstanceId();
}
return 0;
}
// protected static void ticket576_testSerializeObject(Object object) {
// if (object != null) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(object);
// out.flush();
// }
// catch (Exception et) {
// log.error("ticket576_testSerializeDto("+object.getClass().getCanonicalName()+")", et);
// }
// finally {
// try {
// bos.close();
// }
// catch (Exception et) {
// log.error("ticket576_testSerializeDto("+object.getClass().getCanonicalName()+")", et);
// }
// }
// }
// }
}