package org.tylproject.vaadin.addon.utils;

import com.vaadin.addon.jpacontainer.EntityItem;
import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItem;

/**
 * Created by evacchi on 10/02/15.
 */
public class DefaultBeanExtractor implements BeanExtractor {
    @Override
    public Object extract(Object itemId, Item item) throws IllegalArgumentException {

        final Class<?> itemClass = item.getClass();
        final String itemClassName = itemClass.getCanonicalName();
        Object bean;

        // we compare strings so that Java linked does not complain
        // if any of these classes is missing
        if (itemClassName.startsWith("org.vaadin.viritin.")) {
            bean = itemId;
        } else
        if (itemClassName.startsWith("com.vaadin.addon.jpacontainer.")) {
            bean = ((EntityItem<?>)item).getEntity();
        } else
        if (BeanItem.class.isAssignableFrom(item.getClass())) {
            bean = ((BeanItem<?>) item).getBean();
        } else{
            throw new UnsupportedOperationException(
                    "Unknown item type: "+itemClassName);
        }

        return bean;
    }
}

@@ -157,47 +157,166 @@
 em;%0A
-%0A/**%0A * Created by evacchi on 10/02/15.
+import org.vaadin.viritin.DynaBeanItem;%0Aimport org.vaadin.viritin.ListContainer;%0A%0A/**%0A * Extracts bean from an Item, depending on the Container implementation
 %0A */
@@ -542,261 +542,93 @@
     
-final String itemClassName = itemClass.getCanonicalName();%0A        Object bean;%0A%0A        // we compare strings so that Java linked does not complain%0A        // if any of these classes is missing%0A        if (itemClassName.startsWith(%22org.vaadin.viritin.%22
+Object bean;%0A%0A        if (ListContainer.DynaBeanItem.class.isAssignableFrom(itemClass
 )) %7B
@@ -687,64 +687,31 @@
 f (i
-temClassName.startsWith(%22com.vaadin.addon.jpacontainer.%22
+sJPAContainer(itemClass
 )) %7B
@@ -1019,12 +1019,27 @@
 lass
+.getCanonical
 Name
+()
 );%0A 
@@ -1075,10 +1075,220 @@
 ;%0A    %7D%0A
+%0A%0A    protected boolean isJPAContainer(Class%3C?%3E itemClass) %7B%0A        try %7B%0A            return EntityItem.class.isAssignableFrom(itemClass);%0A        %7D catch (NoClassDefFoundError ex) %7B return false; %7D%0A    %7D%0A%0A%0A%0A%0A
 %7D%0A

Migrate bean extractor to more elegant checking