class BeanFactory {

    public static <T> T createBean(final Class<T> clazz) {
        final Class<?> bpClass = tryLoadClassForName("org.apache.deltaspike.core.api.provider.BeanProvider");
        if (bpClass != null) {
            try {
                final Method getContextualReference = bpClass.getMethod("getContextualReference", Class.class, Annotation[].class);
                return clazz.cast(getContextualReference.invoke(null, clazz, new Annotation[0]));
            } catch (final Exception e) {
                // CDI and Deltaspike are not present and configured - fall back
            }
        }

        // XXX: implement lookup for different DI implementations. For now only CDI is supported

        // fall back
        return createInstance(clazz);
    }

    private  BeanFactory();

}