From df92538ab3d83da9839f08b28fc8a67317565463 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 3 Aug 2013 20:21:19 +0200 Subject: wip --- .../persistence/GeneratorConfiguration.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 container-compiler-plugin/src/main/java/io/trygvis/persistence/GeneratorConfiguration.java (limited to 'container-compiler-plugin/src/main/java/io/trygvis/persistence/GeneratorConfiguration.java') diff --git a/container-compiler-plugin/src/main/java/io/trygvis/persistence/GeneratorConfiguration.java b/container-compiler-plugin/src/main/java/io/trygvis/persistence/GeneratorConfiguration.java new file mode 100644 index 0000000..37d8146 --- /dev/null +++ b/container-compiler-plugin/src/main/java/io/trygvis/persistence/GeneratorConfiguration.java @@ -0,0 +1,43 @@ +package io.trygvis.persistence; + +import io.trygvis.container.compiler.CompilerException; +import io.trygvis.container.compiler.model.TypeRef; + +import java.util.Date; +import java.util.Map; +import java.util.TreeMap; + +public class GeneratorConfiguration { + + private final Map primitiveTypeHandlers = new TreeMap<>(); + private final Map typeHandlers = new TreeMap<>(); + + { + typeHandlers.put(new TypeRef(Integer.class), new TypeHandler.IntTypeHandler()); + typeHandlers.put(new TypeRef(Long.class), new TypeHandler.LongTypeHandler()); + typeHandlers.put(new TypeRef(String.class), new TypeHandler.StringTypeHandler()); + typeHandlers.put(new TypeRef(Date.class), new TypeHandler.DateTypeHandler()); + + primitiveTypeHandlers.putAll(typeHandlers); + } + + public void addTypeHandler(TypeRef type, TypeHandler typeHandler) { + typeHandlers.put(type, typeHandler); + } + + public TypeHandler typeHandler(TypeRef type) { + TypeHandler typeHandler = typeHandlers.get(type); + if (typeHandler == null) { + throw new CompilerException("Unsupported field type: " + type.fqName); + } + return typeHandler; + } + + public boolean isPrimitive(TypeRef type) { + return primitiveTypeHandlers.containsKey(type); + } + + public boolean hasTypeHandler(TypeRef type) { + return typeHandlers.containsKey(type); + } +} -- cgit v1.2.3