Search in sources :

Example 1 with InjectionProviderException

use of com.sun.faces.spi.InjectionProviderException in project mojarra by eclipse-ee4j.

the class AbstractConfigProcessor method createInstance.

protected Object createInstance(ServletContext sc, FacesContext facesContext, String className, Class<?> rootType, Object root, Node source, boolean performInjection, boolean[] didPerformInjection) {
    Class<?> clazz;
    Object returnObject = null;
    if (className != null) {
        try {
            clazz = loadClass(sc, facesContext, className, returnObject, null);
            if (clazz != null) {
                if (returnObject == null) {
                    // an object to adapt
                    if (rootType != null && root != null) {
                        Constructor<?> construct = lookupConstructor(clazz, rootType);
                        if (construct != null) {
                            returnObject = construct.newInstance(root);
                        }
                    }
                }
                if (clazz != null && returnObject == null) {
                    returnObject = clazz.newInstance();
                }
                ApplicationInstanceFactoryMetadataMap<String, Object> classMetadataMap = getClassMetadataMap(sc);
                if (classMetadataMap.hasAnnotations(className) && performInjection) {
                    InjectionProvider injectionProvider = (InjectionProvider) facesContext.getAttributes().get(INJECTION_PROVIDER_KEY);
                    try {
                        injectionProvider.inject(returnObject);
                    } catch (InjectionProviderException ex) {
                        LOGGER.log(SEVERE, "Unable to inject instance" + className, ex);
                        throw new FacesException(ex);
                    }
                    try {
                        injectionProvider.invokePostConstruct(returnObject);
                    } catch (InjectionProviderException ex) {
                        LOGGER.log(SEVERE, "Unable to invoke @PostConstruct annotated method on instance " + className, ex);
                        throw new FacesException(ex);
                    }
                    didPerformInjection[0] = true;
                }
            }
        } catch (ClassNotFoundException cnfe) {
            throw new ConfigurationException(buildMessage(format("Unable to find class ''{0}''", className), source), cnfe);
        } catch (NoClassDefFoundError ncdfe) {
            throw new ConfigurationException(buildMessage(format("Class ''{0}'' is missing a runtime dependency: {1}", className, ncdfe.toString()), source), ncdfe);
        } catch (ClassCastException cce) {
            throw new ConfigurationException(buildMessage(format("Class ''{0}'' is not an instance of ''{1}''", className, rootType), source), cce);
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | FacesException e) {
            throw new ConfigurationException(buildMessage(format("Unable to create a new instance of ''{0}'': {1}", className, e.toString()), source), e);
        }
    }
    return returnObject;
}
Also used : InjectionProviderException(com.sun.faces.spi.InjectionProviderException) InjectionProvider(com.sun.faces.spi.InjectionProvider) FacesException(jakarta.faces.FacesException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(com.sun.faces.config.ConfigurationException)

Example 2 with InjectionProviderException

use of com.sun.faces.spi.InjectionProviderException in project mojarra by eclipse-ee4j.

the class WebContainerInjectionProvider method invokeAnnotatedMethod.

// --------------------------------------------------------- Private Methods
private static void invokeAnnotatedMethod(Method method, Object managedBean) throws InjectionProviderException {
    if (method != null) {
        boolean accessible = method.isAccessible();
        method.setAccessible(true);
        try {
            method.invoke(managedBean);
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            throw new InjectionProviderException(e.getMessage(), e);
        } finally {
            method.setAccessible(accessible);
        }
    }
}
Also used : InjectionProviderException(com.sun.faces.spi.InjectionProviderException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InjectionProviderException (com.sun.faces.spi.InjectionProviderException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ConfigurationException (com.sun.faces.config.ConfigurationException)1 InjectionProvider (com.sun.faces.spi.InjectionProvider)1 FacesException (jakarta.faces.FacesException)1