001 package com.khubla.pragmatach.plugin.mongodb.serializer; 002 003 import java.lang.reflect.Field; 004 import java.util.Set; 005 006 import javax.persistence.Entity; 007 008 import com.khubla.pragmatach.framework.api.PragmatachException; 009 import com.khubla.pragmatach.plugin.mongodb.util.AtomicTypeUtil; 010 011 /** 012 * @author tom 013 */ 014 public class FieldSerializerFactory { 015 public static FieldSerializer getFieldSerializer(Class<?> clazz, Field field) throws PragmatachException { 016 if (AtomicTypeUtil.isSimpleType(field.getType())) { 017 return new AtomicFieldSerializer(clazz); 018 } else if (field.getType() == Set.class) { 019 return new SetFieldSerializer(clazz); 020 } else if (null != field.getType().getAnnotation(Entity.class)) { 021 return new EntityFieldSerializer(clazz); 022 } else if (field.getType().isEnum()) { 023 return new EnumFieldSerializer(clazz); 024 } else { 025 throw new PragmatachException("Invalid serialization type '" + field.getType().getName() + "' for field '" + field.getName() + "'"); 026 } 027 } 028 }