Search in sources :

Example 1 with Variable

use of org.jbpm.marshalling.impl.JBPMMessages.Variable in project jbpm by kiegroup.

the class ContentMarshallerHelper method fallbackParse.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Object fallbackParse(MarshallerReaderContext context, Header header, ExtensionRegistry registry) throws Exception {
    Variable parseFrom = JBPMMessages.Variable.parseFrom(header.getPayload(), registry);
    Object value = ProtobufProcessMarshaller.unmarshallVariableValue(context, parseFrom);
    if (value instanceof Map) {
        Map result = new HashMap();
        Map<String, Variable> variablesMap = (Map<String, Variable>) value;
        for (String key : variablesMap.keySet()) {
            result.put(key, ProtobufProcessMarshaller.unmarshallVariableValue(context, variablesMap.get(key)));
        }
        return result;
    }
    return value;
}
Also used : Variable(org.jbpm.marshalling.impl.JBPMMessages.Variable) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Variable

use of org.jbpm.marshalling.impl.JBPMMessages.Variable in project jbpm by kiegroup.

the class ProtobufProcessMarshaller method marshallVariable.

public static Variable marshallVariable(MarshallerWriteContext context, String name, Object value) throws IOException {
    JBPMMessages.Variable.Builder builder = JBPMMessages.Variable.newBuilder().setName(name);
    if (value != null) {
        ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(value);
        Integer index = context.getStrategyIndex(strategy);
        builder.setStrategyIndex(index).setValue(ByteString.copyFrom(strategy.marshal(context.strategyContext.get(strategy), context, value)));
    }
    return builder.build();
}
Also used : Variable(org.jbpm.marshalling.impl.JBPMMessages.Variable) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy)

Example 3 with Variable

use of org.jbpm.marshalling.impl.JBPMMessages.Variable in project jbpm by kiegroup.

the class ProtobufProcessMarshaller method marshallVariablesMap.

public static Variable marshallVariablesMap(MarshallerWriteContext context, Map<String, Object> variables) throws IOException {
    Map<String, Variable> marshalledVariables = new HashMap<String, Variable>();
    for (String key : variables.keySet()) {
        JBPMMessages.Variable.Builder builder = JBPMMessages.Variable.newBuilder().setName(key);
        if (variables.get(key) != null) {
            ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(variables.get(key));
            Integer index = context.getStrategyIndex(strategy);
            builder.setStrategyIndex(index).setValue(ByteString.copyFrom(strategy.marshal(context.strategyContext.get(strategy), context, variables.get(key))));
        }
        marshalledVariables.put(key, builder.build());
    }
    return marshallVariable(context, "variablesMap", marshalledVariables);
}
Also used : Variable(org.jbpm.marshalling.impl.JBPMMessages.Variable) HashMap(java.util.HashMap) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) ByteString(com.google.protobuf.ByteString)

Example 4 with Variable

use of org.jbpm.marshalling.impl.JBPMMessages.Variable in project jbpm by kiegroup.

the class ProtobufProcessMarshaller method unmarshallVariableContainerValue.

public static Map<String, Object> unmarshallVariableContainerValue(MarshallerReaderContext context, JBPMMessages.VariableContainer _variableContiner) throws IOException, ClassNotFoundException {
    Map<String, Object> variables = new HashMap<String, Object>();
    if (_variableContiner.getVariableCount() == 0) {
        return variables;
    }
    for (Variable _variable : _variableContiner.getVariableList()) {
        Object value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
        variables.put(_variable.getName(), value);
    }
    return variables;
}
Also used : Variable(org.jbpm.marshalling.impl.JBPMMessages.Variable) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString)

Aggregations

Variable (org.jbpm.marshalling.impl.JBPMMessages.Variable)4 HashMap (java.util.HashMap)3 ByteString (com.google.protobuf.ByteString)2 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)2 Map (java.util.Map)1