1 22 23 package org.jboss.web.jsf.integration.injection; 24 25 import com.sun.faces.spi.InjectionProvider; 26 import com.sun.faces.spi.InjectionProviderException; 27 import javax.naming.Context ; 28 import javax.naming.InitialContext ; 29 import org.apache.catalina.util.DefaultAnnotationProcessor; 30 import org.jboss.logging.Logger; 31 32 38 public class JBossInjectionProvider implements InjectionProvider { 39 private static final Logger LOG = Logger.getLogger(JBossInjectionProvider.class); 40 private static final String NAMING_DISABLED = "Injection of naming resources into JSF managed beans disabled."; 41 42 private Context namingContext; 43 private DefaultAnnotationProcessor annotationProcessor = null; 44 45 48 public JBossInjectionProvider() { 49 try { 50 this.namingContext = new InitialContext (); 51 this.annotationProcessor = new DefaultAnnotationProcessor(this.namingContext); 52 } catch (Exception e) { 53 LOG.warn(NAMING_DISABLED, e); 54 } 55 } 56 57 66 protected JBossInjectionProvider(Context namingContext) { 67 if (namingContext == null) { 68 LOG.warn(NAMING_DISABLED); 69 } 70 71 this.namingContext = namingContext; 72 this.annotationProcessor = new DefaultAnnotationProcessor(this.namingContext); 73 } 74 75 78 public void invokePreDestroy(Object managedBean) throws InjectionProviderException { 79 try { 80 annotationProcessor.preDestroy(managedBean); 81 } catch (Exception e) { 82 LOG.error("PreDestroy failed on managed bean.", e); 83 } 84 } 85 86 90 public void inject(Object managedBean) throws InjectionProviderException { 91 if (this.namingContext != null) { 92 try { 93 annotationProcessor.processAnnotations(managedBean); 94 } catch (Exception e) { 95 LOG.error("Injection failed on managed bean.", e); 96 } 97 } 98 99 try { 100 annotationProcessor.postConstruct(managedBean); 101 } catch (Exception e) { 102 LOG.error("PostConstruct failed on managed bean.", e); 103 } 104 } 105 106 } 107 | Popular Tags |