From ebcc7b51b5a141c2bd08ad195dbe9e51d432715d Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Mon, 22 Oct 2018 14:18:03 +0100 Subject: [PATCH] Add OperationResolver --- .../refine/model/OperationResolver.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 main/src/com/google/refine/model/OperationResolver.java diff --git a/main/src/com/google/refine/model/OperationResolver.java b/main/src/com/google/refine/model/OperationResolver.java new file mode 100644 index 000000000..6a12b8db4 --- /dev/null +++ b/main/src/com/google/refine/model/OperationResolver.java @@ -0,0 +1,36 @@ +package com.google.refine.model; + +import java.io.IOException; + +import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; +import com.fasterxml.jackson.databind.DatabindContext; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.jsontype.impl.TypeIdResolverBase; +import com.fasterxml.jackson.databind.type.TypeFactory; + +import com.google.refine.operations.OperationRegistry; + +public class OperationResolver extends TypeIdResolverBase { + + protected TypeFactory factory = TypeFactory.defaultInstance(); + + @Override + public Id getMechanism() { + return Id.NAME; + } + + @Override + public String idFromValue(Object instance) { + return ((AbstractOperation)instance).getOperationId(); + } + + @Override + public String idFromValueAndType(Object instance, Class type) { + return OperationRegistry.s_opClassToName.get(type); + } + + @Override + public JavaType typeFromId(DatabindContext context, String id) throws IOException { + return factory.constructSimpleType(OperationRegistry.resolveOperationId(id), new JavaType[0]); + } +}