package io.trivium.extension.type;

import io.trivium.glue.TriviumObject;

public interface TypeFactory<T> extends Typed{
    String getName();
    T getInstance(TriviumObject tvm);
    TriviumObject getTriviumObject(T instance);
}

@@ -40,37 +40,145 @@
 ort 
-io.trivium.glue.TriviumObject
+com.google.common.reflect.TypeToken;%0Aimport io.trivium.glue.TriviumObject;%0Aimport io.trivium.glue.om.Element;%0A%0Aimport java.lang.reflect.*
 ;%0A%0Ap
@@ -249,16 +249,24 @@
 ();%0A    
+default 
 T getIns
@@ -289,17 +289,2018 @@
 ect tvm)
-;
+%7B%0A        TypeToken%3CT%3E token = new TypeToken%3CT%3E(getClass())%7B%7D;%0A        Class%3C?%3E aClass  = token.getRawType();%0A        T t = null;%0A        try %7B%0A            t = (T)aClass.newInstance();%0A        %7D catch (Exception ex) %7B%0A            getLogger().error(%22error while constructing typed object%22, ex);%0A        %7D%0A        Field%5B%5D fields = aClass.getDeclaredFields();%0A        Element el = tvm.getData();%0A        for(Field field:fields)%7B%0A%0A            String name = field.getName();%0A            field.setAccessible(true);%0A            try %7B%0A                if(field.getType()==long.class) %7B%0A                    field.setLong(t, Long.parseLong(el.getFirstChild(name).getValue()));%0A                %7Delse if(field.getType()==int.class) %7B%0A                    field.setInt(t, Integer.parseInt(el.getFirstChild(name).getValue()));%0A                %7Delse if(field.getType()==boolean.class) %7B%0A                    field.setBoolean(t, Boolean.parseBoolean(el.getFirstChild(name).getValue()));%0A                %7Delse if(field.getType()==byte.class) %7B%0A                    field.setByte(t, Byte.parseByte(el.getFirstChild(name).getValue()));%0A                %7Delse if(field.getType()==float.class) %7B%0A                    field.setFloat(t, Float.parseFloat(el.getFirstChild(name).getValue()));%0A                %7Delse if(field.getType()==double.class) %7B%0A                    field.setDouble(t, Double.parseDouble(el.getFirstChild(name).getValue()));%0A                %7Delse if(field.getType()==short.class) %7B%0A                    field.setShort(t, Short.parseShort(el.getFirstChild(name).getValue()));%0A                %7Delse if(field.getType()==char.class) %7B%0A                    field.setChar(t, el.getFirstChild(name).getValue().charAt(0));%0A                %7Delse%7B%0A                    //try String%0A                    field.set(t, el.getFirstChild(name).getValue());%0A                %7D%0A            %7Dcatch(Exception ex)%7B%0A                getLogger().error(%22error while building typed object%22,ex);%0A            %7D%0A        %7D%0A        return t;%0A    %7D
 %0A    Tri

support default impl of getInstance for types