package berlin.reiche.jtriple.converter;

import java.lang.reflect.Field;

import berlin.reiche.jtriple.Binding;
import berlin.reiche.jtriple.rdf.SameAs;

import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.OWL;

public class EnumConverter extends AbstractConverter {

    public EnumConverter(int priority, Binding binding) {
        super(priority, binding);
    }

    @Override
    public void convertEntity(Resource subject, Property predicate,
            Object object) throws Exception {

        Resource newResource = binding.createNewResource(object);
        subject.addProperty(predicate, newResource);

        Field field = object.getClass().getField(((Enum<?>) object).name());
        if (field.isAnnotationPresent(SameAs.class)) {
            for (String uri : field.getAnnotation(SameAs.class).value()) {
                newResource.addProperty(OWL.sameAs, uri);
            }

        }

    }

    @Override
    public boolean canConvert(Class<?> type, Object object) {
        return type.isEnum();
    }

}

@@ -908,24 +908,96 @@
 value()) %7B%0D%0A
+            %09Resource sameAs = binding.getModel().createResource(uri);%0D%0A
             
@@ -1036,19 +1036,22 @@
 sameAs, 
-uri
+sameAs
 );%0D%0A    

Fix owl:sameAs creation