From 6842c70f307b15a239f8298749507b1ab8b6fd90 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Wed, 14 Jul 2010 21:42:18 +0000 Subject: [PATCH] --- .../org/wamblee/cdi/BeanManagerLookup.java | 2 +- .../main/java/org/wamblee/cdi/Injectable.java | 4 +++- .../java/org/wamblee/cdi/SimpleInjector.java | 21 ++++++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/support/cdi/src/main/java/org/wamblee/cdi/BeanManagerLookup.java b/support/cdi/src/main/java/org/wamblee/cdi/BeanManagerLookup.java index 29526538..50bed00a 100644 --- a/support/cdi/src/main/java/org/wamblee/cdi/BeanManagerLookup.java +++ b/support/cdi/src/main/java/org/wamblee/cdi/BeanManagerLookup.java @@ -35,7 +35,7 @@ public class BeanManagerLookup { private static final Logger LOGGER = Logger .getLogger(BeanManagerLookup.class.getName()); - private static final String BEAN_MANAGER_JNDI = "java:comp/BeanManager"; + public static final String BEAN_MANAGER_JNDI = "java:comp/BeanManager"; private static BeanManager mgr = null; /** diff --git a/support/cdi/src/main/java/org/wamblee/cdi/Injectable.java b/support/cdi/src/main/java/org/wamblee/cdi/Injectable.java index 6e9f7b8c..2a9a8e88 100644 --- a/support/cdi/src/main/java/org/wamblee/cdi/Injectable.java +++ b/support/cdi/src/main/java/org/wamblee/cdi/Injectable.java @@ -26,11 +26,13 @@ package org.wamblee.cdi; * @author Erik Brakkee */ public abstract class Injectable { + + private static final SimpleInjector INJECTOR = new SimpleInjector(); /** * Inheritance style constructor. */ protected Injectable() { - SimpleInjector.inject(this); + INJECTOR.inject(this); } } diff --git a/support/cdi/src/main/java/org/wamblee/cdi/SimpleInjector.java b/support/cdi/src/main/java/org/wamblee/cdi/SimpleInjector.java index 7a8db0da..12ebc307 100644 --- a/support/cdi/src/main/java/org/wamblee/cdi/SimpleInjector.java +++ b/support/cdi/src/main/java/org/wamblee/cdi/SimpleInjector.java @@ -23,26 +23,31 @@ package org.wamblee.cdi; */ public class SimpleInjector { - private static InjectorCache cache = new InjectorCache( + private InjectorCache cache = new InjectorCache( new CdiInjectorFactory()); /** - * Override the injector factory (mainly fo runit test). - * - * @param aFactory - * Factory. + * Constructs the injector. */ - public static void setInjectorFactory(InjectorFactory aFactory) { + public SimpleInjector() { + cache = new InjectorCache(new CdiInjectorFactory()); + } + + /** + * Construcst the injector. + * @param aFactory Factory to use. + */ + public SimpleInjector(InjectorFactory aFactory) { cache = new InjectorCache(aFactory); } - + /** * Injects into a given object. * * @param aObject * Object to inject into. */ - public static void inject(Object aObject) { + public void inject(Object aObject) { cache.getInjector(aObject.getClass()).inject(aObject); } } -- 2.31.1