1 package org.simantics.scl.commands.internal.serialization;
3 import org.simantics.db.Resource;
4 import org.simantics.scl.commands.internal.StringConverterFactory;
5 import org.simantics.scl.compiler.errors.CompilationErrorFormatter;
6 import org.simantics.scl.compiler.module.repository.ImportFailureException;
7 import org.simantics.scl.compiler.top.SCLExpressionCompilationException;
8 import org.simantics.scl.compiler.types.Type;
9 import org.simantics.scl.runtime.function.Function;
10 import org.simantics.scl.runtime.function.Function2;
12 public class CommandSerializerFactory {
13 @SuppressWarnings("unchecked")
14 public static CommandSerializer create(String name, Type[] parameterTypes) {
15 Function2<Resource,Object,String>[] stringConverters = new Function[parameterTypes.length];
16 for(int i=0;i<parameterTypes.length;++i) {
18 stringConverters[i] = StringConverterFactory.stringConverterFor(parameterTypes[i]);
19 } catch(SCLExpressionCompilationException e) {
20 System.err.println("Failed to create a string converter for type " + parameterTypes[i] + ".");
21 System.err.println(CompilationErrorFormatter.toString(e.getErrors()));
22 return new ErrorSerializer(name);
23 } catch (ImportFailureException e) {
24 System.err.println("Failed to create a string converter for type " + parameterTypes[i] + ".");
25 System.err.println("Didn't find Simantics/GShow/gshow.");
26 return new ErrorSerializer(name);
29 return new CommandSerializerImpl(name, stringConverters);